@@ -109,14 +109,23 @@ pub struct DefMap {
109
109
/// this contains all kinds of macro, not just `macro_rules!` macro.
110
110
macro_use_prelude : FxHashMap < Name , MacroId > ,
111
111
112
+ /// Tracks which custom derives are in scope for an item, to allow resolution of derive helper
113
+ /// attributes.
114
+ derive_helpers_in_scope : FxHashMap < AstId < ast:: Item > , Vec < ( Name , MacroId , MacroCallId ) > > ,
115
+
116
+ diagnostics : Vec < DefDiagnostic > ,
117
+
118
+ // FIXME: Arc this so we can share it with block def maps
119
+ data : CrateData ,
120
+ }
121
+
122
+ #[ derive( Debug , PartialEq , Eq ) ]
123
+ struct CrateData {
112
124
/// Side table for resolving derive helpers.
113
125
exported_derives : FxHashMap < MacroDefId , Box < [ Name ] > > ,
114
126
fn_proc_macro_mapping : FxHashMap < FunctionId , ProcMacroId > ,
115
127
/// The error that occurred when failing to load the proc-macro dll.
116
128
proc_macro_loading_error : Option < Box < str > > ,
117
- /// Tracks which custom derives are in scope for an item, to allow resolution of derive helper
118
- /// attributes.
119
- derive_helpers_in_scope : FxHashMap < AstId < ast:: Item > , Vec < ( Name , MacroId , MacroCallId ) > > ,
120
129
121
130
/// Custom attributes registered with `#![register_attr]`.
122
131
registered_attrs : Vec < SmolStr > ,
@@ -131,7 +140,6 @@ pub struct DefMap {
131
140
132
141
edition : Edition ,
133
142
recursion_limit : Option < u32 > ,
134
- diagnostics : Vec < DefDiagnostic > ,
135
143
}
136
144
137
145
/// For `DefMap`s computed for a block expression, this stores its location in the parent map.
@@ -278,7 +286,7 @@ impl DefMap {
278
286
let module_data =
279
287
ModuleData :: new ( ModuleOrigin :: BlockExpr { block : block. ast_id } , visibility) ;
280
288
281
- let mut def_map = DefMap :: empty ( krate, parent_map. edition , module_data) ;
289
+ let mut def_map = DefMap :: empty ( krate, parent_map. data . edition , module_data) ;
282
290
def_map. block = Some ( BlockInfo {
283
291
block : block_id,
284
292
parent : BlockRelativeModuleId {
@@ -300,23 +308,25 @@ impl DefMap {
300
308
_c : Count :: new ( ) ,
301
309
block : None ,
302
310
krate,
303
- edition,
304
- recursion_limit : None ,
305
311
extern_prelude : FxHashMap :: default ( ) ,
306
312
macro_use_prelude : FxHashMap :: default ( ) ,
307
- exported_derives : FxHashMap :: default ( ) ,
308
- fn_proc_macro_mapping : FxHashMap :: default ( ) ,
309
- proc_macro_loading_error : None ,
310
313
derive_helpers_in_scope : FxHashMap :: default ( ) ,
311
314
prelude : None ,
312
315
modules,
313
- registered_attrs : Vec :: new ( ) ,
314
- registered_tools : Vec :: new ( ) ,
315
- unstable_features : FxHashSet :: default ( ) ,
316
316
diagnostics : Vec :: new ( ) ,
317
- rustc_coherence_is_core : false ,
318
- no_core : false ,
319
- no_std : false ,
317
+ data : CrateData {
318
+ recursion_limit : None ,
319
+ exported_derives : FxHashMap :: default ( ) ,
320
+ fn_proc_macro_mapping : FxHashMap :: default ( ) ,
321
+ proc_macro_loading_error : None ,
322
+ registered_attrs : Vec :: new ( ) ,
323
+ registered_tools : Vec :: new ( ) ,
324
+ unstable_features : FxHashSet :: default ( ) ,
325
+ rustc_coherence_is_core : false ,
326
+ no_core : false ,
327
+ no_std : false ,
328
+ edition,
329
+ } ,
320
330
}
321
331
}
322
332
@@ -339,31 +349,31 @@ impl DefMap {
339
349
}
340
350
341
351
pub fn registered_tools ( & self ) -> & [ SmolStr ] {
342
- & self . registered_tools
352
+ & self . data . registered_tools
343
353
}
344
354
345
355
pub fn registered_attrs ( & self ) -> & [ SmolStr ] {
346
- & self . registered_attrs
356
+ & self . data . registered_attrs
347
357
}
348
358
349
359
pub fn is_unstable_feature_enabled ( & self , feature : & str ) -> bool {
350
- self . unstable_features . contains ( feature)
360
+ self . data . unstable_features . contains ( feature)
351
361
}
352
362
353
363
pub fn is_rustc_coherence_is_core ( & self ) -> bool {
354
- self . rustc_coherence_is_core
364
+ self . data . rustc_coherence_is_core
355
365
}
356
366
357
367
pub fn is_no_std ( & self ) -> bool {
358
- self . no_std || self . no_core
368
+ self . data . no_std || self . data . no_core
359
369
}
360
370
361
371
pub fn fn_as_proc_macro ( & self , id : FunctionId ) -> Option < ProcMacroId > {
362
- self . fn_proc_macro_mapping . get ( & id) . copied ( )
372
+ self . data . fn_proc_macro_mapping . get ( & id) . copied ( )
363
373
}
364
374
365
375
pub fn proc_macro_loading_error ( & self ) -> Option < & str > {
366
- self . proc_macro_loading_error . as_deref ( )
376
+ self . data . proc_macro_loading_error . as_deref ( )
367
377
}
368
378
369
379
pub fn krate ( & self ) -> CrateId {
@@ -540,25 +550,28 @@ impl DefMap {
540
550
// Exhaustive match to require handling new fields.
541
551
let Self {
542
552
_c : _,
543
- exported_derives,
544
553
extern_prelude,
545
554
macro_use_prelude,
546
555
diagnostics,
547
556
modules,
548
- registered_attrs,
549
- registered_tools,
550
- fn_proc_macro_mapping,
551
557
derive_helpers_in_scope,
552
- unstable_features,
553
- proc_macro_loading_error : _,
554
558
block : _,
555
- edition : _,
556
- recursion_limit : _,
557
559
krate : _,
558
560
prelude : _,
559
- rustc_coherence_is_core : _,
560
- no_core : _,
561
- no_std : _,
561
+ data :
562
+ CrateData {
563
+ exported_derives,
564
+ fn_proc_macro_mapping,
565
+ registered_attrs,
566
+ registered_tools,
567
+ unstable_features,
568
+ proc_macro_loading_error : _,
569
+ rustc_coherence_is_core : _,
570
+ no_core : _,
571
+ no_std : _,
572
+ edition : _,
573
+ recursion_limit : _,
574
+ } ,
562
575
} = self ;
563
576
564
577
extern_prelude. shrink_to_fit ( ) ;
@@ -583,7 +596,7 @@ impl DefMap {
583
596
}
584
597
585
598
pub fn recursion_limit ( & self ) -> Option < u32 > {
586
- self . recursion_limit
599
+ self . data . recursion_limit
587
600
}
588
601
}
589
602
0 commit comments