Skip to content

Commit 414a86e

Browse files
committed
resolve: Add some comments to in-module resolution
1 parent c2533b6 commit 414a86e

File tree

1 file changed

+31
-14
lines changed

1 file changed

+31
-14
lines changed

src/librustc_resolve/resolve_imports.rs

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ impl<'a> Resolver<'a> {
130130
}
131131

132132
/// 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.
134134
pub fn resolve_ident_in_module_unadjusted(&mut self,
135135
module: Module<'a>,
136136
ident: Ident,
@@ -187,7 +187,7 @@ impl<'a> Resolver<'a> {
187187
}
188188
}
189189

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. ---
191191

192192
// Check if one of single imports can still define the name,
193193
// if it can then our result is not determined and can be invalidated.
@@ -207,27 +207,43 @@ impl<'a> Resolver<'a> {
207207
}
208208
}
209209

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();
212211
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 =>
215217
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
217225
_ => return Err(Undetermined),
218226
}
219227

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.
221236
if restricted_shadowing && module.def().is_some() {
222237
return Err(Determined);
223238
}
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()) {
226242
continue
227243
}
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));
229245
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()) {
231247
Some(Some(def)) => self.current_module = self.macro_def_scope(def),
232248
Some(None) => {}
233249
None => continue,
@@ -236,8 +252,9 @@ impl<'a> Resolver<'a> {
236252
module, ident, ns, false, false, path_span,
237253
);
238254
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),
241258
}
242259
}
243260

0 commit comments

Comments
 (0)