Should all the AST node types with attributes be using AttrVec? #77662
Labels
A-attributes
Area: Attributes (`#[…]`, `#![…]`)
A-parser
Area: The lexing & parsing of Rust source code to an AST
C-cleanup
Category: PRs that clean code up or issues documenting cleanup.
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
I've been working on a PR to clippy that involved looking at the different AST node types in
rustc_ast::ast
. I noticed that while most of the subset of those types that can contain attributes useAttrVec
, (an alias of aThinVec
ofAttribute
s) some node types use a plainVec<Attribute>
.In particular, as of this writing,
Variant
,StructField
,Item
,Crate
, andArm
all useVec<Attribute>
. (I found these via a search inrustc_ast
for "attr" and checking each field in the results, so hopefully that list is complete.)ThinVec
's documentation says:I would suspect that for most of the types that use a plain
Vec<Attribute>
theVec
is empty almost all of the time, with the possible exception ofItem
s, since#[derive(Debug)]
etc. is pretty common.So should more of the types that use a plain
Vec<Attribute>
be using anAttrVec
instead? Are these fields plainVec
s just because no one changed them, or was it somehow determined that those types aren't copied enough for this optimization to matter?The text was updated successfully, but these errors were encountered: