4343use std:: collections:: hash_map:: Entry ;
4444
4545use rustc_ast:: node_id:: NodeMap ;
46- use rustc_ast:: ptr:: P ;
4746use rustc_ast:: { self as ast, * } ;
4847use rustc_data_structures:: captures:: Captures ;
4948use rustc_data_structures:: fingerprint:: Fingerprint ;
@@ -101,7 +100,7 @@ struct LoweringContext<'a, 'hir> {
101100 /// Bodies inside the owner being lowered.
102101 bodies : Vec < ( hir:: ItemLocalId , & ' hir hir:: Body < ' hir > ) > ,
103102 /// Attributes inside the owner being lowered.
104- attrs : SortedMap < hir:: ItemLocalId , & ' hir [ Attribute ] > ,
103+ attrs : SortedMap < hir:: ItemLocalId , & ' hir [ hir :: Attribute ] > ,
105104 /// Collect items that were created by lowering the current owner.
106105 children : Vec < ( LocalDefId , hir:: MaybeOwner < ' hir > ) > ,
107106
@@ -927,7 +926,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
927926 ret
928927 }
929928
930- fn lower_attrs ( & mut self , id : HirId , attrs : & [ Attribute ] ) -> & ' hir [ Attribute ] {
929+ fn lower_attrs ( & mut self , id : HirId , attrs : & [ Attribute ] ) -> & ' hir [ hir :: Attribute ] {
931930 if attrs. is_empty ( ) {
932931 & [ ]
933932 } else {
@@ -939,25 +938,33 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
939938 }
940939 }
941940
942- fn lower_attr ( & self , attr : & Attribute ) -> Attribute {
941+ fn lower_attr ( & self , attr : & Attribute ) -> hir :: Attribute {
943942 // Note that we explicitly do not walk the path. Since we don't really
944943 // lower attributes (we use the AST version) there is nowhere to keep
945944 // the `HirId`s. We don't actually need HIR version of attributes anyway.
946945 // Tokens are also not needed after macro expansion and parsing.
947946 let kind = match attr. kind {
948- AttrKind :: Normal ( ref normal) => AttrKind :: Normal ( P ( NormalAttr {
949- item : AttrItem {
950- unsafety : normal. item . unsafety ,
951- path : normal. item . path . clone ( ) ,
952- args : self . lower_attr_args ( & normal. item . args ) ,
953- tokens : None ,
947+ AttrKind :: Normal ( ref normal) => hir:: AttrKind :: Normal ( hir:: AttrItem {
948+ unsafety : self . lower_safety ( normal. item . unsafety , hir:: Safety :: Safe ) ,
949+ path : hir:: AttrPath {
950+ segments : normal
951+ . item
952+ . path
953+ . segments
954+ . iter ( )
955+ . map ( |i| i. ident )
956+ . collect :: < Vec < _ > > ( )
957+ . into_boxed_slice ( ) ,
958+ span : normal. item . path . span ,
954959 } ,
955- tokens : None ,
956- } ) ) ,
957- AttrKind :: DocComment ( comment_kind, data) => AttrKind :: DocComment ( comment_kind, data) ,
960+ args : self . lower_attr_args ( & normal. item . args ) ,
961+ } ) ,
962+ AttrKind :: DocComment ( comment_kind, data) => {
963+ hir:: AttrKind :: DocComment ( comment_kind, data)
964+ }
958965 } ;
959966
960- Attribute { kind, id : attr. id , style : attr. style , span : self . lower_span ( attr. span ) }
967+ hir :: Attribute { kind, id : attr. id , style : attr. style , span : self . lower_span ( attr. span ) }
961968 }
962969
963970 fn alias_attrs ( & mut self , id : HirId , target_id : HirId ) {
@@ -969,14 +976,14 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
969976 }
970977 }
971978
972- fn lower_attr_args ( & self , args : & AttrArgs ) -> AttrArgs {
979+ fn lower_attr_args ( & self , args : & AttrArgs ) -> hir :: AttrArgs {
973980 match args {
974- AttrArgs :: Empty => AttrArgs :: Empty ,
975- AttrArgs :: Delimited ( args) => AttrArgs :: Delimited ( self . lower_delim_args ( args) ) ,
981+ AttrArgs :: Empty => hir :: AttrArgs :: Empty ,
982+ AttrArgs :: Delimited ( args) => hir :: AttrArgs :: Delimited ( self . lower_delim_args ( args) ) ,
976983 // This is an inert key-value attribute - it will never be visible to macros
977984 // after it gets lowered to HIR. Therefore, we can extract literals to handle
978985 // nonterminals in `#[doc]` (e.g. `#[doc = $e]`).
979- AttrArgs :: Eq ( eq_span, AttrArgsEq :: Ast ( expr) ) => {
986+ AttrArgs :: Eq ( eq_span, expr) => {
980987 // In valid code the value always ends up as a single literal. Otherwise, a dummy
981988 // literal suffices because the error is handled elsewhere.
982989 let lit = if let ExprKind :: Lit ( token_lit) = expr. kind
@@ -992,10 +999,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
992999 span : DUMMY_SP ,
9931000 }
9941001 } ;
995- AttrArgs :: Eq ( * eq_span, AttrArgsEq :: Hir ( lit) )
996- }
997- AttrArgs :: Eq ( _, AttrArgsEq :: Hir ( lit) ) => {
998- unreachable ! ( "in literal form when lowering mac args eq: {:?}" , lit)
1002+ hir:: AttrArgs :: Eq ( * eq_span, lit)
9991003 }
10001004 }
10011005 }
0 commit comments