Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Edit error messages for rustc_resolve::AmbiguityKind variants #90075

Merged
merged 1 commit into from
Oct 26, 2021
Merged
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
9 changes: 2 additions & 7 deletions compiler/rustc_resolve/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1165,14 +1165,9 @@ impl<'a> Resolver<'a> {
(b1, b2, misc1, misc2, false)
};

let mut err = struct_span_err!(
self.session,
ident.span,
E0659,
"`{ident}` is ambiguous ({why})",
why = kind.descr()
);
let mut err = struct_span_err!(self.session, ident.span, E0659, "`{ident}` is ambiguous");
err.span_label(ident.span, "ambiguous name");
err.note(&format!("ambiguous because of {}", kind.descr()));

let mut could_refer_to = |b: &NameBinding<'_>, misc: AmbiguityErrorMisc, also: &str| {
let what = self.binding_description(b, ident, misc == AmbiguityErrorMisc::FromPrelude);
Expand Down
18 changes: 8 additions & 10 deletions compiler/rustc_resolve/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -728,23 +728,21 @@ enum AmbiguityKind {
impl AmbiguityKind {
fn descr(self) -> &'static str {
match self {
AmbiguityKind::Import => "name vs any other name during import resolution",
AmbiguityKind::BuiltinAttr => "built-in attribute vs any other name",
AmbiguityKind::DeriveHelper => "derive helper attribute vs any other name",
AmbiguityKind::Import => "multiple potential import sources",
AmbiguityKind::BuiltinAttr => "a name conflict with a builtin attribute",
AmbiguityKind::DeriveHelper => "a name conflict with a derive helper attribute",
AmbiguityKind::MacroRulesVsModularized => {
"`macro_rules` vs non-`macro_rules` from other module"
"a conflict between a `macro_rules` name and a non-`macro_rules` name from another module"
}
AmbiguityKind::GlobVsOuter => {
"glob import vs any other name from outer scope during import/macro resolution"
"a conflict between a name from a glob import and an outer scope during import or macro resolution"
}
AmbiguityKind::GlobVsGlob => "glob import vs glob import in the same module",
AmbiguityKind::GlobVsGlob => "multiple glob imports of a name in the same module",
AmbiguityKind::GlobVsExpanded => {
"glob import vs macro-expanded name in the same \
module during import/macro resolution"
"a conflict between a name from a glob import and a macro-expanded name in the same module during import or macro resolution"
}
AmbiguityKind::MoreExpandedVsOuter => {
"macro-expanded name vs less macro-expanded name \
from outer scope during import/macro resolution"
"a conflict between a macro-expanded name and a less macro-expanded name from outer scope during import or macro resolution"
}
}
}
Expand Down
6 changes: 4 additions & 2 deletions src/test/ui/binding/ambiguity-item.stderr
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
error[E0659]: `f` is ambiguous (glob import vs glob import in the same module)
error[E0659]: `f` is ambiguous
--> $DIR/ambiguity-item.rs:14:13
|
LL | let v = f;
| ^ ambiguous name
|
= note: ambiguous because of multiple glob imports of a name in the same module
note: `f` could refer to the function imported here
--> $DIR/ambiguity-item.rs:6:5
|
Expand All @@ -17,12 +18,13 @@ LL | use n::*; // OK, no conflict with `use m::*;`
| ^^^^
= help: consider adding an explicit import of `f` to disambiguate

error[E0659]: `f` is ambiguous (glob import vs glob import in the same module)
error[E0659]: `f` is ambiguous
--> $DIR/ambiguity-item.rs:16:9
|
LL | f => {}
| ^ ambiguous name
|
= note: ambiguous because of multiple glob imports of a name in the same module
note: `f` could refer to the function imported here
--> $DIR/ambiguity-item.rs:6:5
|
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/entry-point/imported_main_conflict.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#![feature(imported_main)]
//~^ ERROR `main` is ambiguous (glob import vs glob import in the same module)
//~^ ERROR `main` is ambiguous
mod m1 { pub(crate) fn main() {} }
mod m2 { pub(crate) fn main() {} }

Expand Down
3 changes: 2 additions & 1 deletion src/test/ui/entry-point/imported_main_conflict.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
error[E0659]: `main` is ambiguous (glob import vs glob import in the same module)
error[E0659]: `main` is ambiguous
|
= note: ambiguous because of multiple glob imports of a name in the same module
note: `main` could refer to the function imported here
--> $DIR/imported_main_conflict.rs:6:5
|
Expand Down
3 changes: 2 additions & 1 deletion src/test/ui/error-codes/E0659.stderr
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
error[E0659]: `foo` is ambiguous (glob import vs glob import in the same module)
error[E0659]: `foo` is ambiguous
--> $DIR/E0659.rs:15:15
|
LL | collider::foo();
| ^^^ ambiguous name
|
= note: ambiguous because of multiple glob imports of a name in the same module
note: `foo` could refer to the function imported here
--> $DIR/E0659.rs:10:13
|
Expand Down
9 changes: 6 additions & 3 deletions src/test/ui/imports/duplicate.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@ LL | use a::foo;
|
= note: `foo` must be defined only once in the value namespace of this module

error[E0659]: `foo` is ambiguous (glob import vs glob import in the same module)
error[E0659]: `foo` is ambiguous
--> $DIR/duplicate.rs:46:15
|
LL | use self::foo::bar;
| ^^^ ambiguous name
|
= note: ambiguous because of multiple glob imports of a name in the same module
note: `foo` could refer to the module imported here
--> $DIR/duplicate.rs:43:9
|
Expand All @@ -27,12 +28,13 @@ LL | use self::m2::*;
| ^^^^^^^^^^^
= help: consider adding an explicit import of `foo` to disambiguate

error[E0659]: `foo` is ambiguous (glob import vs glob import in the same module)
error[E0659]: `foo` is ambiguous
--> $DIR/duplicate.rs:35:8
|
LL | f::foo();
| ^^^ ambiguous name
|
= note: ambiguous because of multiple glob imports of a name in the same module
note: `foo` could refer to the function imported here
--> $DIR/duplicate.rs:24:13
|
Expand All @@ -46,12 +48,13 @@ LL | pub use b::*;
| ^^^^
= help: consider adding an explicit import of `foo` to disambiguate

error[E0659]: `foo` is ambiguous (glob import vs glob import in the same module)
error[E0659]: `foo` is ambiguous
--> $DIR/duplicate.rs:49:9
|
LL | foo::bar();
| ^^^ ambiguous name
|
= note: ambiguous because of multiple glob imports of a name in the same module
note: `foo` could refer to the module imported here
--> $DIR/duplicate.rs:43:9
|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@ LL | define_other_core!();
|
= note: this error originates in the macro `define_other_core` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0659]: `Vec` is ambiguous (macro-expanded name vs less macro-expanded name from outer scope during import/macro resolution)
error[E0659]: `Vec` is ambiguous
--> $DIR/extern-prelude-extern-crate-restricted-shadowing.rs:13:9
|
LL | Vec::panic!();
| ^^^ ambiguous name
|
= 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: `Vec` could refer to the crate imported here
--> $DIR/extern-prelude-extern-crate-restricted-shadowing.rs:5:9
|
Expand Down
9 changes: 6 additions & 3 deletions src/test/ui/imports/glob-shadowing.stderr
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
error[E0659]: `env` is ambiguous (glob import vs any other name from outer scope during import/macro resolution)
error[E0659]: `env` is ambiguous
--> $DIR/glob-shadowing.rs:11:17
|
LL | let x = env!("PATH");
| ^^^ ambiguous name
|
= note: ambiguous because of a conflict between a name from a glob import and an outer scope during import or macro resolution
= note: `env` could refer to a macro from prelude
note: `env` could also refer to the macro imported here
--> $DIR/glob-shadowing.rs:9:9
Expand All @@ -13,12 +14,13 @@ LL | use m::*;
= help: consider adding an explicit import of `env` to disambiguate
= help: or use `self::env` to refer to this macro unambiguously

