Description
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 use AttrVec
, (an alias of a ThinVec
of Attribute
s) some node types use a plain Vec<Attribute>
.
In particular, as of this writing, Variant
, StructField
, Item
, Crate
, and Arm
all use Vec<Attribute>
. (I found these via a search in rustc_ast
for "attr" and checking each field in the results, so hopefully that list is complete.)
ThinVec
's documentation says:
A vector type optimized for cases where this size is usually 0 (cf. SmallVector). The Option<Box<..>> wrapping allows us to represent a zero sized vector with None, which uses only a single (null) pointer.
I would suspect that for most of the types that use a plain Vec<Attribute>
the Vec
is empty almost all of the time, with the possible exception of Item
s, since #[derive(Debug)]
etc. is pretty common.
So should more of the types that use a plain Vec<Attribute>
be using an AttrVec
instead? Are these fields plain Vec
s just because no one changed them, or was it somehow determined that those types aren't copied enough for this optimization to matter?