Skip to content

Commit c8cbf5b

Browse files
committed
address review
1 parent b80aba2 commit c8cbf5b

File tree

2 files changed

+19
-12
lines changed

2 files changed

+19
-12
lines changed

compiler/rustc_resolve/src/ident.rs

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
224224
}
225225

226226
#[instrument(skip(self, visitor), level = "debug")]
227-
pub(crate) fn visit_module_scopes<T>(
227+
fn visit_module_scopes<T>(
228228
&mut self,
229229
ns: Namespace,
230230
mut visitor: impl FnMut(&mut Self, ModuleScope) -> Option<T>,
@@ -236,8 +236,8 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
236236
}
237237

238238
scope = match scope {
239-
ModuleScope::NonGlobal => ModuleScope::Global,
240-
ModuleScope::Global => break, // nowhere else to search
239+
ModuleScope::NonGlobal => ModuleScope::Globs,
240+
ModuleScope::Globs => break, // nowhere else to search
241241
};
242242
}
243243

@@ -893,11 +893,8 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
893893
let resolution =
894894
self.resolution(module, key).try_borrow_mut().map_err(|_| (Determined, Weak::No))?; // This happens when there is a cycle of imports.
895895

896-
debug!(?resolution);
897-
898896
let check_usable = |this: &mut Self, binding: NameBinding<'ra>| {
899897
let usable = this.is_accessible_from(binding.vis, parent_scope.module);
900-
debug!(?usable);
901898
if usable { Ok(binding) } else { Err((Determined, Weak::No)) }
902899
};
903900

@@ -923,7 +920,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
923920

924921
None // Continue to global scope
925922
}
926-
ModuleScope::Global => {
923+
ModuleScope::Globs => {
927924
// If we are here, any primary `resolution.binding` is either a glob, None,
928925
// or should be ignored.
929926
let binding = resolution.glob_binding;
@@ -957,7 +954,18 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
957954
return Some(Err((Undetermined, Weak::No)));
958955
}
959956

960-
// A glob resolution is determined if it cannot be shadowed by a macro expansion.
957+
// So we have a resolution that's from a glob import. This resolution is determined
958+
// if it cannot be shadowed by some new item/import expanded from a macro.
959+
// This happens either if there are no unexpanded macros, or expanded names cannot
960+
// shadow globs (that happens in macro namespace or with restricted shadowing).
961+
//
962+
// Additionally, any macro in any module can plant names in the root module if it creates
963+
// `macro_export` macros, so the root module effectively has unresolved invocations if any
964+
// module has unresolved invocations.
965+
// However, it causes resolution/expansion to stuck too often (#53144), so, to make
966+
// progress, we have to ignore those potential unresolved invocations from other modules
967+
// and prohibit access to macro-expanded `macro_export` macros instead (unless restricted
968+
// shadowing is enabled, see `macro_expanded_macro_export_errors`).
961969
if let Some(binding) = binding {
962970
if binding.determined() || ns == MacroNS || shadowing == Shadowing::Restricted {
963971
return Some(check_usable(this, binding));
@@ -970,9 +978,8 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
970978
}
971979
});
972980

973-
match break_result {
974-
Some(result) => return result,
975-
None => {}
981+
if let Some(result) = break_result {
982+
return result;
976983
}
977984

978985
// --- From now on we have no resolution. ---

compiler/rustc_resolve/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ enum Scope<'ra> {
134134
#[derive(Debug, Copy, Clone, PartialEq)]
135135
enum ModuleScope {
136136
NonGlobal,
137-
Global,
137+
Globs,
138138
}
139139

140140
/// Names from different contexts may want to visit different subsets of all specific scopes

0 commit comments

Comments
 (0)