error[E0659]: `env` is ambiguous (glob import vs any other name from outer scope during import/macro resolution)
error[E0659]: `env` is ambiguous
--> $DIR/glob-shadowing.rs:19:21
|
LL | let x = env!("PATH");
| ^^^ ambiguous name
|
= note: ambiguous because of a conflict between a name from a glob import and an outer scope during import or macro resolution
= note: `env` could refer to a macro from prelude
note: `env` could also refer to the macro imported here
--> $DIR/glob-shadowing.rs:17:13
Expand All @@ -27,12 +29,13 @@ LL | use m::*;
| ^^^^
= help: consider adding an explicit import of `env` to disambiguate

error[E0659]: `fenv` is ambiguous (glob import vs any other name from outer scope during import/macro resolution)
error[E0659]: `fenv` is ambiguous
--> $DIR/glob-shadowing.rs:29:21
|
LL | let x = fenv!();
| ^^^^ ambiguous name
|
= note: ambiguous because of a conflict between a name from a glob import and an outer scope during import or macro resolution
note: `fenv` could refer to the macro imported here
--> $DIR/glob-shadowing.rs:27:13
|
Expand Down
3 changes: 2 additions & 1 deletion src/test/ui/imports/issue-53269.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ error[E0432]: unresolved import `nonexistent_module`
LL | use nonexistent_module::mac;
| ^^^^^^^^^^^^^^^^^^ maybe a missing crate `nonexistent_module`?

