@@ -109,14 +109,23 @@ pub struct DefMap {
109109 /// this contains all kinds of macro, not just `macro_rules!` macro.
110110 macro_use_prelude : FxHashMap < Name , MacroId > ,
111111
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 {
112124 /// Side table for resolving derive helpers.
113125 exported_derives : FxHashMap < MacroDefId , Box < [ Name ] > > ,
114126 fn_proc_macro_mapping : FxHashMap < FunctionId , ProcMacroId > ,
115127 /// The error that occurred when failing to load the proc-macro dll.
116128 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 ) > > ,
120129
121130 /// Custom attributes registered with `#![register_attr]`.
122131 registered_attrs : Vec < SmolStr > ,
@@ -131,7 +140,6 @@ pub struct DefMap {
131140
132141 edition : Edition ,
133142 recursion_limit : Option < u32 > ,
134- diagnostics : Vec < DefDiagnostic > ,
135143}
136144
137145/// For `DefMap`s computed for a block expression, this stores its location in the parent map.
@@ -278,7 +286,7 @@ impl DefMap {
278286 let module_data =
279287 ModuleData :: new ( ModuleOrigin :: BlockExpr { block : block. ast_id } , visibility) ;
280288
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) ;
282290 def_map. block = Some ( BlockInfo {
283291 block : block_id,
284292 parent : BlockRelativeModuleId {
@@ -300,23 +308,25 @@ impl DefMap {
300308 _c : Count :: new ( ) ,
301309 block : None ,
302310 krate,
303- edition,
304- recursion_limit : None ,
305311 extern_prelude : FxHashMap :: default ( ) ,
306312 macro_use_prelude : FxHashMap :: default ( ) ,
307- exported_derives : FxHashMap :: default ( ) ,
308- fn_proc_macro_mapping : FxHashMap :: default ( ) ,
309- proc_macro_loading_error : None ,
310313 derive_helpers_in_scope : FxHashMap :: default ( ) ,
311314 prelude : None ,
312315 modules,
313- registered_attrs : Vec :: new ( ) ,
314- registered_tools : Vec :: new ( ) ,
315- unstable_features : FxHashSet :: default ( ) ,
316316 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+ } ,
320330 }
321331 }
322332
@@ -339,31 +349,31 @@ impl DefMap {
339349 }
340350
341351 pub fn registered_tools ( & self ) -> & [ SmolStr ] {
342- & self . registered_tools
352+ & self . data . registered_tools
343353 }
344354
345355 pub fn registered_attrs ( & self ) -> & [ SmolStr ] {
346- & self . registered_attrs
356+ & self . data . registered_attrs
347357 }
348358
349359 pub fn is_unstable_feature_enabled ( & self , feature : & str ) -> bool {
350- self . unstable_features . contains ( feature)
360+ self . data . unstable_features . contains ( feature)
351361 }
352362
353363 pub fn is_rustc_coherence_is_core ( & self ) -> bool {
354- self . rustc_coherence_is_core
364+ self . data . rustc_coherence_is_core
355365 }
356366
357367 pub fn is_no_std ( & self ) -> bool {
358- self . no_std || self . no_core
368+ self . data . no_std || self . data . no_core
359369 }
360370
361371 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 ( )
363373 }
364374
365375 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 ( )
367377 }
368378
369379 pub fn krate ( & self ) -> CrateId {
@@ -540,25 +550,28 @@ impl DefMap {
540550 // Exhaustive match to require handling new fields.
541551 let Self {
542552 _c : _,
543- exported_derives,
544553 extern_prelude,
545554 macro_use_prelude,
546555 diagnostics,
547556 modules,
548- registered_attrs,
549- registered_tools,
550- fn_proc_macro_mapping,
551557 derive_helpers_in_scope,
552- unstable_features,
553- proc_macro_loading_error : _,
554558 block : _,
555- edition : _,
556- recursion_limit : _,
557559 krate : _,
558560 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+ } ,
562575 } = self ;
563576
564577 extern_prelude. shrink_to_fit ( ) ;
@@ -583,7 +596,7 @@ impl DefMap {
583596 }
584597
585598 pub fn recursion_limit ( & self ) -> Option < u32 > {
586- self . recursion_limit
599+ self . data . recursion_limit
587600 }
588601}
589602
0 commit comments