Skip to content

Commit c7a30c8

Browse files
committed
Auto merge of #90075 - pierwill:fix-79717, r=petrochenkov
Edit error messages for `rustc_resolve::AmbiguityKind` variants Edit the language of the ambiguity descriptions for E0659. These strings now appear as notes. Closes #79717.
2 parents 1b61b1b + 7de1ff1 commit c7a30c8

38 files changed

+160
-93
lines changed

compiler/rustc_resolve/src/diagnostics.rs

+2-7
Original file line numberDiff line numberDiff line change
@@ -1165,14 +1165,9 @@ impl<'a> Resolver<'a> {
11651165
(b1, b2, misc1, misc2, false)
11661166
};
11671167

1168-
let mut err = struct_span_err!(
1169-
self.session,
1170-
ident.span,
1171-
E0659,
1172-
"`{ident}` is ambiguous ({why})",
1173-
why = kind.descr()
1174-
);
1168+
let mut err = struct_span_err!(self.session, ident.span, E0659, "`{ident}` is ambiguous");
11751169
err.span_label(ident.span, "ambiguous name");
1170+
err.note(&format!("ambiguous because of {}", kind.descr()));
11761171

11771172
let mut could_refer_to = |b: &NameBinding<'_>, misc: AmbiguityErrorMisc, also: &str| {
11781173
let what = self.binding_description(b, ident, misc == AmbiguityErrorMisc::FromPrelude);

compiler/rustc_resolve/src/lib.rs

