resolve: Avoid additional ambiguities from splitting modules into two scopes

This commit is contained in:
Vadim Petrochenkov 2026-01-02 14:29:23 +03:00
parent 78c61beb48
commit 2e123aef70
2 changed files with 40 additions and 1 deletions

View file

@ -828,8 +828,21 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
&& innermost_results[1..].iter().any(|(b, s)| {
matches!(s, Scope::ExternPreludeItems) && *b != innermost_binding
});
// Skip ambiguity errors for nonglob module bindings "overridden"
// by glob module bindings in the same module.
// FIXME: Remove with lang team approval.
let issue_149681_hack = match scope {
Scope::ModuleGlobs(m1, _)
if innermost_results[1..]
.iter()
.any(|(_, s)| matches!(*s, Scope::ModuleNonGlobs(m2, _) if m1 == m2)) =>
{
true
}
_ => false,
};
if issue_145575_hack {
if issue_145575_hack || issue_149681_hack {
self.issue_145575_hack_applied = true;
} else {
self.ambiguity_errors.push(AmbiguityError {

View file

@ -0,0 +1,26 @@
// Test for a regression introduced by splitting module scope into two scopes
// (similar to issue #145575).
//@ check-pass
//@ edition: 2018..
#[macro_use]
mod one {
// Macro that is in a different module, but still in scope due to `macro_use`
macro_rules! mac { () => {} }
pub(crate) use mac;
}
mod other {
macro_rules! mac { () => {} }
pub(crate) use mac;
}
// Single import of the same in the current module.
use one::mac;
// Glob import of a different macro in the current module (should be an ambiguity).
use other::*;
fn main() {
mac!(); // OK for now, the ambiguity is not reported
}