43
43
use std:: collections:: hash_map:: Entry ;
44
44
45
45
use rustc_ast:: node_id:: NodeMap ;
46
- use rustc_ast:: ptr:: P ;
47
46
use rustc_ast:: { self as ast, * } ;
48
47
use rustc_data_structures:: captures:: Captures ;
49
48
use rustc_data_structures:: fingerprint:: Fingerprint ;
@@ -101,7 +100,7 @@ struct LoweringContext<'a, 'hir> {
101
100
/// Bodies inside the owner being lowered.
102
101
bodies : Vec < ( hir:: ItemLocalId , & ' hir hir:: Body < ' hir > ) > ,
103
102
/// Attributes inside the owner being lowered.
104
- attrs : SortedMap < hir:: ItemLocalId , & ' hir [ Attribute ] > ,
103
+ attrs : SortedMap < hir:: ItemLocalId , & ' hir [ hir :: Attribute ] > ,
105
104
/// Collect items that were created by lowering the current owner.
106
105
children : Vec < ( LocalDefId , hir:: MaybeOwner < ' hir > ) > ,
107
106
@@ -927,7 +926,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
927
926
ret
928
927
}
929
928
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 ] {
931
930
if attrs. is_empty ( ) {
932
931
& [ ]
933
932
} else {
@@ -939,25 +938,33 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
939
938
}
940
939
}
941
940
942
- fn lower_attr ( & self , attr : & Attribute ) -> Attribute {
941
+ fn lower_attr ( & self , attr : & Attribute ) -> hir :: Attribute {
943
942
// Note that we explicitly do not walk the path. Since we don't really
944
943
// lower attributes (we use the AST version) there is nowhere to keep
945
944
// the `HirId`s. We don't actually need HIR version of attributes anyway.
946
945
// Tokens are also not needed after macro expansion and parsing.
947
946
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 ,
954
959
} ,
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
+ }
958
965
} ;
959
966
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 ) }
961
968
}
962
969
963
970
fn alias_attrs ( & mut self , id : HirId , target_id : HirId ) {
@@ -969,14 +976,14 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
969
976
}
970
977
}
971
978
972
- fn lower_attr_args ( & self , args : & AttrArgs ) -> AttrArgs {
979
+ fn lower_attr_args ( & self , args : & AttrArgs ) -> hir :: AttrArgs {
973
980
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) ) ,
976
983
// This is an inert key-value attribute - it will never be visible to macros
977
984
// after it gets lowered to HIR. Therefore, we can extract literals to handle
978
985
// nonterminals in `#[doc]` (e.g. `#[doc = $e]`).
979
- AttrArgs :: Eq ( eq_span, AttrArgsEq :: Ast ( expr) ) => {
986
+ AttrArgs :: Eq ( eq_span, expr) => {
980
987
// In valid code the value always ends up as a single literal. Otherwise, a dummy
981
988
// literal suffices because the error is handled elsewhere.
982
989
let lit = if let ExprKind :: Lit ( token_lit) = expr. kind
@@ -992,10 +999,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
992
999
span : DUMMY_SP ,
993
1000
}
994
1001
} ;
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)
999
1003
}
1000
1004
}
1001
1005
}
0 commit comments