+8-10
Original file line numberDiff line numberDiff line change
@@ -728,23 +728,21 @@ enum AmbiguityKind {
728728
impl AmbiguityKind {
729729
fn descr(self) -> &'static str {
730730
match self {
731-
AmbiguityKind::Import => "name vs any other name during import resolution",
732-
AmbiguityKind::BuiltinAttr => "built-in attribute vs any other name",
733-
AmbiguityKind::DeriveHelper => "derive helper attribute vs any other name",
731+
AmbiguityKind::Import => "multiple potential import sources",
732+
AmbiguityKind::BuiltinAttr => "a name conflict with a builtin attribute",
733+
AmbiguityKind::DeriveHelper => "a name conflict with a derive helper attribute",
734734
AmbiguityKind::MacroRulesVsModularized => {
735-
"`macro_rules` vs non-`macro_rules` from other module"
735+
"a conflict between a `macro_rules` name and a non-`macro_rules` name from another module"
736736
}
737737
AmbiguityKind::GlobVsOuter => {
738-
"glob import vs any other name from outer scope during import/macro resolution"
738+
"a conflict between a name from a glob import and an outer scope during import or macro resolution"
739739
}
740-
AmbiguityKind::GlobVsGlob => "glob import vs glob import in the same module",
740+
AmbiguityKind::GlobVsGlob => "multiple glob imports of a name in the same module",
741741
AmbiguityKind::GlobVsExpanded => {
742-
"glob import vs macro-expanded name in the same \
743-
module during import/macro resolution"
742+
"a conflict between a name from a glob import and a macro-expanded name in the same module during import or macro resolution"
744743
}
745744
AmbiguityKind::MoreExpandedVsOuter => {
746-
"macro-expanded name vs less macro-expanded name \
747-
from outer scope during import/macro resolution"
745+
"a conflict between a macro-expanded name and a less macro-expanded name from outer scope during import or macro resolution"
748746
}
749747
}
750748
}

src/test/ui/binding/ambiguity-item.stderr

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
error[E0659]: `f` is ambiguous (glob import vs glob import in the same module)
1+
error[E0659]: `f` is ambiguous
22
--> $DIR/ambiguity-item.rs:14:13
33
|
44
LL | let v = f;
55
| ^ ambiguous name
66
|
7+
= note: ambiguous because of multiple glob imports of a name in the same module
78
note: `f` could refer to the function imported here
89
--> $DIR/ambiguity-item.rs:6:5
910
|
@@ -17,12 +18,13 @@ LL | use n::*; // OK, no conflict with `use m::*;`
1718
| ^^^^
1819
= help: consider adding an explicit import of `f` to disambiguate
1920

20-
error[E0659]: `f` is ambiguous (glob import vs glob import in the same module)
21+
error[E0659]: `f` is ambiguous
2122
--> $DIR/ambiguity-item.rs:16:9
2223
|
2324
LL | f => {}
2425
| ^ ambiguous name
2526
|
27+
= note: ambiguous because of multiple glob imports of a name in the same module
2628
note: `f` could refer to the function imported here
2729
--> $DIR/ambiguity-item.rs:6:5
2830
|

src/test/ui/entry-point/imported_main_conflict.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#![feature(imported_main)]
2-
//~^ ERROR `main` is ambiguous (glob import vs glob import in the same module)
2+
//~^ ERROR `main` is ambiguous
33
mod m1 { pub(crate) fn main() {} }
44
mod m2 { pub(crate) fn main() {} }
55

src/test/ui/entry-point/imported_main_conflict.stderr

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
error[E0659]: `main` is ambiguous (glob import vs glob import in the same module)
1+
error[E0659]: `main` is ambiguous
22
|
3+
= note: ambiguous because of multiple glob imports of a name in the same module
34
note: `main` could refer to the function imported here
45
--> $DIR/imported_main_conflict.rs:6:5
56
|

src/test/ui/error-codes/E0659.stderr

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
error[E0659]: `foo` is ambiguous (glob import vs glob import in the same module)
1+
error[E0659]: `foo` is ambiguous
22
--> $DIR/E0659.rs:15:15
33
|
44
LL | collider::foo();
55
| ^^^ ambiguous name
66
|
7+
= note: ambiguous because of multiple glob imports of a name in the same module
78
note: `foo` could refer to the function imported here
89
--> $DIR/E0659.rs:10:13
910
|

src/test/ui/imports/duplicate.stderr

+6-3
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,13 @@ LL | use a::foo;
88
|
99
= note: `foo` must be defined only once in the value namespace of this module
1010

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

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

49-
error[E0659]: `foo` is ambiguous (glob import vs glob import in the same module)
51+
error[E0659]: `foo` is ambiguous
5052
--> $DIR/duplicate.rs:49:9
5153
|
5254
LL | foo::bar();
5355
| ^^^ ambiguous name
5456
|
57+
= note: ambiguous because of multiple glob imports of a name in the same module
5558
note: `foo` could refer to the module imported here
5659
--> $DIR/duplicate.rs:43:9
5760
|

src/test/ui/imports/extern-prelude-extern-crate-restricted-shadowing.stderr

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,13 @@ LL | define_other_core!();
99
|
1010
= note: this error originates in the macro `define_other_core` (in Nightly builds, run with -Z macro-backtrace for more info)
1111

12-
error[E0659]: `Vec` is ambiguous (macro-expanded name vs less macro-expanded name from outer scope during import/macro resolution)
12+
error[E0659]: `Vec` is ambiguous
1313
--> $DIR/extern-prelude-extern-crate-restricted-shadowing.rs:13:9
1414
|
1515
LL | Vec::panic!();
1616
| ^^^ ambiguous name
1717
|
18+
= 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
1819
note: `Vec` could refer to the crate imported here
1920
--> $DIR/extern-prelude-extern-crate-restricted-shadowing.rs:5:9
2021
|

src/test/ui/imports/glob-shadowing.stderr

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
error[E0659]: `env` is ambiguous (glob import vs any other name from outer scope during import/macro resolution)
1+
error[E0659]: `env` is ambiguous
22
--> $DIR/glob-shadowing.rs:11:17
33
|
44
LL | let x = env!("PATH");
55
| ^^^ ambiguous name
66
|
7+
= note: ambiguous because of a conflict between a name from a glob import and an outer scope during import or macro resolution
78
= note: `env` could refer to a macro from prelude
89
note: `env` could also refer to the macro imported here
910
--> $DIR/glob-shadowing.rs:9:9
@@ -13,12 +14,13 @@ LL | use m::*;
1314
= help: consider adding an explicit import of `env` to disambiguate
1415
= help: or use `self::env` to refer to this macro unambiguously
1516

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

30-
error[E0659]: `fenv` is ambiguous (glob import vs any other name from outer scope during import/macro resolution)
32+
error[E0659]: `fenv` is ambiguous
3133
--> $DIR/glob-shadowing.rs:29:21
3234
|
3335
LL | let x = fenv!();
3436
| ^^^^ ambiguous name
3537
|
38+
= note: ambiguous because of a conflict between a name from a glob import and an outer scope during import or macro resolution
3639
note: `fenv` could refer to the macro imported here
3740
--> $DIR/glob-shadowing.rs:27:13
3841
|

src/test/ui/imports/issue-53269.stderr

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@ error[E0432]: unresolved import `nonexistent_module`
44
LL | use nonexistent_module::mac;
55
| ^^^^^^^^^^^^^^^^^^ maybe a missing crate `nonexistent_module`?
66

7-
error[E0659]: `mac` is ambiguous (`macro_rules` vs non-`macro_rules` from other module)
7+
error[E0659]: `mac` is ambiguous
88
--> $DIR/issue-53269.rs:8:5
99
|
1010
LL | mac!();
1111
| ^^^ ambiguous name
1212
|
13+
= note: ambiguous because of a conflict between a `macro_rules` name and a non-`macro_rules` name from another module
1314
note: `mac` could refer to the macro defined here
1415
--> $DIR/issue-53269.rs:3:1
1516
|

src/test/ui/imports/issue-55884-1.stderr

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
error[E0659]: `S` is ambiguous (glob import vs glob import in the same module)
1+
error[E0659]: `S` is ambiguous
22
--> $DIR/issue-55884-1.rs:19:12
33
|
44
LL | use m::S;
55
| ^ ambiguous name
66
|
7+
= note: ambiguous because of multiple glob imports of a name in the same module
78
note: `S` could refer to the struct imported here
89
--> $DIR/issue-55884-1.rs:14:13
910
|

src/test/ui/imports/issue-56125.stderr

+6-3
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@ error[E0432]: unresolved import `empty::issue_56125`
44
LL | use empty::issue_56125;
55
| ^^^^^^^^^^^^^^^^^^ no `issue_56125` in `m3::empty`
66

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

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

37-
error[E0659]: `issue_56125` is ambiguous (name vs any other name during import resolution)
39+
error[E0659]: `issue_56125` is ambiguous
3840
--> $DIR/issue-56125.rs:18:9
3941
|
4042
LL | use issue_56125::*;
4143
| ^^^^^^^^^^^ ambiguous name
4244
|
45+
= note: ambiguous because of multiple potential import sources
4346
= note: `issue_56125` could refer to a crate passed with `--extern`
4447
= help: use `::issue_56125` to refer to this crate unambiguously
4548
note: `issue_56125` could also refer to the module imported here

src/test/ui/imports/issue-57539.stderr

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
error[E0659]: `core` is ambiguous (name vs any other name during import resolution)
1+
error[E0659]: `core` is ambiguous
22
--> $DIR/issue-57539.rs:4:9
33
|
44
LL | use core;
55
| ^^^^ ambiguous name
66
|
7+
= note: ambiguous because of multiple potential import sources
78
= note: `core` could refer to a built-in crate
89
= help: use `::core` to refer to this crate unambiguously
910
note: `core` could also refer to the module imported here

src/test/ui/imports/local-modularized-tricky-fail-1.stderr

+8-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
error[E0659]: `exported` is ambiguous (glob import vs macro-expanded name in the same module during import/macro resolution)
1+
error[E0659]: `exported` is ambiguous
22
--> $DIR/local-modularized-tricky-fail-1.rs:28:1
33
|
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
78
note: `exported` could refer to the macro defined here
89
--> $DIR/local-modularized-tricky-fail-1.rs:5:5
910
|
@@ -22,12 +23,13 @@ LL | use inner1::*;
2223
= help: consider adding an explicit import of `exported` to disambiguate
2324
= note: this error originates in the macro `define_exported` (in Nightly builds, run with -Z macro-backtrace for more info)
2425

25-
error[E0659]: `exported` is ambiguous (glob import vs macro-expanded name in the same module during import/macro resolution)
26+
error[E0659]: `exported` is ambiguous
2627
--> $DIR/local-modularized-tricky-fail-1.rs:28:1
2728
|
2829
LL | exported!();
2930
| ^^^^^^^^ ambiguous name
3031
|
32+
= 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
3133
note: `exported` could refer to the macro defined here
3234
--> $DIR/local-modularized-tricky-fail-1.rs:5:5
3335
|
@@ -46,12 +48,13 @@ LL | use inner1::*;
4648
= help: consider adding an explicit import of `exported` to disambiguate
4749
= note: this error originates in the macro `define_exported` (in Nightly builds, run with -Z macro-backtrace for more info)
4850

49-
error[E0659]: `panic` is ambiguous (macro-expanded name vs less macro-expanded name from outer scope during import/macro resolution)
51+
error[E0659]: `panic` is ambiguous
5052
--> $DIR/local-modularized-tricky-fail-1.rs:36:5
5153
|
5254
LL | panic!();
5355
| ^^^^^ ambiguous name
5456
|
57+
= 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
5558
= note: `panic` could refer to a macro from prelude
5659
note: `panic` could also refer to the macro defined here
5760
--> $DIR/local-modularized-tricky-fail-1.rs:11:5
@@ -66,12 +69,13 @@ LL | define_panic!();
6669
= help: use `crate::panic` to refer to this macro unambiguously
6770
= note: this error originates in the macro `define_panic` (in Nightly builds, run with -Z macro-backtrace for more info)
6871

69-
error[E0659]: `include` is ambiguous (macro-expanded name vs less macro-expanded name from outer scope during import/macro resolution)
72+
error[E0659]: `include` is ambiguous
7073
--> $DIR/local-modularized-tricky-fail-1.rs:47:1
7174
|
7275
LL | include!();
7376
| ^^^^^^^ ambiguous name
7477
|
78+
= 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
7579
= note: `include` could refer to a macro from prelude
7680
note: `include` could also refer to the macro defined here
7781
--> $DIR/local-modularized-tricky-fail-1.rs:17:5

src/test/ui/imports/macro-paths.stderr

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
error[E0659]: `bar` is ambiguous (glob import vs macro-expanded name in the same module during import/macro resolution)
1+
error[E0659]: `bar` is ambiguous
22
--> $DIR/macro-paths.rs:13:5
33
|
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
78
note: `bar` could refer to the module defined here
89
--> $DIR/macro-paths.rs:14:9
910
|
@@ -16,12 +17,13 @@ LL | use foo::*;
1617
| ^^^^^^
1718
= help: consider adding an explicit import of `bar` to disambiguate
1819

19-
error[E0659]: `baz` is ambiguous (macro-expanded name vs less macro-expanded name from outer scope during import/macro resolution)
20+
error[E0659]: `baz` is ambiguous
2021
--> $DIR/macro-paths.rs:23:5
2122
|
2223
LL | baz::m! {
2324
| ^^^ ambiguous name
2425
|
26+
= 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
2527
note: `baz` could refer to the module defined here
2628
--> $DIR/macro-paths.rs:24:9
2729
|

0 commit comments

Comments
 (0)