Skip to content

Commit 07d616f

Browse files
committed
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`
1 parent b34ea1d commit 07d616f

File tree

3 files changed

+15
-46
lines changed

3 files changed

+15
-46
lines changed

compiler/rustc_resolve/src/ident.rs

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -825,9 +825,19 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
825825
Some(AmbiguityKind::GlobVsOuter)
826826
} else if innermost_binding.may_appear_after(parent_scope.expansion, binding) {
827827
Some(AmbiguityKind::MoreExpandedVsOuter)
828+
} else if innermost_binding.expansion != LocalExpnId::ROOT
829+
&& binding.is_glob_import()
830+
&& !innermost_binding.is_glob_import()
831+
&& self.binding_parent_modules.get(&innermost_binding)
832+
== Some(&self.binding_parent_modules[&binding])
833+
{
834+
// FIXME: this error is too conservative and technically unnecessary now when module
835+
// scope is split into two scopes, remove it with lang team approval.
836+
Some(AmbiguityKind::GlobVsExpanded)
828837
} else {
829838
None
830839
};
840+
831841
// Skip ambiguity errors for extern flag bindings "overridden"
832842
// by extern item bindings.
833843
// FIXME: Remove with lang team approval.
@@ -1057,7 +1067,6 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
10571067
return self.get_mut().finalize_module_binding(
10581068
ident,
10591069
binding,
1060-
if resolution.non_glob_binding.is_some() { resolution.glob_binding } else { None },
10611070
parent_scope,
10621071
module,
10631072
finalize,
@@ -1119,7 +1128,6 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
11191128
return self.get_mut().finalize_module_binding(
11201129
ident,
11211130
binding,
1122-
if resolution.non_glob_binding.is_some() { resolution.glob_binding } else { None },
11231131
parent_scope,
11241132
module,
11251133
finalize,
@@ -1231,7 +1239,6 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
12311239
&mut self,
12321240
ident: Ident,
12331241
binding: Option<NameBinding<'ra>>,
1234-
shadowed_glob: Option<NameBinding<'ra>>,
12351242
parent_scope: &ParentScope<'ra>,
12361243
module: Module<'ra>,
12371244
finalize: Finalize,
@@ -1259,24 +1266,6 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
12591266
}
12601267
}
12611268

1262-
// Forbid expanded shadowing to avoid time travel.
1263-
if let Some(shadowed_glob) = shadowed_glob
1264-
&& shadowing == Shadowing::Restricted
1265-
&& finalize.stage == Stage::Early
1266-
&& binding.expansion != LocalExpnId::ROOT
1267-
&& binding.res() != shadowed_glob.res()
1268-
{
1269-
self.ambiguity_errors.push(AmbiguityError {
1270-
kind: AmbiguityKind::GlobVsExpanded,
1271-
ident,
1272-
b1: binding,
1273-
b2: shadowed_glob,
1274-
warning: false,
1275-
misc1: AmbiguityErrorMisc::None,
1276-
misc2: AmbiguityErrorMisc::None,
1277-
});
1278-
}
1279-
12801269
if shadowing == Shadowing::Unrestricted
12811270
&& binding.expansion != LocalExpnId::ROOT
12821271
&& let NameBindingKind::Import { import, .. } = binding.kind

tests/ui/imports/macro-paths.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ mod foo {
1111
fn f() {
1212
use foo::*;
1313
bar::m! { //~ ERROR ambiguous
14-
//~| ERROR `bar` is ambiguous
1514
mod bar { pub use two_macros::m; }
1615
}
1716
}
Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,3 @@
1-
error[E0659]: `bar` is ambiguous
2-
--> $DIR/macro-paths.rs:13:5
3-
|
4-
LL | bar::m! {
5-
| ^^^ ambiguous name
6-
|
7-
= 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
8-
note: `bar` could refer to the module defined here
9-
--> $DIR/macro-paths.rs:15:9
10-
|
11-
LL | mod bar { pub use two_macros::m; }
12-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13-
note: `bar` could also refer to the module imported here
14-
--> $DIR/macro-paths.rs:12:9
15-
|
16-
LL | use foo::*;
17-
| ^^^^^^
18-
= help: consider adding an explicit import of `bar` to disambiguate
19-
201
error[E0659]: `bar` is ambiguous
212
--> $DIR/macro-paths.rs:13:5
223
|
@@ -25,7 +6,7 @@ LL | bar::m! {
256
|
267
= 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
278
note: `bar` could refer to the module defined here
28-
--> $DIR/macro-paths.rs:15:9
9+
--> $DIR/macro-paths.rs:14:9
2910
|
3011
LL | mod bar { pub use two_macros::m; }
3112
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -36,26 +17,26 @@ LL | use foo::*;
3617
| ^^^^^^
3718

3819
error[E0659]: `baz` is ambiguous
39-
--> $DIR/macro-paths.rs:24:5
20+
--> $DIR/macro-paths.rs:23:5
4021
|
4122
LL | baz::m! {
4223
| ^^^ ambiguous name
4324
|
4425
= 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
4526
note: `baz` could refer to the module defined here
46-
--> $DIR/macro-paths.rs:25:9
27+
--> $DIR/macro-paths.rs:24:9
4728
|
4829
LL | mod baz { pub use two_macros::m; }
4930
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5031
note: `baz` could also refer to the module defined here
51-
--> $DIR/macro-paths.rs:19:1
32+
--> $DIR/macro-paths.rs:18:1
5233
|
5334
LL | / pub mod baz {
5435
LL | | pub use two_macros::m;
5536
LL | | }
5637
| |_^
5738
= help: use `crate::baz` to refer to this module unambiguously
5839

59-
error: aborting due to 3 previous errors
40+
error: aborting due to 2 previous errors
6041

6142
For more information about this error, try `rustc --explain E0659`.

0 commit comments

Comments
 (0)