diff --git a/compiler/rustc_ast/src/ast.rs b/compiler/rustc_ast/src/ast.rs index 3f71fce0e3b31..3a55396248e68 100644 --- a/compiler/rustc_ast/src/ast.rs +++ b/compiler/rustc_ast/src/ast.rs @@ -2547,10 +2547,16 @@ pub struct Attribute { pub span: Span, } +#[derive(Clone, Encodable, Decodable, Debug)] +pub struct NormalAttr { + pub item: AttrItem, + pub tokens: Option, +} + #[derive(Clone, Encodable, Decodable, Debug)] pub enum AttrKind { /// A normal attribute. - Normal(AttrItem, Option), + Normal(P), /// A doc comment (e.g. `/// ...`, `//! ...`, `/** ... */`, `/*! ... */`). /// Doc attributes (e.g. `#[doc="..."]`) are represented with the `Normal` @@ -3033,7 +3039,7 @@ mod size_asserts { // These are in alphabetical order, which is easy to maintain. static_assert_size!(AssocItem, 160); static_assert_size!(AssocItemKind, 72); - static_assert_size!(Attribute, 152); + static_assert_size!(Attribute, 32); static_assert_size!(Block, 48); static_assert_size!(Expr, 104); static_assert_size!(Fn, 192); diff --git a/compiler/rustc_ast/src/ast_traits.rs b/compiler/rustc_ast/src/ast_traits.rs index 5c30a75a140a4..1fc5e480215ea 100644 --- a/compiler/rustc_ast/src/ast_traits.rs +++ b/compiler/rustc_ast/src/ast_traits.rs @@ -212,7 +212,7 @@ impl HasTokens for Stmt { impl HasTokens for Attribute { fn tokens(&self) -> Option<&LazyTokenStream> { match &self.kind { - AttrKind::Normal(_, tokens) => tokens.as_ref(), + AttrKind::Normal(normal) => normal.tokens.as_ref(), kind @ AttrKind::DocComment(..) => { panic!("Called tokens on doc comment attr {:?}", kind) } @@ -220,7 +220,7 @@ impl HasTokens for Attribute { } fn tokens_mut(&mut self) -> Option<&mut Option> { Some(match &mut self.kind { - AttrKind::Normal(_, tokens) => tokens, + AttrKind::Normal(normal) => &mut normal.tokens, kind @ AttrKind::DocComment(..) => { panic!("Called tokens_mut on doc comment attr {:?}", kind) } diff --git a/compiler/rustc_ast/src/attr/mod.rs b/compiler/rustc_ast/src/attr/mod.rs index 86af7769d1b0b..bc4f183d9b111 100644 --- a/compiler/rustc_ast/src/attr/mod.rs +++ b/compiler/rustc_ast/src/attr/mod.rs @@ -114,7 +114,7 @@ impl Attribute { #[inline] pub fn has_name(&self, name: Symbol) -> bool { match self.kind { - AttrKind::Normal(ref item, _) => item.path == name, + AttrKind::Normal(ref normal) => normal.item.path == name, AttrKind::DocComment(..) => false, } } @@ -122,9 +122,9 @@ impl Attribute { /// For a single-segment attribute, returns its name; otherwise, returns `None`. pub fn ident(&self) -> Option { match self.kind { - AttrKind::Normal(ref item, _) => { - if item.path.segments.len() == 1 { - Some(item.path.segments[0].ident) + AttrKind::Normal(ref normal) => { + if normal.item.path.segments.len() == 1 { + Some(normal.item.path.segments[0].ident) } else { None } @@ -138,14 +138,16 @@ impl Attribute { pub fn value_str(&self) -> Option { match self.kind { - AttrKind::Normal(ref item, _) => item.meta_kind().and_then(|kind| kind.value_str()), + AttrKind::Normal(ref normal) => { + normal.item.meta_kind().and_then(|kind| kind.value_str()) + } AttrKind::DocComment(..) => None, } } pub fn meta_item_list(&self) -> Option> { match self.kind { - AttrKind::Normal(ref item, _) => match item.meta_kind() { + AttrKind::Normal(ref normal) => match normal.item.meta_kind() { Some(MetaItemKind::List(list)) => Some(list), _ => None, }, @@ -154,8 +156,8 @@ impl Attribute { } pub fn is_word(&self) -> bool { - if let AttrKind::Normal(item, _) = &self.kind { - matches!(item.args, MacArgs::Empty) + if let AttrKind::Normal(normal) = &self.kind { + matches!(normal.item.args, MacArgs::Empty) } else { false } @@ -247,7 +249,8 @@ impl Attribute { pub fn doc_str_and_comment_kind(&self) -> Option<(Symbol, CommentKind)> { match self.kind { AttrKind::DocComment(kind, data) => Some((data, kind)), - AttrKind::Normal(ref item, _) if item.path == sym::doc => item + AttrKind::Normal(ref normal) if normal.item.path == sym::doc => normal + .item .meta_kind() .and_then(|kind| kind.value_str()) .map(|data| (data, CommentKind::Line)), @@ -258,8 +261,8 @@ impl Attribute { pub fn doc_str(&self) -> Option { match self.kind { AttrKind::DocComment(.., data) => Some(data), - AttrKind::Normal(ref item, _) if item.path == sym::doc => { - item.meta_kind().and_then(|kind| kind.value_str()) + AttrKind::Normal(ref normal) if normal.item.path == sym::doc => { + normal.item.meta_kind().and_then(|kind| kind.value_str()) } _ => None, } @@ -271,14 +274,14 @@ impl Attribute { pub fn get_normal_item(&self) -> &AttrItem { match self.kind { - AttrKind::Normal(ref item, _) => item, + AttrKind::Normal(ref normal) => &normal.item, AttrKind::DocComment(..) => panic!("unexpected doc comment"), } } pub fn unwrap_normal_item(self) -> AttrItem { match self.kind { - AttrKind::Normal(item, _) => item, + AttrKind::Normal(normal) => normal.into_inner().item, AttrKind::DocComment(..) => panic!("unexpected doc comment"), } } @@ -286,21 +289,22 @@ impl Attribute { /// Extracts the MetaItem from inside this Attribute. pub fn meta(&self) -> Option { match self.kind { - AttrKind::Normal(ref item, _) => item.meta(self.span), + AttrKind::Normal(ref normal) => normal.item.meta(self.span), AttrKind::DocComment(..) => None, } } pub fn meta_kind(&self) -> Option { match self.kind { - AttrKind::Normal(ref item, _) => item.meta_kind(), + AttrKind::Normal(ref normal) => normal.item.meta_kind(), AttrKind::DocComment(..) => None, } } pub fn tokens(&self) -> AttrAnnotatedTokenStream { match self.kind { - AttrKind::Normal(_, ref tokens) => tokens + AttrKind::Normal(ref normal) => normal + .tokens .as_ref() .unwrap_or_else(|| panic!("attribute is missing tokens: {:?}", self)) .create_token_stream(), @@ -361,7 +365,12 @@ pub fn mk_attr_from_item( style: AttrStyle, span: Span, ) -> Attribute { - Attribute { kind: AttrKind::Normal(item, tokens), id: mk_attr_id(), style, span } + Attribute { + kind: AttrKind::Normal(P(ast::NormalAttr { item, tokens })), + id: mk_attr_id(), + style, + span, + } } /// Returns an inner attribute with the given value and span. diff --git a/compiler/rustc_ast/src/mut_visit.rs b/compiler/rustc_ast/src/mut_visit.rs index 40c05f43f686d..54e2f7557e534 100644 --- a/compiler/rustc_ast/src/mut_visit.rs +++ b/compiler/rustc_ast/src/mut_visit.rs @@ -596,7 +596,9 @@ pub fn noop_visit_local(local: &mut P, vis: &mut T) { pub fn noop_visit_attribute(attr: &mut Attribute, vis: &mut T) { let Attribute { kind, id: _, style: _, span } = attr; match kind { - AttrKind::Normal(AttrItem { path, args, tokens }, attr_tokens) => { + AttrKind::Normal(normal) => { + let NormalAttr { item: AttrItem { path, args, tokens }, tokens: attr_tokens } = + &mut **normal; vis.visit_path(path); visit_mac_args(args, vis); visit_lazy_tts(tokens, vis); @@ -659,8 +661,8 @@ pub fn visit_attr_annotated_tt(tt: &mut AttrAnnotatedTokenTree, v AttrAnnotatedTokenTree::Attributes(data) => { for attr in &mut *data.attrs { match &mut attr.kind { - AttrKind::Normal(_, attr_tokens) => { - visit_lazy_tts(attr_tokens, vis); + AttrKind::Normal(normal) => { + visit_lazy_tts(&mut normal.tokens, vis); } AttrKind::DocComment(..) => { vis.visit_span(&mut attr.span); diff --git a/compiler/rustc_ast/src/visit.rs b/compiler/rustc_ast/src/visit.rs index 4b485b547f495..f687bfeced841 100644 --- a/compiler/rustc_ast/src/visit.rs +++ b/compiler/rustc_ast/src/visit.rs @@ -929,7 +929,7 @@ pub fn walk_vis<'a, V: Visitor<'a>>(visitor: &mut V, vis: &'a Visibility) { pub fn walk_attribute<'a, V: Visitor<'a>>(visitor: &mut V, attr: &'a Attribute) { match attr.kind { - AttrKind::Normal(ref item, ref _tokens) => walk_mac_args(visitor, &item.args), + AttrKind::Normal(ref normal) => walk_mac_args(visitor, &normal.item.args), AttrKind::DocComment(..) => {} } } diff --git a/compiler/rustc_ast_lowering/src/lib.rs b/compiler/rustc_ast_lowering/src/lib.rs index 056f9ca08f8f2..73777aa6bb4de 100644 --- a/compiler/rustc_ast_lowering/src/lib.rs +++ b/compiler/rustc_ast_lowering/src/lib.rs @@ -39,6 +39,7 @@ #[macro_use] extern crate tracing; +use rustc_ast::ptr::P; use rustc_ast::visit; use rustc_ast::{self as ast, *}; use rustc_ast_pretty::pprust; @@ -873,14 +874,14 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { // the `HirId`s. We don't actually need HIR version of attributes anyway. // Tokens are also not needed after macro expansion and parsing. let kind = match attr.kind { - AttrKind::Normal(ref item, _) => AttrKind::Normal( - AttrItem { - path: item.path.clone(), - args: self.lower_mac_args(&item.args), + AttrKind::Normal(ref normal) => AttrKind::Normal(P(NormalAttr { + item: AttrItem { + path: normal.item.path.clone(), + args: self.lower_mac_args(&normal.item.args), tokens: None, }, - None, - ), + tokens: None, + })), AttrKind::DocComment(comment_kind, data) => AttrKind::DocComment(comment_kind, data), }; diff --git a/compiler/rustc_ast_pretty/src/pprust/state.rs b/compiler/rustc_ast_pretty/src/pprust/state.rs index 5eb7bf6347f7b..c454034efa735 100644 --- a/compiler/rustc_ast_pretty/src/pprust/state.rs +++ b/compiler/rustc_ast_pretty/src/pprust/state.rs @@ -442,12 +442,12 @@ pub trait PrintState<'a>: std::ops::Deref + std::ops::Dere } self.maybe_print_comment(attr.span.lo()); match attr.kind { - ast::AttrKind::Normal(ref item, _) => { + ast::AttrKind::Normal(ref normal) => { match attr.style { ast::AttrStyle::Inner => self.word("#!["), ast::AttrStyle::Outer => self.word("#["), } - self.print_attr_item(&item, attr.span); + self.print_attr_item(&normal.item, attr.span); self.word("]"); } ast::AttrKind::DocComment(comment_kind, data) => { diff --git a/compiler/rustc_query_system/src/ich/impls_syntax.rs b/compiler/rustc_query_system/src/ich/impls_syntax.rs index 1fa085926767d..d7732cb1825b1 100644 --- a/compiler/rustc_query_system/src/ich/impls_syntax.rs +++ b/compiler/rustc_query_system/src/ich/impls_syntax.rs @@ -42,12 +42,12 @@ impl<'ctx> rustc_ast::HashStableContext for StableHashingContext<'ctx> { debug_assert!(!attr.is_doc_comment()); let ast::Attribute { kind, id: _, style, span } = attr; - if let ast::AttrKind::Normal(item, tokens) = kind { - item.hash_stable(self, hasher); + if let ast::AttrKind::Normal(normal) = kind { + normal.item.hash_stable(self, hasher); style.hash_stable(self, hasher); span.hash_stable(self, hasher); assert_matches!( - tokens.as_ref(), + normal.tokens.as_ref(), None, "Tokens should have been removed during lowering!" ); diff --git a/src/test/ui/stats/hir-stats.stderr b/src/test/ui/stats/hir-stats.stderr index f4874408c9094..9ea32e8d64ea4 100644 --- a/src/test/ui/stats/hir-stats.stderr +++ b/src/test/ui/stats/hir-stats.stderr @@ -4,58 +4,58 @@ PRE EXPANSION AST STATS Name Accumulated Size Count Item Size ---------------------------------------------------------------- ExprField 48 ( 0.5%) 1 48 +Attribute 64 ( 0.7%) 2 32 +- Normal 32 ( 0.4%) 1 +- DocComment 32 ( 0.4%) 1 GenericArgs 64 ( 0.7%) 1 64 - AngleBracketed 64 ( 0.7%) 1 Local 72 ( 0.8%) 1 72 WherePredicate 72 ( 0.8%) 1 72 - BoundPredicate 72 ( 0.8%) 1 Crate 72 ( 0.8%) 1 72 -Arm 96 ( 1.0%) 2 48 -FieldDef 160 ( 1.7%) 2 80 -ForeignItem 160 ( 1.7%) 1 160 -- Fn 160 ( 1.7%) 1 -Stmt 160 ( 1.7%) 5 32 -- Local 32 ( 0.3%) 1 -- MacCall 32 ( 0.3%) 1 -- Expr 96 ( 1.0%) 3 -Param 160 ( 1.7%) 4 40 +Arm 96 ( 1.1%) 2 48 +FieldDef 160 ( 1.8%) 2 80 +ForeignItem 160 ( 1.8%) 1 160 +- Fn 160 ( 1.8%) 1 +Stmt 160 ( 1.8%) 5 32 +- Local 32 ( 0.4%) 1 +- MacCall 32 ( 0.4%) 1 +- Expr 96 ( 1.1%) 3 +Param 160 ( 1.8%) 4 40 FnDecl 200 ( 2.2%) 5 40 -Variant 240 ( 2.6%) 2 120 -Block 288 ( 3.1%) 6 48 -Attribute 304 ( 3.3%) 2 152 -- Normal 152 ( 1.7%) 1 -- DocComment 152 ( 1.7%) 1 -GenericBound 352 ( 3.8%) 4 88 -- Trait 352 ( 3.8%) 4 -GenericParam 520 ( 5.7%) 5 104 -AssocItem 640 ( 7.0%) 4 160 -- TyAlias 320 ( 3.5%) 2 -- Fn 320 ( 3.5%) 2 -PathSegment 720 ( 7.9%) 30 24 -Expr 832 ( 9.1%) 8 104 -- Path 104 ( 1.1%) 1 -- Match 104 ( 1.1%) 1 -- Struct 104 ( 1.1%) 1 +Variant 240 ( 2.7%) 2 120 +Block 288 ( 3.2%) 6 48 +GenericBound 352 ( 4.0%) 4 88 +- Trait 352 ( 4.0%) 4 +GenericParam 520 ( 5.8%) 5 104 +AssocItem 640 ( 7.2%) 4 160 +- TyAlias 320 ( 3.6%) 2 +- Fn 320 ( 3.6%) 2 +PathSegment 720 ( 8.1%) 30 24 +Expr 832 ( 9.3%) 8 104 +- Path 104 ( 1.2%) 1 +- Match 104 ( 1.2%) 1 +- Struct 104 ( 1.2%) 1 - Lit 208 ( 2.3%) 2 -- Block 312 ( 3.4%) 3 -Pat 840 ( 9.2%) 7 120 +- Block 312 ( 3.5%) 3 +Pat 840 ( 9.4%) 7 120 - Struct 120 ( 1.3%) 1 - Wild 120 ( 1.3%) 1 -- Ident 600 ( 6.6%) 5 -Ty 1_344 (14.7%) 14 96 -- Rptr 96 ( 1.0%) 1 -- Ptr 96 ( 1.0%) 1 -- ImplicitSelf 192 ( 2.1%) 2 -- Path 960 (10.5%) 10 -Item 1_800 (19.7%) 9 200 +- Ident 600 ( 6.7%) 5 +Ty 1_344 (15.1%) 14 96 +- Rptr 96 ( 1.1%) 1 +- Ptr 96 ( 1.1%) 1 +- ImplicitSelf 192 ( 2.2%) 2 +- Path 960 (10.8%) 10 +Item 1_800 (20.2%) 9 200 - Trait 200 ( 2.2%) 1 - Enum 200 ( 2.2%) 1 - ForeignMod 200 ( 2.2%) 1 - Impl 200 ( 2.2%) 1 -- Fn 400 ( 4.4%) 2 -- Use 600 ( 6.6%) 3 +- Fn 400 ( 4.5%) 2 +- Use 600 ( 6.7%) 3 ---------------------------------------------------------------- -Total 9_144 +Total 8_904 POST EXPANSION AST STATS @@ -63,61 +63,61 @@ POST EXPANSION AST STATS Name Accumulated Size Count Item Size ---------------------------------------------------------------- ExprField 48 ( 0.5%) 1 48 -GenericArgs 64 ( 0.6%) 1 64 -- AngleBracketed 64 ( 0.6%) 1 +GenericArgs 64 ( 0.7%) 1 64 +- AngleBracketed 64 ( 0.7%) 1 Local 72 ( 0.7%) 1 72 WherePredicate 72 ( 0.7%) 1 72 - BoundPredicate 72 ( 0.7%) 1 Crate 72 ( 0.7%) 1 72 -Arm 96 ( 0.9%) 2 48 +Arm 96 ( 1.0%) 2 48 InlineAsm 120 ( 1.2%) 1 120 -FieldDef 160 ( 1.6%) 2 80 -ForeignItem 160 ( 1.6%) 1 160 -- Fn 160 ( 1.6%) 1 -Stmt 160 ( 1.6%) 5 32 +Attribute 128 ( 1.3%) 4 32 +- DocComment 32 ( 0.3%) 1 +- Normal 96 ( 1.0%) 3 +FieldDef 160 ( 1.7%) 2 80 +ForeignItem 160 ( 1.7%) 1 160 +- Fn 160 ( 1.7%) 1 +Stmt 160 ( 1.7%) 5 32 - Local 32 ( 0.3%) 1 - Semi 32 ( 0.3%) 1 -- Expr 96 ( 0.9%) 3 -Param 160 ( 1.6%) 4 40 -FnDecl 200 ( 2.0%) 5 40 -Variant 240 ( 2.4%) 2 120 -Block 288 ( 2.8%) 6 48 -GenericBound 352 ( 3.5%) 4 88 -- Trait 352 ( 3.5%) 4 -GenericParam 520 ( 5.1%) 5 104 -Attribute 608 ( 6.0%) 4 152 -- DocComment 152 ( 1.5%) 1 -- Normal 456 ( 4.5%) 3 -AssocItem 640 ( 6.3%) 4 160 -- TyAlias 320 ( 3.2%) 2 -- Fn 320 ( 3.2%) 2 -PathSegment 792 ( 7.8%) 33 24 -Pat 840 ( 8.3%) 7 120 +- Expr 96 ( 1.0%) 3 +Param 160 ( 1.7%) 4 40 +FnDecl 200 ( 2.1%) 5 40 +Variant 240 ( 2.5%) 2 120 +Block 288 ( 3.0%) 6 48 +GenericBound 352 ( 3.6%) 4 88 +- Trait 352 ( 3.6%) 4 +GenericParam 520 ( 5.4%) 5 104 +AssocItem 640 ( 6.6%) 4 160 +- TyAlias 320 ( 3.3%) 2 +- Fn 320 ( 3.3%) 2 +PathSegment 792 ( 8.2%) 33 24 +Pat 840 ( 8.7%) 7 120 - Struct 120 ( 1.2%) 1 - Wild 120 ( 1.2%) 1 -- Ident 600 ( 5.9%) 5 -Expr 936 ( 9.2%) 9 104 -- Path 104 ( 1.0%) 1 -- Match 104 ( 1.0%) 1 -- Struct 104 ( 1.0%) 1 -- InlineAsm 104 ( 1.0%) 1 -- Lit 208 ( 2.1%) 2 -- Block 312 ( 3.1%) 3 -Ty 1_344 (13.2%) 14 96 -- Rptr 96 ( 0.9%) 1 -- Ptr 96 ( 0.9%) 1 -- ImplicitSelf 192 ( 1.9%) 2 -- Path 960 ( 9.5%) 10 -Item 2_200 (21.7%) 11 200 -- Trait 200 ( 2.0%) 1 -- Enum 200 ( 2.0%) 1 -- ExternCrate 200 ( 2.0%) 1 -- ForeignMod 200 ( 2.0%) 1 -- Impl 200 ( 2.0%) 1 -- Fn 400 ( 3.9%) 2 -- Use 800 ( 7.9%) 4 +- Ident 600 ( 6.2%) 5 +Expr 936 ( 9.7%) 9 104 +- Path 104 ( 1.1%) 1 +- Match 104 ( 1.1%) 1 +- Struct 104 ( 1.1%) 1 +- InlineAsm 104 ( 1.1%) 1 +- Lit 208 ( 2.2%) 2 +- Block 312 ( 3.2%) 3 +Ty 1_344 (13.9%) 14 96 +- Rptr 96 ( 1.0%) 1 +- Ptr 96 ( 1.0%) 1 +- ImplicitSelf 192 ( 2.0%) 2 +- Path 960 ( 9.9%) 10 +Item 2_200 (22.8%) 11 200 +- Trait 200 ( 2.1%) 1 +- Enum 200 ( 2.1%) 1 +- ExternCrate 200 ( 2.1%) 1 +- ForeignMod 200 ( 2.1%) 1 +- Impl 200 ( 2.1%) 1 +- Fn 400 ( 4.1%) 2 +- Use 800 ( 8.3%) 4 ---------------------------------------------------------------- -Total 10_144 +Total 9_664 HIR STATS @@ -126,26 +126,26 @@ Name Accumulated Size Count Item Size ---------------------------------------------------------------- Param 64 ( 0.7%) 2 32 Local 64 ( 0.7%) 1 64 -ForeignItem 72 ( 0.7%) 1 72 +ForeignItem 72 ( 0.8%) 1 72 FieldDef 96 ( 1.0%) 2 48 Arm 96 ( 1.0%) 2 48 Stmt 96 ( 1.0%) 3 32 -FnDecl 120 ( 1.2%) 3 40 -Lifetime 128 ( 1.3%) 4 32 -Variant 160 ( 1.6%) 2 80 -ImplItem 176 ( 1.8%) 2 88 -GenericBound 192 ( 2.0%) 4 48 -TraitItem 192 ( 2.0%) 2 96 -WherePredicate 216 ( 2.2%) 3 72 -Block 288 ( 3.0%) 6 48 -QPath 408 ( 4.2%) 17 24 -Pat 440 ( 4.5%) 5 88 -Attribute 608 ( 6.2%) 4 152 -Expr 672 ( 6.9%) 12 56 -Item 960 ( 9.9%) 12 80 -Ty 1_152 (11.8%) 16 72 -Path 1_296 (13.3%) 27 48 -PathSegment 2_240 (23.0%) 40 56 +FnDecl 120 ( 1.3%) 3 40 +Attribute 128 ( 1.4%) 4 32 +Lifetime 128 ( 1.4%) 4 32 +Variant 160 ( 1.7%) 2 80 +ImplItem 176 ( 1.9%) 2 88 +GenericBound 192 ( 2.1%) 4 48 +TraitItem 192 ( 2.1%) 2 96 +WherePredicate 216 ( 2.3%) 3 72 +Block 288 ( 3.1%) 6 48 +QPath 408 ( 4.4%) 17 24 +Pat 440 ( 4.8%) 5 88 +Expr 672 ( 7.3%) 12 56 +Item 960 (10.4%) 12 80 +Ty 1_152 (12.4%) 16 72 +Path 1_296 (14.0%) 27 48 +PathSegment 2_240 (24.2%) 40 56 ---------------------------------------------------------------- -Total 9_736 +Total 9_256 diff --git a/src/tools/clippy/clippy_lints/src/crate_in_macro_def.rs b/src/tools/clippy/clippy_lints/src/crate_in_macro_def.rs index 454ec23388af9..20cc330e035f8 100644 --- a/src/tools/clippy/clippy_lints/src/crate_in_macro_def.rs +++ b/src/tools/clippy/clippy_lints/src/crate_in_macro_def.rs @@ -74,8 +74,8 @@ impl EarlyLintPass for CrateInMacroDef { fn is_macro_export(attr: &Attribute) -> bool { if_chain! { - if let AttrKind::Normal(attr_item, _) = &attr.kind; - if let [segment] = attr_item.path.segments.as_slice(); + if let AttrKind::Normal(normal) = &attr.kind; + if let [segment] = normal.item.path.segments.as_slice(); then { segment.ident.name == sym::macro_export } else { diff --git a/src/tools/clippy/clippy_utils/src/ast_utils.rs b/src/tools/clippy/clippy_utils/src/ast_utils.rs index 9f74729bdfa18..493991f30e872 100644 --- a/src/tools/clippy/clippy_utils/src/ast_utils.rs +++ b/src/tools/clippy/clippy_utils/src/ast_utils.rs @@ -695,7 +695,7 @@ pub fn eq_attr(l: &Attribute, r: &Attribute) -> bool { l.style == r.style && match (&l.kind, &r.kind) { (DocComment(l1, l2), DocComment(r1, r2)) => l1 == r1 && l2 == r2, - (Normal(l, _), Normal(r, _)) => eq_path(&l.path, &r.path) && eq_mac_args(&l.args, &r.args), + (Normal(l), Normal(r)) => eq_path(&l.item.path, &r.item.path) && eq_mac_args(&l.item.args, &r.item.args), _ => false, } } diff --git a/src/tools/clippy/clippy_utils/src/attrs.rs b/src/tools/clippy/clippy_utils/src/attrs.rs index 186bba09d2012..8ab77c8816636 100644 --- a/src/tools/clippy/clippy_utils/src/attrs.rs +++ b/src/tools/clippy/clippy_utils/src/attrs.rs @@ -59,8 +59,8 @@ pub fn get_attr<'a>( name: &'static str, ) -> impl Iterator { attrs.iter().filter(move |attr| { - let attr = if let ast::AttrKind::Normal(ref attr, _) = attr.kind { - attr + let attr = if let ast::AttrKind::Normal(ref normal) = attr.kind { + &normal.item } else { return false; }; diff --git a/src/tools/clippy/clippy_utils/src/lib.rs b/src/tools/clippy/clippy_utils/src/lib.rs index dc772e5efeef3..f716f009ff3f5 100644 --- a/src/tools/clippy/clippy_utils/src/lib.rs +++ b/src/tools/clippy/clippy_utils/src/lib.rs @@ -1893,8 +1893,8 @@ pub fn std_or_core(cx: &LateContext<'_>) -> Option<&'static str> { pub fn is_no_std_crate(cx: &LateContext<'_>) -> bool { cx.tcx.hir().attrs(hir::CRATE_HIR_ID).iter().any(|attr| { - if let ast::AttrKind::Normal(ref attr, _) = attr.kind { - attr.path == sym::no_std + if let ast::AttrKind::Normal(ref normal) = attr.kind { + normal.item.path == sym::no_std } else { false } @@ -1903,8 +1903,8 @@ pub fn is_no_std_crate(cx: &LateContext<'_>) -> bool { pub fn is_no_core_crate(cx: &LateContext<'_>) -> bool { cx.tcx.hir().attrs(hir::CRATE_HIR_ID).iter().any(|attr| { - if let ast::AttrKind::Normal(ref attr, _) = attr.kind { - attr.path == sym::no_core + if let ast::AttrKind::Normal(ref normal) = attr.kind { + normal.item.path == sym::no_core } else { false } diff --git a/src/tools/rustfmt/src/skip.rs b/src/tools/rustfmt/src/skip.rs index 0fdc097efc23f..032922d421df7 100644 --- a/src/tools/rustfmt/src/skip.rs +++ b/src/tools/rustfmt/src/skip.rs @@ -58,8 +58,8 @@ fn get_skip_names(kind: &str, attrs: &[ast::Attribute]) -> Vec { for attr in attrs { // rustc_ast::ast::Path is implemented partialEq // but it is designed for segments.len() == 1 - if let ast::AttrKind::Normal(attr_item, _) = &attr.kind { - if pprust::path_to_string(&attr_item.path) != path { + if let ast::AttrKind::Normal(normal) = &attr.kind { + if pprust::path_to_string(&normal.item.path) != path { continue; } } diff --git a/src/tools/rustfmt/src/visitor.rs b/src/tools/rustfmt/src/visitor.rs index 9a0e0752c12f5..7bb745eeb8b9b 100644 --- a/src/tools/rustfmt/src/visitor.rs +++ b/src/tools/rustfmt/src/visitor.rs @@ -811,8 +811,8 @@ impl<'b, 'a: 'b> FmtVisitor<'a> { ); } else { match &attr.kind { - ast::AttrKind::Normal(ref attribute_item, _) - if self.is_unknown_rustfmt_attr(&attribute_item.path.segments) => + ast::AttrKind::Normal(ref normal) + if self.is_unknown_rustfmt_attr(&normal.item.path.segments) => { let file_name = self.parse_sess.span_to_filename(attr.span); self.report.append(