error[E0659]: `mac` is ambiguous (`macro_rules` vs non-`macro_rules` from other module)
error[E0659]: `mac` is ambiguous
--> $DIR/issue-53269.rs:8:5
|
LL | mac!();
| ^^^ ambiguous name
|
= note: ambiguous because of a conflict between a `macro_rules` name and a non-`macro_rules` name from another module
note: `mac` could refer to the macro defined here
--> $DIR/issue-53269.rs:3:1
|
Expand Down
3 changes: 2 additions & 1 deletion src/test/ui/imports/issue-55884-1.stderr
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
error[E0659]: `S` is ambiguous (glob import vs glob import in the same module)
error[E0659]: `S` is ambiguous
--> $DIR/issue-55884-1.rs:19:12
|
LL | use m::S;
| ^ ambiguous name
|
= note: ambiguous because of multiple glob imports of a name in the same module
note: `S` could refer to the struct imported here
--> $DIR/issue-55884-1.rs:14:13
|
Expand Down
9 changes: 6 additions & 3 deletions src/test/ui/imports/issue-56125.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ error[E0432]: unresolved import `empty::issue_56125`
LL | use empty::issue_56125;
| ^^^^^^^^^^^^^^^^^^ no `issue_56125` in `m3::empty`

error[E0659]: `issue_56125` is ambiguous (name vs any other name during import resolution)
error[E0659]: `issue_56125` is ambiguous
--> $DIR/issue-56125.rs:6:9
|
LL | use issue_56125::last_segment::*;
| ^^^^^^^^^^^ ambiguous name
|
= note: ambiguous because of multiple potential import sources
= note: `issue_56125` could refer to a crate passed with `--extern`
= help: use `::issue_56125` to refer to this crate unambiguously
note: `issue_56125` could also refer to the module imported here
Expand All @@ -19,12 +20,13 @@ LL | use issue_56125::last_segment::*;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= help: use `self::issue_56125` to refer to this module unambiguously

error[E0659]: `issue_56125` is ambiguous (name vs any other name during import resolution)
error[E0659]: `issue_56125` is ambiguous
--> $DIR/issue-56125.rs:11:9
|
LL | use issue_56125::non_last_segment::non_last_segment::*;
| ^^^^^^^^^^^ ambiguous name
|
= note: ambiguous because of multiple potential import sources
= note: `issue_56125` could refer to a crate passed with `--extern`
= help: use `::issue_56125` to refer to this crate unambiguously
note: `issue_56125` could also refer to the module imported here
Expand All @@ -34,12 +36,13 @@ LL | use issue_56125::non_last_segment::non_last_segment::*;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= help: use `self::issue_56125` to refer to this module unambiguously

