@@ -2,7 +2,7 @@ use rustc_abi::ExternAbi;
2
2
use rustc_ast:: visit:: AssocCtxt ;
3
3
use rustc_ast:: * ;
4
4
use rustc_errors:: { E0570 , ErrorGuaranteed , struct_span_code_err} ;
5
- use rustc_hir:: attrs:: AttributeKind ;
5
+ use rustc_hir:: attrs:: { AttributeKind , EiiDecl } ;
6
6
use rustc_hir:: def:: { DefKind , PerNS , Res } ;
7
7
use rustc_hir:: def_id:: { CRATE_DEF_ID , LocalDefId } ;
8
8
use rustc_hir:: {
@@ -11,6 +11,7 @@ use rustc_hir::{
11
11
use rustc_index:: { IndexSlice , IndexVec } ;
12
12
use rustc_middle:: span_bug;
13
13
use rustc_middle:: ty:: { ResolverAstLowering , TyCtxt } ;
14
+ use rustc_span:: def_id:: DefId ;
14
15
use rustc_span:: edit_distance:: find_best_match_for_name;
15
16
use rustc_span:: { DUMMY_SP , DesugaringKind , Ident , Span , Symbol , kw, sym} ;
16
17
use smallvec:: { SmallVec , smallvec} ;
@@ -135,10 +136,92 @@ impl<'hir> LoweringContext<'_, 'hir> {
135
136
}
136
137
}
137
138
139
+ fn generate_extra_attrs_for_item_kind (
140
+ & mut self ,
141
+ id : NodeId ,
142
+ i : & ItemKind ,
143
+ ) -> Vec < hir:: Attribute > {
144
+ match i {
145
+ ItemKind :: Fn ( box Fn { eii_impls, .. } ) if eii_impls. is_empty ( ) => Vec :: new ( ) ,
146
+ ItemKind :: Fn ( box Fn { eii_impls, .. } ) => {
147
+ vec ! [ hir:: Attribute :: Parsed ( AttributeKind :: EiiImpls (
148
+ eii_impls
149
+ . iter( )
150
+ . flat_map(
151
+ |EiiImpl {
152
+ node_id,
153
+ eii_macro_path,
154
+ impl_safety,
155
+ span,
156
+ inner_span,
157
+ is_default,
158
+ } | {
159
+ self . lower_path_simple_eii( * node_id, eii_macro_path) . map( |did| {
160
+ hir:: attrs:: EiiImpl {
161
+ eii_macro: did,
162
+ span: self . lower_span( * span) ,
163
+ inner_span: self . lower_span( * inner_span) ,
164
+ impl_marked_unsafe: self
165
+ . lower_safety( * impl_safety, hir:: Safety :: Safe )
166
+ . is_unsafe( ) ,
167
+ is_default: * is_default,
168
+ }
169
+ } )
170
+ } ,
171
+ )
172
+ . collect( ) ,
173
+ ) ) ]
174
+ }
175
+ ItemKind :: MacroDef (
176
+ _,
177
+ MacroDef {
178
+ eii_extern_target : Some ( EiiExternTarget { extern_item_path, impl_unsafe, span } ) ,
179
+ ..
180
+ } ,
181
+ ) => self
182
+ . lower_path_simple_eii ( id, extern_item_path)
183
+ . map ( |did| {
184
+ vec ! [ hir:: Attribute :: Parsed ( AttributeKind :: EiiExternTarget ( EiiDecl {
185
+ eii_extern_target: did,
186
+ impl_unsafe: * impl_unsafe,
187
+ span: self . lower_span( * span) ,
188
+ } ) ) ]
189
+ } )
190
+ . unwrap_or_default ( ) ,
191
+ ItemKind :: ExternCrate ( ..)
192
+ | ItemKind :: Use ( ..)
193
+ | ItemKind :: Static ( ..)
194
+ | ItemKind :: Const ( ..)
195
+ | ItemKind :: Mod ( ..)
196
+ | ItemKind :: ForeignMod ( ..)
197
+ | ItemKind :: GlobalAsm ( ..)
198
+ | ItemKind :: TyAlias ( ..)
199
+ | ItemKind :: Enum ( ..)
200
+ | ItemKind :: Struct ( ..)
201
+ | ItemKind :: Union ( ..)
202
+ | ItemKind :: Trait ( ..)
203
+ | ItemKind :: TraitAlias ( ..)
204
+ | ItemKind :: Impl ( ..)
205
+ | ItemKind :: MacCall ( ..)
206
+ | ItemKind :: MacroDef ( ..)
207
+ | ItemKind :: Delegation ( ..)
208
+ | ItemKind :: DelegationMac ( ..) => Vec :: new ( ) ,
209
+ }
210
+ }
211
+
138
212
fn lower_item ( & mut self , i : & Item ) -> & ' hir hir:: Item < ' hir > {
139
213
let vis_span = self . lower_span ( i. vis . span ) ;
140
214
let hir_id = hir:: HirId :: make_owner ( self . current_hir_id_owner . def_id ) ;
141
- let attrs = self . lower_attrs ( hir_id, & i. attrs , i. span , Target :: from_ast_item ( i) ) ;
215
+
216
+ let extra_hir_attributes = self . generate_extra_attrs_for_item_kind ( i. id , & i. kind ) ;
217
+ let attrs = self . lower_attrs_with_extra (
218
+ hir_id,
219
+ & i. attrs ,
220
+ i. span ,
221
+ Target :: from_ast_item ( i) ,
222
+ & extra_hir_attributes,
223
+ ) ;
224
+
142
225
let kind = self . lower_item_kind ( i. span , i. id , hir_id, attrs, vis_span, & i. kind ) ;
143
226
let item = hir:: Item {
144
227
owner_id : hir_id. expect_owner ( ) ,
@@ -467,6 +550,16 @@ impl<'hir> LoweringContext<'_, 'hir> {
467
550
}
468
551
}
469
552
553
+ fn lower_path_simple_eii ( & mut self , id : NodeId , path : & Path ) -> Option < DefId > {
554
+ let res = self . resolver . get_partial_res ( id) ?;
555
+ let Some ( did) = res. expect_full_res ( ) . opt_def_id ( ) else {
556
+ self . dcx ( ) . span_delayed_bug ( path. span , "should have errored in resolve" ) ;
557
+ return None ;
558
+ } ;
559
+
560
+ Some ( did)
561
+ }
562
+
470
563
fn lower_const_item (
471
564
& mut self ,
472
565
ty : & Ty ,
0 commit comments