Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion compiler/rustc_resolve/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1205,9 +1205,12 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
}
}
}
Scope::Module(module, _) => {
Scope::ModuleNonGlobs(module, _) => {
this.add_module_candidates(module, suggestions, filter_fn, None);
}
Scope::ModuleGlobs(..) => {
// Already handled in `ModuleNonGlobs`.
}
Scope::MacroUsePrelude => {
suggestions.extend(this.macro_use_prelude.iter().filter_map(
|(name, binding)| {
Expand Down
290 changes: 161 additions & 129 deletions compiler/rustc_resolve/src/ident.rs

Large diffs are not rendered by default.

15 changes: 1 addition & 14 deletions compiler/rustc_resolve/src/imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -390,20 +390,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
(old_glob @ true, false) | (old_glob @ false, true) => {
let (glob_binding, non_glob_binding) =
if old_glob { (old_binding, binding) } else { (binding, old_binding) };
if ns == MacroNS
&& non_glob_binding.expansion != LocalExpnId::ROOT
&& glob_binding.res() != non_glob_binding.res()
{
resolution.non_glob_binding = Some(this.new_ambiguity_binding(
AmbiguityKind::GlobVsExpanded,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yaahc you may be interested, this PR removes one of the "gray areas".

non_glob_binding,
glob_binding,
false,
));
} else {
resolution.non_glob_binding = Some(non_glob_binding);
}

resolution.non_glob_binding = Some(non_glob_binding);
if let Some(old_glob_binding) = resolution.glob_binding {
assert!(old_glob_binding.is_glob_import());
if glob_binding.res() != old_glob_binding.res() {
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_resolve/src/late.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ use tracing::{debug, instrument, trace};

use crate::{
BindingError, BindingKey, Finalize, LexicalScopeBinding, Module, ModuleOrUniformRoot,
NameBinding, ParentScope, PathResult, ResolutionError, Resolver, Segment, TyCtxt, UseError,
Used, errors, path_names_to_string, rustdoc,
NameBinding, ParentScope, PathResult, ResolutionError, Resolver, Segment, Stage, TyCtxt,
UseError, Used, errors, path_names_to_string, rustdoc,
};

mod diagnostics;
Expand Down Expand Up @@ -1498,7 +1498,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
opt_ns,
&self.parent_scope,
Some(source),
finalize,
finalize.map(|finalize| Finalize { stage: Stage::Late, ..finalize }),
Some(&self.ribs),
None,
None,
Expand Down
15 changes: 12 additions & 3 deletions compiler/rustc_resolve/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,14 @@ enum Scope<'ra> {
DeriveHelpersCompat,
/// Textual `let`-like scopes introduced by `macro_rules!` items.
MacroRules(MacroRulesScopeRef<'ra>),
/// Names declared in the given module.
/// Non-glob names declared in the given module.
/// The node ID is for reporting the `PROC_MACRO_DERIVE_RESOLUTION_FALLBACK`
/// lint if it should be reported.
Module(Module<'ra>, Option<NodeId>),
ModuleNonGlobs(Module<'ra>, Option<NodeId>),
/// Glob names declared in the given module.
/// The node ID is for reporting the `PROC_MACRO_DERIVE_RESOLUTION_FALLBACK`
/// lint if it should be reported.
ModuleGlobs(Module<'ra>, Option<NodeId>),
/// Names introduced by `#[macro_use]` attributes on `extern crate` items.
MacroUsePrelude,
/// Built-in attributes.
Expand All @@ -148,6 +152,8 @@ enum Scope<'ra> {
enum ScopeSet<'ra> {
/// All scopes with the given namespace.
All(Namespace),
/// Two scopes inside a module, for non-glob and glob bindings.
Module(Namespace, Module<'ra>),
/// A module, then extern prelude (used for mixed 2015-2018 mode in macros).
ModuleAndExternPrelude(Namespace, Module<'ra>),
/// Just two extern prelude scopes.
Expand Down Expand Up @@ -1898,9 +1904,12 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
let scope_set = ScopeSet::All(TypeNS);
self.cm().visit_scopes(scope_set, parent_scope, ctxt, None, |this, scope, _, _| {
match scope {
Scope::Module(module, _) => {
Scope::ModuleNonGlobs(module, _) => {
this.get_mut().traits_in_module(module, assoc_item, &mut found_traits);
}
Scope::ModuleGlobs(..) => {
// Already handled in `ModuleNonGlobs` (but see #144993).
}
Scope::StdLibPrelude => {
if let Some(module) = this.prelude {
this.get_mut().traits_in_module(module, assoc_item, &mut found_traits);
Expand Down
5 changes: 3 additions & 2 deletions tests/ui/imports/issue-114682-1.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ error[E0659]: `A` is ambiguous
LL | A!();
| ^ 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: 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: `A` could refer to the macro defined here
--> $DIR/issue-114682-1.rs:7:9
|
Expand All @@ -15,12 +15,13 @@ LL | | }
...
LL | mac!();
| ------ in this macro invocation
= help: use `crate::A` to refer to this macro unambiguously
note: `A` could also refer to the macro imported here
--> $DIR/issue-114682-1.rs:19:9
|
LL | pub use m::*;
| ^^^^
= help: consider adding an explicit import of `A` to disambiguate
= help: use `crate::A` to refer to this macro unambiguously
= note: this error originates in the macro `mac` (in Nightly builds, run with -Z macro-backtrace for more info)

error: aborting due to 1 previous error
Expand Down
5 changes: 3 additions & 2 deletions tests/ui/imports/local-modularized-tricky-fail-1.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ error[E0659]: `exported` is ambiguous
LL | exported!();
| ^^^^^^^^ 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: 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: `exported` could refer to the macro defined here
--> $DIR/local-modularized-tricky-fail-1.rs:6:5
|
Expand All @@ -15,12 +15,13 @@ LL | | }
...
LL | define_exported!();
| ------------------ in this macro invocation
= help: use `crate::exported` to refer to this macro unambiguously
note: `exported` could also refer to the macro imported here
--> $DIR/local-modularized-tricky-fail-1.rs:23:5
|
LL | use inner1::*;
| ^^^^^^^^^
= help: consider adding an explicit import of `exported` to disambiguate
= help: use `crate::exported` to refer to this macro unambiguously
= note: this error originates in the macro `define_exported` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0659]: `panic` is ambiguous
Expand Down
3 changes: 1 addition & 2 deletions tests/ui/imports/macro-paths.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ error[E0659]: `bar` is ambiguous
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: 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:14:9
|
Expand All @@ -15,7 +15,6 @@ note: `bar` could also refer to the module imported here
|
LL | use foo::*;
| ^^^^^^
= help: consider adding an explicit import of `bar` to disambiguate

error[E0659]: `baz` is ambiguous
--> $DIR/macro-paths.rs:23:5
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/imports/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ mod m1 {

mod m2 {
use two_macros::*;
m! { //~ ERROR ambiguous
m! { //~ ERROR `m` is ambiguous
use crate::foo::m;
}
}
Expand Down
5 changes: 3 additions & 2 deletions tests/ui/imports/macros.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,19 @@ error[E0659]: `m` is ambiguous
LL | 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: 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: `m` could refer to the macro imported here
--> $DIR/macros.rs:17:13
|
LL | use crate::foo::m;
| ^^^^^^^^^^^^^
= help: use `self::m` to refer to this macro unambiguously
note: `m` could also refer to the macro imported here
--> $DIR/macros.rs:15:9
|
LL | use two_macros::*;
| ^^^^^^^^^^^^^
= help: consider adding an explicit import of `m` to disambiguate
= help: use `self::m` to refer to this macro unambiguously

error[E0659]: `m` is ambiguous
--> $DIR/macros.rs:29:9
Expand Down
Loading