error[E0659]: `issue_56125` is ambiguous (name vs any other name during import resolution)
error[E0659]: `issue_56125` is ambiguous
--> $DIR/issue-56125.rs:18:9
|
LL | use issue_56125::*;
| ^^^^^^^^^^^ ambiguous name
|
= note: ambiguous because of multiple potential import sources
= note: `issue_56125` could refer to a crate passed with `--extern`
= help: use `::issue_56125` to refer to this crate unambiguously
note: `issue_56125` could also refer to the module imported here
Expand Down
3 changes: 2 additions & 1 deletion src/test/ui/imports/issue-57539.stderr
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
error[E0659]: `core` is ambiguous (name vs any other name during import resolution)
error[E0659]: `core` is ambiguous
--> $DIR/issue-57539.rs:4:9
|
LL | use core;
| ^^^^ ambiguous name
|
= note: ambiguous because of multiple potential import sources
= note: `core` could refer to a built-in crate
= help: use `::core` to refer to this crate unambiguously
note: `core` could also refer to the module imported here
Expand Down
12 changes: 8 additions & 4 deletions src/test/ui/imports/local-modularized-tricky-fail-1.stderr
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
error[E0659]: `exported` is ambiguous (glob import vs macro-expanded name in the same module during import/macro resolution)
error[E0659]: `exported` is ambiguous
--> $DIR/local-modularized-tricky-fail-1.rs:28:1
|
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: `exported` could refer to the macro defined here
--> $DIR/local-modularized-tricky-fail-1.rs:5:5
|
Expand All @@ -22,12 +23,13 @@ LL | use inner1::*;
= help: consider adding an explicit import of `exported` to disambiguate
= note: this error originates in the macro `define_exported` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0659]: `exported` is ambiguous (glob import vs macro-expanded name in the same module during import/macro resolution)
error[E0659]: `exported` is ambiguous
--> $DIR/local-modularized-tricky-fail-1.rs:28:1
|
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: `exported` could refer to the macro defined here
--> $DIR/local-modularized-tricky-fail-1.rs:5:5
|
Expand All @@ -46,12 +48,13 @@ LL | use inner1::*;
= help: consider adding an explicit import of `exported` to disambiguate
= 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 (macro-expanded name vs less macro-expanded name from outer scope during import/macro resolution)
error[E0659]: `panic` is ambiguous
--> $DIR/local-modularized-tricky-fail-1.rs:36:5
|
LL | panic!();
| ^^^^^ ambiguous name
|
= 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: `panic` could refer to a macro from prelude
note: `panic` could also refer to the macro defined here
--> $DIR/local-modularized-tricky-fail-1.rs:11:5
Expand All @@ -66,12 +69,13 @@ LL | define_panic!();
= help: use `crate::panic` to refer to this macro unambiguously
= note: this error originates in the macro `define_panic` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0659]: `include` is ambiguous (macro-expanded name vs less macro-expanded name from outer scope during import/macro resolution)
error[E0659]: `include` is ambiguous
--> $DIR/local-modularized-tricky-fail-1.rs:47:1
|
LL | include!();
| ^^^^^^^ ambiguous name
|
= 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: `include` could refer to a macro from prelude
note: `include` could also refer to the macro defined here
--> $DIR/local-modularized-tricky-fail-1.rs:17:5
Expand Down
6 changes: 4 additions & 2 deletions src/test/ui/imports/macro-paths.stderr
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
error[E0659]: `bar` is ambiguous (glob import vs macro-expanded name in the same module during import/macro resolution)
error[E0659]: `bar` is ambiguous
--> $DIR/macro-paths.rs:13:5
|
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: `bar` could refer to the module defined here
--> $DIR/macro-paths.rs:14:9
|
Expand All @@ -16,12 +17,13 @@ LL | use foo::*;
| ^^^^^^
= help: consider adding an explicit import of `bar` to disambiguate

error[E0659]: `baz` is ambiguous (macro-expanded name vs less macro-expanded name from outer scope during import/macro resolution)
error[E0659]: `baz` is ambiguous
--> $DIR/macro-paths.rs:23:5
|
LL | baz::m! {
| ^^^ ambiguous name
|
= 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: `baz` could refer to the module defined here
--> $DIR/macro-paths.rs:24:9
|
Expand Down
Loading