@@ -130,7 +130,7 @@ impl<'a> Resolver<'a> {
130
130
}
131
131
132
132
/// Attempts to resolve `ident` in namespaces `ns` of `module`.
133
- /// Invariant: if `record_used` is `Some`, import resolution must be complete.
133
+ /// Invariant: if `record_used` is `Some`, expansion and import resolution must be complete.
134
134
pub fn resolve_ident_in_module_unadjusted ( & mut self ,
135
135
module : Module < ' a > ,
136
136
ident : Ident ,
@@ -187,7 +187,7 @@ impl<'a> Resolver<'a> {
187
187
}
188
188
}
189
189
190
- // From now on we either have a glob resolution or no resolution.
190
+ // --- From now on we either have a glob resolution or no resolution. ---
191
191
192
192
// Check if one of single imports can still define the name,
193
193
// if it can then our result is not determined and can be invalidated.
@@ -207,27 +207,43 @@ impl<'a> Resolver<'a> {
207
207
}
208
208
}
209
209
210
- let no_unresolved_invocations =
211
- restricted_shadowing || module. unresolved_invocations . borrow ( ) . is_empty ( ) ;
210
+ let no_unexpanded_macros = module. unresolved_invocations . borrow ( ) . is_empty ( ) ;
212
211
match resolution. binding {
213
- // In `MacroNS`, expanded bindings do not shadow (enforced in `try_define`).
214
- Some ( binding) if no_unresolved_invocations || ns == MacroNS =>
212
+ // So we have a resolution that's from a glob import. This resolution is determined
213
+ // if it cannot be shadowed by some new item/import expanded from a macro.
214
+ // This happens either if there are no unexpanded macros, or expanded names cannot
215
+ // shadow globs (that happens in macro namespace or with restricted shadowing).
216
+ Some ( binding) if no_unexpanded_macros || ns == MacroNS || restricted_shadowing =>
215
217
return check_usable ( self , binding) ,
216
- None if no_unresolved_invocations => { }
218
+ // If we have no resolution, then it's a determined error it some new item/import
219
+ // cannot appear from a macro expansion or an undetermined glob.
220
+ None if no_unexpanded_macros => { } // go check for globs below
221
+ // This is actually an undetermined error, but we need to return determinate error
222
+ // due to subtle interactions with `resolve_lexical_macro_path_segment`
223
+ // that are going to be removed in the next commit.
224
+ None if restricted_shadowing => { } // go check for globs below
217
225
_ => return Err ( Undetermined ) ,
218
226
}
219
227
220
- // Check if the globs are determined
228
+ // --- From now on we have no resolution. ---
229
+
230
+ // Check if one of glob imports can still define the name,
231
+ // if it can then our "no resolution" result is not determined and can be invalidated.
232
+
233
+ // What on earth is this?
234
+ // Apparently one more subtle interaction with `resolve_lexical_macro_path_segment`
235
+ // that are going to be removed in the next commit.
221
236
if restricted_shadowing && module. def ( ) . is_some ( ) {
222
237
return Err ( Determined ) ;
223
238
}
224
- for directive in module. globs . borrow ( ) . iter ( ) {
225
- if !self . is_accessible ( directive. vis . get ( ) ) {
239
+
240
+ for glob_import in module. globs . borrow ( ) . iter ( ) {
241
+ if !self . is_accessible ( glob_import. vis . get ( ) ) {
226
242
continue
227
243
}
228
- let module = unwrap_or ! ( directive . imported_module. get( ) , return Err ( Undetermined ) ) ;
244
+ let module = unwrap_or ! ( glob_import . imported_module. get( ) , return Err ( Undetermined ) ) ;
229
245
let ( orig_current_module, mut ident) = ( self . current_module , ident. modern ( ) ) ;
230
- match ident. span . glob_adjust ( module. expansion , directive . span . ctxt ( ) . modern ( ) ) {
246
+ match ident. span . glob_adjust ( module. expansion , glob_import . span . ctxt ( ) . modern ( ) ) {
231
247
Some ( Some ( def) ) => self . current_module = self . macro_def_scope ( def) ,
232
248
Some ( None ) => { }
233
249
None => continue ,
@@ -236,8 +252,9 @@ impl<'a> Resolver<'a> {
236
252
module, ident, ns, false , false , path_span,
237
253
) ;
238
254
self . current_module = orig_current_module;
239
- if let Err ( Undetermined ) = result {
240
- return Err ( Undetermined ) ;
255
+ match result {
256
+ Err ( Determined ) => continue ,
257
+ Ok ( _) | Err ( Undetermined ) => return Err ( Undetermined ) ,
241
258
}
242
259
}
243
260
0 commit comments