@@ -85,7 +85,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
85
85
/// Reachable macros with block module parents exist due to `#[macro_export] macro_rules!`,
86
86
/// but they cannot use def-site hygiene, so the assumption holds
87
87
/// (<https://github.com/rust-lang/rust/pull/77984#issuecomment-712445508>).
88
- pub ( crate ) fn get_nearest_non_block_module ( & mut self , mut def_id : DefId ) -> Module < ' ra > {
88
+ pub ( crate ) fn get_nearest_non_block_module ( & self , mut def_id : DefId ) -> Module < ' ra > {
89
89
loop {
90
90
match self . get_module ( def_id) {
91
91
Some ( module) => return module,
@@ -94,44 +94,47 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
94
94
}
95
95
}
96
96
97
- pub ( crate ) fn expect_module ( & mut self , def_id : DefId ) -> Module < ' ra > {
97
+ pub ( crate ) fn expect_module ( & self , def_id : DefId ) -> Module < ' ra > {
98
98
self . get_module ( def_id) . expect ( "argument `DefId` is not a module" )
99
99
}
100
100
101
101
/// If `def_id` refers to a module (in resolver's sense, i.e. a module item, crate root, enum,
102
102
/// or trait), then this function returns that module's resolver representation, otherwise it
103
103
/// returns `None`.
104
- pub ( crate ) fn get_module ( & mut self , def_id : DefId ) -> Option < Module < ' ra > > {
105
- if let module @ Some ( ..) = self . module_map . get ( & def_id) {
106
- return module. copied ( ) ;
107
- }
104
+ pub ( crate ) fn get_module ( & self , def_id : DefId ) -> Option < Module < ' ra > > {
105
+ match def_id. as_local ( ) {
106
+ Some ( local_def_id) => self . local_module_map . get ( & local_def_id) . copied ( ) ,
107
+ None => {
108
+ if let module @ Some ( ..) = self . extern_module_map . borrow ( ) . get ( & def_id) {
109
+ return module. copied ( ) ;
110
+ }
108
111
109
- if !def_id. is_local ( ) {
110
- // Query `def_kind` is not used because query system overhead is too expensive here.
111
- let def_kind = self . cstore ( ) . def_kind_untracked ( def_id) ;
112
- if def_kind. is_module_like ( ) {
113
- let parent = self
114
- . tcx
115
- . opt_parent ( def_id)
116
- . map ( |parent_id| self . get_nearest_non_block_module ( parent_id) ) ;
117
- // Query `expn_that_defined` is not used because
118
- // hashing spans in its result is expensive.
119
- let expn_id = self . cstore ( ) . expn_that_defined_untracked ( def_id, self . tcx . sess ) ;
120
- return Some ( self . new_module (
121
- parent,
122
- ModuleKind :: Def ( def_kind, def_id, Some ( self . tcx . item_name ( def_id) ) ) ,
123
- expn_id,
124
- self . def_span ( def_id) ,
125
- // FIXME: Account for `#[no_implicit_prelude]` attributes.
126
- parent. is_some_and ( |module| module. no_implicit_prelude ) ,
127
- ) ) ;
112
+ // Query `def_kind` is not used because query system overhead is too expensive here.
113
+ let def_kind = self . cstore ( ) . def_kind_untracked ( def_id) ;
114
+ if def_kind. is_module_like ( ) {
115
+ let parent = self
116
+ . tcx
117
+ . opt_parent ( def_id)
118
+ . map ( |parent_id| self . get_nearest_non_block_module ( parent_id) ) ;
119
+ // Query `expn_that_defined` is not used because
120
+ // hashing spans in its result is expensive.
121
+ let expn_id = self . cstore ( ) . expn_that_defined_untracked ( def_id, self . tcx . sess ) ;
122
+ return Some ( self . new_extern_module (
123
+ parent,
124
+ ModuleKind :: Def ( def_kind, def_id, Some ( self . tcx . item_name ( def_id) ) ) ,
125
+ expn_id,
126
+ self . def_span ( def_id) ,
127
+ // FIXME: Account for `#[no_implicit_prelude]` attributes.
128
+ parent. is_some_and ( |module| module. no_implicit_prelude ) ,
129
+ ) ) ;
130
+ }
131
+
132
+ None
128
133
}
129
134
}
130
-
131
- None
132
135
}
133
136
134
- pub ( crate ) fn expn_def_scope ( & mut self , expn_id : ExpnId ) -> Module < ' ra > {
137
+ pub ( crate ) fn expn_def_scope ( & self , expn_id : ExpnId ) -> Module < ' ra > {
135
138
match expn_id. expn_data ( ) . macro_def_id {
136
139
Some ( def_id) => self . macro_def_scope ( def_id) ,
137
140
None => expn_id
@@ -141,7 +144,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
141
144
}
142
145
}
143
146
144
- pub ( crate ) fn macro_def_scope ( & mut self , def_id : DefId ) -> Module < ' ra > {
147
+ pub ( crate ) fn macro_def_scope ( & self , def_id : DefId ) -> Module < ' ra > {
145
148
if let Some ( id) = def_id. as_local ( ) {
146
149
self . local_macro_def_scopes [ & id]
147
150
} else {
@@ -403,7 +406,7 @@ impl<'a, 'ra, 'tcx> BuildReducedGraphVisitor<'a, 'ra, 'tcx> {
403
406
self . r . field_visibility_spans . insert ( def_id, field_vis) ;
404
407
}
405
408
406
- fn block_needs_anonymous_module ( & mut self , block : & Block ) -> bool {
409
+ fn block_needs_anonymous_module ( & self , block : & Block ) -> bool {
407
410
// If any statements are items, we need to create an anonymous module
408
411
block
409
412
. stmts
@@ -758,7 +761,7 @@ impl<'a, 'ra, 'tcx> BuildReducedGraphVisitor<'a, 'ra, 'tcx> {
758
761
if let ast:: ModKind :: Loaded ( _, _, _, Err ( _) ) = mod_kind {
759
762
self . r . mods_with_parse_errors . insert ( def_id) ;
760
763
}
761
- self . parent_scope . module = self . r . new_module (
764
+ self . parent_scope . module = self . r . new_local_module (
762
765
Some ( parent) ,
763
766
ModuleKind :: Def ( def_kind, def_id, Some ( ident. name ) ) ,
764
767
expansion. to_expn_id ( ) ,
@@ -790,7 +793,7 @@ impl<'a, 'ra, 'tcx> BuildReducedGraphVisitor<'a, 'ra, 'tcx> {
790
793
ItemKind :: Enum ( ident, _, _) | ItemKind :: Trait ( box ast:: Trait { ident, .. } ) => {
791
794
self . r . define ( parent, ident, TypeNS , res, vis, sp, expansion) ;
792
795
793
- self . parent_scope . module = self . r . new_module (
796
+ self . parent_scope . module = self . r . new_local_module (
794
797
Some ( parent) ,
795
798
ModuleKind :: Def ( def_kind, def_id, Some ( ident. name ) ) ,
796
799
expansion. to_expn_id ( ) ,
@@ -986,7 +989,7 @@ impl<'a, 'ra, 'tcx> BuildReducedGraphVisitor<'a, 'ra, 'tcx> {
986
989
let parent = self . parent_scope . module ;
987
990
let expansion = self . parent_scope . expansion ;
988
991
if self . block_needs_anonymous_module ( block) {
989
- let module = self . r . new_module (
992
+ let module = self . r . new_local_module (
990
993
Some ( parent) ,
991
994
ModuleKind :: Block ,
992
995
expansion. to_expn_id ( ) ,
@@ -1118,7 +1121,7 @@ impl<'a, 'ra, 'tcx> BuildReducedGraphVisitor<'a, 'ra, 'tcx> {
1118
1121
}
1119
1122
1120
1123
/// Returns `true` if this attribute list contains `macro_use`.
1121
- fn contains_macro_use ( & mut self , attrs : & [ ast:: Attribute ] ) -> bool {
1124
+ fn contains_macro_use ( & self , attrs : & [ ast:: Attribute ] ) -> bool {
1122
1125
for attr in attrs {
1123
1126
if attr. has_name ( sym:: macro_escape) {
1124
1127
let inner_attribute = matches ! ( attr. style, ast:: AttrStyle :: Inner ) ;
0 commit comments