Skip to content

Commit 1b2b0da

Browse files
committed
Match the old logic closer
1 parent 37dc384 commit 1b2b0da

File tree

3 files changed

+12
-30
lines changed

3 files changed

+12
-30
lines changed

compiler/rustc_resolve/src/ident.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,8 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
491491
// Found another solution, if the first one was "weak", report an error.
492492
if this.get_mut().maybe_push_ambiguity(
493493
orig_ident,
494+
ns,
495+
scope_set,
494496
parent_scope,
495497
binding,
496498
innermost_binding,
@@ -798,6 +800,8 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
798800
fn maybe_push_ambiguity(
799801
&mut self,
800802
orig_ident: Ident,
803+
ns: Namespace,
804+
scope_set: ScopeSet<'ra>,
801805
parent_scope: &ParentScope<'ra>,
802806
binding: NameBinding<'ra>,
803807
innermost_binding: NameBinding<'ra>,
@@ -811,6 +815,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
811815
return false;
812816
}
813817

818+
let module_only = matches!(scope_set, ScopeSet::Module(..));
814819
let is_builtin = |res| matches!(res, Res::NonMacroAttr(NonMacroAttrKind::Builtin(..)));
815820
let derive_helper = Res::NonMacroAttr(NonMacroAttrKind::DeriveHelper);
816821
let derive_helper_compat = Res::NonMacroAttr(NonMacroAttrKind::DeriveHelperCompat);
@@ -839,9 +844,12 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
839844
)
840845
} else if innermost_binding.is_glob_import() {
841846
Some(AmbiguityKind::GlobVsOuter)
842-
} else if innermost_binding.may_appear_after(parent_scope.expansion, binding) {
847+
} else if !module_only
848+
&& innermost_binding.may_appear_after(parent_scope.expansion, binding)
849+
{
843850
Some(AmbiguityKind::MoreExpandedVsOuter)
844851
} else if innermost_binding.expansion != LocalExpnId::ROOT
852+
&& (!module_only || ns == MacroNS)
845853
&& binding.is_glob_import()
846854
&& !innermost_binding.is_glob_import()
847855
&& self.binding_parent_modules.get(&innermost_binding)

tests/ui/underscore-imports/shadow.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ mod b {
1414

1515
mod c {
1616
use crate::b::Shadow as _; // Only imports the struct
17-
//~^ ERROR `Shadow` is ambiguous
1817

1918
fn f(x: &()) {
2019
x.deref(); //~ ERROR no method named `deref` found
Lines changed: 3 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,5 @@
1-
error[E0659]: `Shadow` is ambiguous
2-
--> $DIR/shadow.rs:16:19
3-
|
4-
LL | use crate::b::Shadow as _; // Only imports the struct
5-
| ^^^^^^ ambiguous name
6-
|
7-
= 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
8-
note: `Shadow` could refer to the struct defined here
9-
--> $DIR/shadow.rs:10:25
10-
|
11-
LL | ($i:ident) => { pub struct $i; }
12-
| ^^^^^^^^^^^^^^
13-
LL | }
14-
LL | m!(Shadow);
15-
| ---------- in this macro invocation
16-
= help: use `self::Shadow` to refer to this struct unambiguously
17-
note: `Shadow` could also refer to the trait imported here
18-
--> $DIR/shadow.rs:8:13
19-
|
20-
LL | pub use crate::a::*;
21-
| ^^^^^^^^^^^
22-
= help: use `self::Shadow` to refer to this trait unambiguously
23-
= note: this error originates in the macro `m` (in Nightly builds, run with -Z macro-backtrace for more info)
24-
251
error[E0599]: no method named `deref` found for reference `&()` in the current scope
26-
--> $DIR/shadow.rs:20:11
2+
--> $DIR/shadow.rs:19:11
273
|
284
LL | x.deref();
295
| ^^^^^ method not found in `&()`
@@ -34,7 +10,6 @@ help: trait `Deref` which provides `deref` is implemented but not in scope; perh
3410
LL + use std::ops::Deref;
3511
|
3612

37-
error: aborting due to 2 previous errors
13+
error: aborting due to 1 previous error
3814

39-
Some errors have detailed explanations: E0599, E0659.
40-
For more information about an error, try `rustc --explain E0599`.
15+
For more information about this error, try `rustc --explain E0599`.

0 commit comments

Comments
 (0)