resolve: Migrate a special ambiguity for glob vs non-glob bindings

in the same module to the usual ambiguity infra in `resolve_ident_in_scope_set`
This commit is contained in:
Vadim Petrochenkov 2025-12-03 22:46:42 +03:00
parent 75d90094e7
commit bcfbb5619c
3 changed files with 14 additions and 46 deletions

View file

@ -783,9 +783,18 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
Some(AmbiguityKind::GlobVsOuter)
} else if innermost_binding.may_appear_after(parent_scope.expansion, binding) {
Some(AmbiguityKind::MoreExpandedVsOuter)
} else if innermost_binding.expansion != LocalExpnId::ROOT
&& let Scope::ModuleGlobs(m1, _) = scope
&& let Scope::ModuleNonGlobs(m2, _) = innermost_scope
&& m1 == m2
{
// FIXME: this error is too conservative and technically unnecessary now when module
// scope is split into two scopes, remove it with lang team approval.
Some(AmbiguityKind::GlobVsExpanded)
} else {
None
};
if let Some(kind) = ambiguity_error_kind {
// Skip ambiguity errors for extern flag bindings "overridden"
// by extern item bindings.
@ -1008,7 +1017,6 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
return self.get_mut().finalize_module_binding(
ident,
binding,
if resolution.non_glob_binding.is_some() { resolution.glob_binding } else { None },
parent_scope,
module,
finalize,
@ -1070,7 +1078,6 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
return self.get_mut().finalize_module_binding(
ident,
binding,
if resolution.non_glob_binding.is_some() { resolution.glob_binding } else { None },
parent_scope,
module,
finalize,
@ -1182,7 +1189,6 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
&mut self,
ident: Ident,
binding: Option<NameBinding<'ra>>,
shadowed_glob: Option<NameBinding<'ra>>,
parent_scope: &ParentScope<'ra>,
module: Module<'ra>,
finalize: Finalize,
@ -1210,24 +1216,6 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
}
}
// Forbid expanded shadowing to avoid time travel.
if let Some(shadowed_glob) = shadowed_glob
&& shadowing == Shadowing::Restricted
&& finalize.stage == Stage::Early
&& binding.expansion != LocalExpnId::ROOT
&& binding.res() != shadowed_glob.res()
{
self.ambiguity_errors.push(AmbiguityError {
kind: AmbiguityKind::GlobVsExpanded,
ident,
b1: binding,
b2: shadowed_glob,
scope1: Scope::ModuleGlobs(self.empty_module, None),
scope2: Scope::ModuleGlobs(self.empty_module, None),
warning: false,
});
}
if shadowing == Shadowing::Unrestricted
&& binding.expansion != LocalExpnId::ROOT
&& let NameBindingKind::Import { import, .. } = binding.kind

View file

@ -11,7 +11,6 @@ mod foo {
fn f() {
use foo::*;
bar::m! { //~ ERROR ambiguous
//~| ERROR `bar` is ambiguous
mod bar { pub use two_macros::m; }
}
}

View file

@ -1,22 +1,3 @@
error[E0659]: `bar` is ambiguous
--> $DIR/macro-paths.rs:13:5
|
LL | bar::m! {
| ^^^ ambiguous name
|
= note: ambiguous because of a conflict between a name from a glob import and a macro-expanded name in the same module during import or macro resolution
note: `bar` could refer to the module defined here
--> $DIR/macro-paths.rs:15:9
|
LL | mod bar { pub use two_macros::m; }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: `bar` could also refer to the module imported here
--> $DIR/macro-paths.rs:12:9
|
LL | use foo::*;
| ^^^^^^
= help: consider adding an explicit import of `bar` to disambiguate
error[E0659]: `bar` is ambiguous
--> $DIR/macro-paths.rs:13:5
|
@ -25,7 +6,7 @@ LL | bar::m! {
|
= note: ambiguous because of a conflict between a macro-expanded name and a less macro-expanded name from outer scope during import or macro resolution
note: `bar` could refer to the module defined here
--> $DIR/macro-paths.rs:15:9
--> $DIR/macro-paths.rs:14:9
|
LL | mod bar { pub use two_macros::m; }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@ -36,19 +17,19 @@ LL | use foo::*;
| ^^^^^^
error[E0659]: `baz` is ambiguous
--> $DIR/macro-paths.rs:24:5
--> $DIR/macro-paths.rs:23:5
|
LL | baz::m! {
| ^^^ ambiguous name
|
= note: ambiguous because of a conflict between a macro-expanded name and a less macro-expanded name from outer scope during import or macro resolution
note: `baz` could refer to the module defined here
--> $DIR/macro-paths.rs:25:9
--> $DIR/macro-paths.rs:24:9
|
LL | mod baz { pub use two_macros::m; }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: `baz` could also refer to the module defined here
--> $DIR/macro-paths.rs:19:1
--> $DIR/macro-paths.rs:18:1
|
LL | / pub mod baz {
LL | | pub use two_macros::m;
@ -56,6 +37,6 @@ LL | | }
| |_^
= help: use `crate::baz` to refer to this module unambiguously
error: aborting due to 3 previous errors
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0659`.