Skip to content

Commit e7aeb2b

Browse files
committed
resolve: Add more comments to in-module resolution
1 parent 32453db commit e7aeb2b

File tree

1 file changed

+26
-22
lines changed

1 file changed

+26
-22
lines changed

src/librustc_resolve/resolve_imports.rs

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -207,36 +207,39 @@ impl<'a> Resolver<'a> {
207207
}
208208
}
209209

210-
let no_unexpanded_macros = module.unresolved_invocations.borrow().is_empty();
211-
match resolution.binding {
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 =>
217-
return check_usable(self, binding),
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
225-
_ => return Err(Undetermined),
210+
// So we have a resolution that's from a glob import. This resolution is determined
211+
// if it cannot be shadowed by some new item/import expanded from a macro.
212+
// This happens either if there are no unexpanded macros, or expanded names cannot
213+
// shadow globs (that happens in macro namespace or with restricted shadowing).
214+
let unexpanded_macros = !module.unresolved_invocations.borrow().is_empty();
215+
if let Some(binding) = resolution.binding {
216+
if !unexpanded_macros || ns == MacroNS || restricted_shadowing {
217+
return check_usable(self, binding);
218+
} else {
219+
return Err(Undetermined);
220+
}
226221
}
227222

228223
// --- From now on we have no resolution. ---
229224

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.
225+
// Now we are in situation when new item/import can appear only from a glob or a macro
226+
// expansion. With restricted shadowing names from globs and macro expansions cannot
227+
// shadow names from outer scopes, so we can freely fallback from module search to search
228+
// in outer scopes. To continue search in outer scopes we have to lie a bit and return
229+
// `Determined` to `resolve_lexical_macro_path_segment` even if the correct answer
230+
// for in-module resolution could be `Undetermined`.
236231
if restricted_shadowing {
237232
return Err(Determined);
238233
}
239234

235+
// Check if one of unexpanded macros can still define the name,
236+
// if it can then our "no resolution" result is not determined and can be invalidated.
237+
if unexpanded_macros {
238+
return Err(Undetermined);
239+
}
240+
241+
// Check if one of glob imports can still define the name,
242+
// if it can then our "no resolution" result is not determined and can be invalidated.
240243
for glob_import in module.globs.borrow().iter() {
241244
if !self.is_accessible(glob_import.vis.get()) {
242245
continue
@@ -258,6 +261,7 @@ impl<'a> Resolver<'a> {
258261
}
259262
}
260263

264+
// No resolution and no one else can define the name - determinate error.
261265
Err(Determined)
262266
}
263267

0 commit comments

Comments
 (0)