Skip to content

Commit 588eab2

Browse files
Auto merge of #149681 - petrochenkov:openapi1, r=<try>
resolve: Split `Scope::Module` into two scopes for non-glob and glob bindings
2 parents 97b131c + fdaf022 commit 588eab2

File tree

12 files changed

+212
-161
lines changed

12 files changed

+212
-161
lines changed

compiler/rustc_resolve/src/diagnostics.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1205,9 +1205,12 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
12051205
}
12061206
}
12071207
}
1208-
Scope::Module(module, _) => {
1208+
Scope::ModuleNonGlobs(module, _) => {
12091209
this.add_module_candidates(module, suggestions, filter_fn, None);
12101210
}
1211+
Scope::ModuleGlobs(..) => {
1212+
// Already handled in `ModuleNonGlobs`.
1213+
}
12111214
Scope::MacroUsePrelude => {
12121215
suggestions.extend(this.macro_use_prelude.iter().filter_map(
12131216
|(name, binding)| {

compiler/rustc_resolve/src/ident.rs

Lines changed: 152 additions & 128 deletions
Large diffs are not rendered by default.

compiler/rustc_resolve/src/imports.rs

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -390,20 +390,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
390390
(old_glob @ true, false) | (old_glob @ false, true) => {
391391
let (glob_binding, non_glob_binding) =
392392
if old_glob { (old_binding, binding) } else { (binding, old_binding) };
393-
if ns == MacroNS
394-
&& non_glob_binding.expansion != LocalExpnId::ROOT
395-
&& glob_binding.res() != non_glob_binding.res()
396-
{
397-
resolution.non_glob_binding = Some(this.new_ambiguity_binding(
398-
AmbiguityKind::GlobVsExpanded,
399-
non_glob_binding,
400-
glob_binding,
401-
false,
402-
));
403-
} else {
404-
resolution.non_glob_binding = Some(non_glob_binding);
405-
}
406-
393+
resolution.non_glob_binding = Some(non_glob_binding);
407394
if let Some(old_glob_binding) = resolution.glob_binding {
408395
assert!(old_glob_binding.is_glob_import());
409396
if glob_binding.res() != old_glob_binding.res() {

compiler/rustc_resolve/src/late.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ use tracing::{debug, instrument, trace};
4141

4242
use crate::{
4343
BindingError, BindingKey, Finalize, LexicalScopeBinding, Module, ModuleOrUniformRoot,
44-
NameBinding, ParentScope, PathResult, ResolutionError, Resolver, Segment, TyCtxt, UseError,
45-
Used, errors, path_names_to_string, rustdoc,
44+
NameBinding, ParentScope, PathResult, ResolutionError, Resolver, Segment, Stage, TyCtxt,
45+
UseError, Used, errors, path_names_to_string, rustdoc,
4646
};
4747

4848
mod diagnostics;
@@ -1498,7 +1498,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
14981498
opt_ns,
14991499
&self.parent_scope,
15001500
Some(source),
1501-
finalize,
1501+
finalize.map(|finalize| Finalize { stage: Stage::Late, ..finalize }),
15021502
Some(&self.ribs),
15031503
None,
15041504
None,

compiler/rustc_resolve/src/lib.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,14 @@ enum Scope<'ra> {
122122
DeriveHelpersCompat,
123123
/// Textual `let`-like scopes introduced by `macro_rules!` items.
124124
MacroRules(MacroRulesScopeRef<'ra>),
125-
/// Names declared in the given module.
125+
/// Non-glob names declared in the given module.
126126
/// The node ID is for reporting the `PROC_MACRO_DERIVE_RESOLUTION_FALLBACK`
127127
/// lint if it should be reported.
128-
Module(Module<'ra>, Option<NodeId>),
128+
ModuleNonGlobs(Module<'ra>, Option<NodeId>),
129+
/// Glob names declared in the given module.
130+
/// The node ID is for reporting the `PROC_MACRO_DERIVE_RESOLUTION_FALLBACK`
131+
/// lint if it should be reported.
132+
ModuleGlobs(Module<'ra>, Option<NodeId>),
129133
/// Names introduced by `#[macro_use]` attributes on `extern crate` items.
130134
MacroUsePrelude,
131135
/// Built-in attributes.
@@ -148,6 +152,8 @@ enum Scope<'ra> {
148152
enum ScopeSet<'ra> {
149153
/// All scopes with the given namespace.
150154
All(Namespace),
155+
/// Two scopes inside a module, for non-glob and glob bindings.
156+
Module(Namespace, Module<'ra>),
151157
/// A module, then extern prelude (used for mixed 2015-2018 mode in macros).
152158
ModuleAndExternPrelude(Namespace, Module<'ra>),
153159
/// Just two extern prelude scopes.
@@ -1898,9 +1904,12 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
18981904
let scope_set = ScopeSet::All(TypeNS);
18991905
self.cm().visit_scopes(scope_set, parent_scope, ctxt, None, |this, scope, _, _| {
19001906
match scope {
1901-
Scope::Module(module, _) => {
1907+
Scope::ModuleNonGlobs(module, _) => {
19021908
this.get_mut().traits_in_module(module, assoc_item, &mut found_traits);
19031909
}
1910+
Scope::ModuleGlobs(..) => {
1911+
// Already handled in `ModuleNonGlobs` (but see #144993).
1912+
}
19041913
Scope::StdLibPrelude => {
19051914
if let Some(module) = this.prelude {
19061915
this.get_mut().traits_in_module(module, assoc_item, &mut found_traits);

tests/ui/imports/issue-114682-1.stderr

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error[E0659]: `A` is ambiguous
44
LL | A!();
55
| ^ ambiguous name
66
|
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
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
88
note: `A` could refer to the macro defined here
99
--> $DIR/issue-114682-1.rs:7:9
1010
|
@@ -15,12 +15,13 @@ LL | | }
1515
...
1616
LL | mac!();
1717
| ------ in this macro invocation
18+
= help: use `crate::A` to refer to this macro unambiguously
1819
note: `A` could also refer to the macro imported here
1920
--> $DIR/issue-114682-1.rs:19:9
2021
|
2122
LL | pub use m::*;
2223
| ^^^^
23-
= help: consider adding an explicit import of `A` to disambiguate
24+
= help: use `crate::A` to refer to this macro unambiguously
2425
= note: this error originates in the macro `mac` (in Nightly builds, run with -Z macro-backtrace for more info)
2526

2627
error: aborting due to 1 previous error

tests/ui/imports/local-modularized-tricky-fail-1.stderr

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error[E0659]: `exported` is ambiguous
44
LL | exported!();
55
| ^^^^^^^^ ambiguous name
66
|
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
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
88
note: `exported` could refer to the macro defined here
99
--> $DIR/local-modularized-tricky-fail-1.rs:6:5
1010
|
@@ -15,12 +15,13 @@ LL | | }
1515
...
1616
LL | define_exported!();
1717
| ------------------ in this macro invocation
18+
= help: use `crate::exported` to refer to this macro unambiguously
1819
note: `exported` could also refer to the macro imported here
1920
--> $DIR/local-modularized-tricky-fail-1.rs:23:5
2021
|
2122
LL | use inner1::*;
2223
| ^^^^^^^^^
23-
= help: consider adding an explicit import of `exported` to disambiguate
24+
= help: use `crate::exported` to refer to this macro unambiguously
2425
= note: this error originates in the macro `define_exported` (in Nightly builds, run with -Z macro-backtrace for more info)
2526

2627
error[E0659]: `panic` is ambiguous

tests/ui/imports/macro-paths.stderr

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error[E0659]: `bar` is ambiguous
44
LL | bar::m! {
55
| ^^^ ambiguous name
66
|
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
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
88
note: `bar` could refer to the module defined here
99
--> $DIR/macro-paths.rs:14:9
1010
|
@@ -15,7 +15,6 @@ note: `bar` could also refer to the module imported here
1515
|
1616
LL | use foo::*;
1717
| ^^^^^^
18-
= help: consider adding an explicit import of `bar` to disambiguate
1918

2019
error[E0659]: `baz` is ambiguous
2120
--> $DIR/macro-paths.rs:23:5

tests/ui/imports/macros.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ mod m1 {
1313

1414
mod m2 {
1515
use two_macros::*;
16-
m! { //~ ERROR ambiguous
16+
m! { //~ ERROR `m` is ambiguous
1717
use crate::foo::m;
1818
}
1919
}

tests/ui/imports/macros.stderr

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,19 @@ error[E0659]: `m` is ambiguous
44
LL | m! {
55
| ^ ambiguous name
66
|
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
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
88
note: `m` could refer to the macro imported here
99
--> $DIR/macros.rs:17:13
1010
|
1111
LL | use crate::foo::m;
1212
| ^^^^^^^^^^^^^
13+
= help: use `self::m` to refer to this macro unambiguously
1314
note: `m` could also refer to the macro imported here
1415
--> $DIR/macros.rs:15:9
1516
|
1617
LL | use two_macros::*;
1718
| ^^^^^^^^^^^^^
18-
= help: consider adding an explicit import of `m` to disambiguate
19+
= help: use `self::m` to refer to this macro unambiguously
1920

2021
error[E0659]: `m` is ambiguous
2122
--> $DIR/macros.rs:29:9

0 commit comments

Comments
 (0)