Skip to content

Commit 1a46283

Browse files
committed
Auto merge of #86385 - JohnTitor:use-attrvec, r=davidtwco
Use `AttrVec` for `Arm`, `FieldDef`, and `Variant` Uses `AttrVec` for `Arm`, `FieldDef`, and `Variant`, i.e., where the size of the vector can be empty often. Skips `Crate` and `Item` because I think they may have the attributes on common cases and need more work outside of `rustc_ast` (e.g. rustc_expand needs a lot of tweaks). But if it's reasonable to change, I'm happy to do so. Fixes #77662
2 parents a6bc43e + 4f8e0eb commit 1a46283

File tree

7 files changed

+16
-16
lines changed

7 files changed

+16
-16
lines changed

compiler/rustc_ast/src/ast.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1017,7 +1017,7 @@ pub struct Local {
10171017
/// ```
10181018
#[derive(Clone, Encodable, Decodable, Debug)]
10191019
pub struct Arm {
1020-
pub attrs: Vec<Attribute>,
1020+
pub attrs: AttrVec,
10211021
/// Match arm pattern, e.g. `10` in `match foo { 10 => {}, _ => {} }`
10221022
pub pat: P<Pat>,
10231023
/// Match arm guard, e.g. `n > 10` in `match foo { n if n > 10 => {}, _ => {} }`
@@ -2293,7 +2293,7 @@ pub struct EnumDef {
22932293
#[derive(Clone, Encodable, Decodable, Debug)]
22942294
pub struct Variant {
22952295
/// Attributes of the variant.
2296-
pub attrs: Vec<Attribute>,
2296+
pub attrs: AttrVec,
22972297
/// Id of the variant (not the constructor, see `VariantData::ctor_id()`).
22982298
pub id: NodeId,
22992299
/// Span
@@ -2474,7 +2474,7 @@ impl VisibilityKind {
24742474
/// E.g., `bar: usize` as in `struct Foo { bar: usize }`.
24752475
#[derive(Clone, Encodable, Decodable, Debug)]
24762476
pub struct FieldDef {
2477-
pub attrs: Vec<Attribute>,
2477+
pub attrs: AttrVec,
24782478
pub id: NodeId,
24792479
pub span: Span,
24802480
pub vis: Visibility,

compiler/rustc_ast/src/mut_visit.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ pub fn noop_visit_use_tree<T: MutVisitor>(use_tree: &mut UseTree, vis: &mut T) {
420420

421421
pub fn noop_flat_map_arm<T: MutVisitor>(mut arm: Arm, vis: &mut T) -> SmallVec<[Arm; 1]> {
422422
let Arm { attrs, pat, guard, body, span, id, is_placeholder: _ } = &mut arm;
423-
visit_attrs(attrs, vis);
423+
visit_thin_attrs(attrs, vis);
424424
vis.visit_id(id);
425425
vis.visit_pat(pat);
426426
visit_opt(guard, |guard| vis.visit_expr(guard));
@@ -504,7 +504,7 @@ pub fn noop_flat_map_variant<T: MutVisitor>(
504504
let Variant { ident, vis, attrs, id, data, disr_expr, span, is_placeholder: _ } = &mut variant;
505505
visitor.visit_ident(ident);
506506
visitor.visit_vis(vis);
507-
visit_attrs(attrs, visitor);
507+
visit_thin_attrs(attrs, visitor);
508508
visitor.visit_id(id);
509509
visitor.visit_variant_data(data);
510510
visit_opt(disr_expr, |disr_expr| visitor.visit_anon_const(disr_expr));
@@ -918,7 +918,7 @@ pub fn noop_flat_map_field_def<T: MutVisitor>(
918918
visitor.visit_vis(vis);
919919
visitor.visit_id(id);
920920
visitor.visit_ty(ty);
921-
visit_attrs(attrs, visitor);
921+
visit_thin_attrs(attrs, visitor);
922922
smallvec![fd]
923923
}
924924

compiler/rustc_ast_pretty/src/pprust/tests.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ fn test_variant_to_string() {
4949
kind: ast::VisibilityKind::Inherited,
5050
tokens: None,
5151
},
52-
attrs: Vec::new(),
52+
attrs: ast::AttrVec::new(),
5353
id: ast::DUMMY_NODE_ID,
5454
data: ast::VariantData::Unit(ast::DUMMY_NODE_ID),
5555
disr_expr: None,

compiler/rustc_expand/src/build.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ impl<'a> ExtCtxt<'a> {
432432

433433
pub fn arm(&self, span: Span, pat: P<ast::Pat>, expr: P<ast::Expr>) -> ast::Arm {
434434
ast::Arm {
435-
attrs: vec![],
435+
attrs: AttrVec::new(),
436436
pat,
437437
guard: None,
438438
body: expr,

compiler/rustc_parse/src/parser/expr.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2116,7 +2116,7 @@ impl<'a> Parser<'a> {
21162116
let span = body.span;
21172117
return Ok((
21182118
ast::Arm {
2119-
attrs,
2119+
attrs: attrs.into(),
21202120
pat,
21212121
guard,
21222122
body,
@@ -2170,7 +2170,7 @@ impl<'a> Parser<'a> {
21702170

21712171
Ok((
21722172
ast::Arm {
2173-
attrs,
2173+
attrs: attrs.into(),
21742174
pat,
21752175
guard,
21762176
body: expr,

compiler/rustc_parse/src/parser/item.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1143,7 +1143,7 @@ impl<'a> Parser<'a> {
11431143
ident,
11441144
vis,
11451145
id: DUMMY_NODE_ID,
1146-
attrs: variant_attrs,
1146+
attrs: variant_attrs.into(),
11471147
data: struct_def,
11481148
disr_expr,
11491149
span: vlo.to(this.prev_token.span),
@@ -1286,7 +1286,7 @@ impl<'a> Parser<'a> {
12861286
ident: None,
12871287
id: DUMMY_NODE_ID,
12881288
ty,
1289-
attrs,
1289+
attrs: attrs.into(),
12901290
is_placeholder: false,
12911291
},
12921292
TrailingToken::MaybeComma,
@@ -1460,7 +1460,7 @@ impl<'a> Parser<'a> {
14601460
vis,
14611461
id: DUMMY_NODE_ID,
14621462
ty,
1463-
attrs,
1463+
attrs: attrs.into(),
14641464
is_placeholder: false,
14651465
})
14661466
}

src/tools/rustfmt/src/types.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::iter::ExactSizeIterator;
22
use std::ops::Deref;
33

4-
use rustc_ast::ast::{self, FnRetTy, Mutability};
4+
use rustc_ast::ast::{self, AttrVec, FnRetTy, Mutability};
55
use rustc_span::{symbol::kw, symbol::Ident, BytePos, Pos, Span};
66

77
use crate::config::lists::*;
@@ -776,7 +776,7 @@ impl Rewrite for ast::Ty {
776776
);
777777
let data = ast::VariantData::Struct(fields.clone(), recovered);
778778
let variant = ast::Variant {
779-
attrs: vec![],
779+
attrs: AttrVec::new(),
780780
id: self.id,
781781
span: self.span,
782782
vis: DEFAULT_VISIBILITY,
@@ -800,7 +800,7 @@ impl Rewrite for ast::Ty {
800800
);
801801
let data = ast::VariantData::Struct(fields.clone(), recovered);
802802
let variant = ast::Variant {
803-
attrs: vec![],
803+
attrs: AttrVec::new(),
804804
id: self.id,
805805
span: self.span,
806806
vis: DEFAULT_VISIBILITY,

0 commit comments

Comments
 (0)