Skip to content

Commit 2d25f71

Browse files
authored
Rollup merge of rust-lang#70227 - LeSeulArtichaut:typo-def, r=Centril
Only display definition when suggesting a typo Closes rust-lang#70206 r? @Centril
2 parents 520dbfe + cb7a2c1 commit 2d25f71

13 files changed

+69
-116
lines changed

src/librustc_resolve/diagnostics.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -797,7 +797,7 @@ impl<'a> Resolver<'a> {
797797
});
798798
if let Some(span) = def_span {
799799
err.span_label(
800-
span,
800+
self.session.source_map().def_span(span),
801801
&format!(
802802
"similarly named {} `{}` defined here",
803803
suggestion.res.descr(),

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

+9-12
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,17 @@ LL | for _ in (std::ops::Range { start: 0, end: 10 }) {}
2929
error[E0423]: expected function, tuple struct or tuple variant, found struct `Foo`
3030
--> $DIR/E0423.rs:4:13
3131
|
32-
LL | struct Foo { a: bool };
33-
| ---------------------- `Foo` defined here
32+
LL | struct Foo { a: bool };
33+
| ---------------------- `Foo` defined here
3434
LL |
35-
LL | let f = Foo();
36-
| ^^^
37-
| |
38-
| did you mean `Foo { /* fields */ }`?
39-
| help: a function with a similar name exists (notice the capitalization): `foo`
35+
LL | let f = Foo();
36+
| ^^^
37+
| |
38+
| did you mean `Foo { /* fields */ }`?
39+
| help: a function with a similar name exists (notice the capitalization): `foo`
4040
...
41-
LL | / fn foo() {
42-
LL | | for _ in std::ops::Range { start: 0, end: 10 } {}
43-
LL | |
44-
LL | | }
45-
| |_- similarly named function `foo` defined here
41+
LL | fn foo() {
42+
| -------- similarly named function `foo` defined here
4643

4744
error[E0423]: expected value, found struct `T`
4845
--> $DIR/E0423.rs:14:8

src/test/ui/glob-resolve1.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ error[E0412]: cannot find type `A` in this scope
4747
--> $DIR/glob-resolve1.rs:28:11
4848
|
4949
LL | pub enum B { B1 }
50-
| ----------------- similarly named enum `B` defined here
50+
| ---------- similarly named enum `B` defined here
5151
...
5252
LL | foo::<A>();
5353
| ^
@@ -65,7 +65,7 @@ error[E0412]: cannot find type `C` in this scope
6565
--> $DIR/glob-resolve1.rs:29:11
6666
|
6767
LL | pub enum B { B1 }
68-
| ----------------- similarly named enum `B` defined here
68+
| ---------- similarly named enum `B` defined here
6969
...
7070
LL | foo::<C>();
7171
| ^
@@ -83,7 +83,7 @@ error[E0412]: cannot find type `D` in this scope
8383
--> $DIR/glob-resolve1.rs:30:11
8484
|
8585
LL | pub enum B { B1 }
86-
| ----------------- similarly named enum `B` defined here
86+
| ---------- similarly named enum `B` defined here
8787
...
8888
LL | foo::<D>();
8989
| ^

src/test/ui/issues/issue-31845.stderr

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
error[E0425]: cannot find function `g` in this scope
22
--> $DIR/issue-31845.rs:7:12
33
|
4-
LL | / fn h() {
5-
LL | | g();
6-
| | ^ help: a function with a similar name exists: `h`
7-
LL | | }
8-
| |_________- similarly named function `h` defined here
4+
LL | fn h() {
5+
| ------ similarly named function `h` defined here
6+
LL | g();
7+
| ^ help: a function with a similar name exists: `h`
98

109
error: aborting due to previous error
1110

src/test/ui/issues/issue-46332.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0422]: cannot find struct, variant or union type `TyUInt` in this scope
22
--> $DIR/issue-46332.rs:9:5
33
|
44
LL | struct TyUint {}
5-
| ---------------- similarly named struct `TyUint` defined here
5+
| ------------- similarly named struct `TyUint` defined here
66
...
77
LL | TyUInt {};
88
| ^^^^^^ help: a struct with a similar name exists (notice the capitalization): `TyUint`
+4-6
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
error: cannot find macro `k` in this scope
22
--> $DIR/macro_undefined.rs:11:5
33
|
4-
LL | / macro_rules! kl {
5-
LL | | () => ()
6-
LL | | }
7-
| |_____- similarly named macro `kl` defined here
4+
LL | macro_rules! kl {
5+
| --------------- similarly named macro `kl` defined here
86
...
9-
LL | k!();
10-
| ^ help: a macro with a similar name exists: `kl`
7+
LL | k!();
8+
| ^ help: a macro with a similar name exists: `kl`
119

1210
error: aborting due to previous error
1311

src/test/ui/privacy/legacy-ctor-visibility.stderr

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
error[E0423]: expected function, tuple struct or tuple variant, found struct `S`
22
--> $DIR/legacy-ctor-visibility.rs:9:13
33
|
4-
LL | / fn f() {
5-
LL | | S(10);
6-
| | ^ help: a function with a similar name exists: `f`
7-
LL | |
8-
LL | | }
9-
| |_________- similarly named function `f` defined here
4+
LL | fn f() {
5+
| ------ similarly named function `f` defined here
6+
LL | S(10);
7+
| ^ help: a function with a similar name exists: `f`
108

119
error: aborting due to previous error
1210

src/test/ui/proc-macro/resolve-error.stderr

+8-12
Original file line numberDiff line numberDiff line change
@@ -18,24 +18,20 @@ LL | Dlona!();
1818
error: cannot find macro `attr_proc_macra` in this scope
1919
--> $DIR/resolve-error.rs:58:5
2020
|
21-
LL | / macro_rules! attr_proc_mac {
22-
LL | | () => {}
23-
LL | | }
24-
| |_- similarly named macro `attr_proc_mac` defined here
21+
LL | macro_rules! attr_proc_mac {
22+
| -------------------------- similarly named macro `attr_proc_mac` defined here
2523
...
26-
LL | attr_proc_macra!();
27-
| ^^^^^^^^^^^^^^^ help: a macro with a similar name exists: `attr_proc_mac`
24+
LL | attr_proc_macra!();
25+
| ^^^^^^^^^^^^^^^ help: a macro with a similar name exists: `attr_proc_mac`
2826

2927
error: cannot find macro `FooWithLongNama` in this scope
3028
--> $DIR/resolve-error.rs:55:5
3129
|
32-
LL | / macro_rules! FooWithLongNam {
33-
LL | | () => {}
34-
LL | | }
35-
| |_- similarly named macro `FooWithLongNam` defined here
30+
LL | macro_rules! FooWithLongNam {
31+
| --------------------------- similarly named macro `FooWithLongNam` defined here
3632
...
37-
LL | FooWithLongNama!();
38-
| ^^^^^^^^^^^^^^^ help: a macro with a similar name exists: `FooWithLongNam`
33+
LL | FooWithLongNama!();
34+
| ^^^^^^^^^^^^^^^ help: a macro with a similar name exists: `FooWithLongNam`
3935

4036
error: cannot find derive macro `attr_proc_macra` in this scope
4137
--> $DIR/resolve-error.rs:49:10

src/test/ui/resolve/issue-5035.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ error[E0404]: expected trait, found type alias `K`
88
--> $DIR/issue-5035.rs:3:6
99
|
1010
LL | trait I {}
11-
| ---------- similarly named trait `I` defined here
11+
| ------- similarly named trait `I` defined here
1212
LL | type K = dyn I;
1313
LL | impl K for isize {}
1414
| ^

src/test/ui/resolve/levenshtein.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ error[E0412]: cannot find type `Baz` in this scope
88
--> $DIR/levenshtein.rs:14:10
99
|
1010
LL | enum Bar { }
11-
| ------------ similarly named enum `Bar` defined here
11+
| -------- similarly named enum `Bar` defined here
1212
LL |
1313
LL | type A = Baz; // Misspelled type name.
1414
| ^^^ help: an enum with a similar name exists: `Bar`
@@ -43,7 +43,7 @@ error[E0425]: cannot find function `foobar` in this scope
4343
--> $DIR/levenshtein.rs:30:5
4444
|
4545
LL | fn foo_bar() {}
46-
| --------------- similarly named function `foo_bar` defined here
46+
| ------------ similarly named function `foo_bar` defined here
4747
...
4848
LL | foobar(); // Misspelled function name.
4949
| ^^^^^^ help: a function with a similar name exists: `foo_bar`

src/test/ui/resolve/privacy-enum-ctor.stderr

+25-59
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,11 @@ LL | m::Z::Unit;
1616
error[E0423]: expected value, found enum `Z`
1717
--> $DIR/privacy-enum-ctor.rs:25:9
1818
|
19-
LL | / fn f() {
20-
LL | | n::Z;
21-
LL | |
22-
LL | | Z;
23-
| | ^
24-
... |
25-
LL | | // This is ok, it is equivalent to not having braces
26-
LL | | }
27-
| |_____- similarly named function `f` defined here
19+
LL | fn f() {
20+
| ------ similarly named function `f` defined here
21+
...
22+
LL | Z;
23+
| ^
2824
|
2925
help: a function with a similar name exists
3026
|
@@ -53,17 +49,11 @@ LL | let _: Z = Z::Struct;
5349
error[E0423]: expected value, found enum `m::E`
5450
--> $DIR/privacy-enum-ctor.rs:41:16
5551
|
56-
LL | / fn f() {
57-
LL | | n::Z;
58-
LL | |
59-
LL | | Z;
60-
... |
61-
LL | | // This is ok, it is equivalent to not having braces
62-
LL | | }
63-
| |_____- similarly named function `f` defined here
52+
LL | fn f() {
53+
| ------ similarly named function `f` defined here
6454
...
65-
LL | let _: E = m::E;
66-
| ^^^^
55+
LL | let _: E = m::E;
56+
| ^^^^
6757
|
6858
help: a function with a similar name exists
6959
|
@@ -130,17 +120,11 @@ LL | let _: E = E::Struct;
130120
error[E0412]: cannot find type `Z` in this scope
131121
--> $DIR/privacy-enum-ctor.rs:57:12
132122
|
133-
LL | / pub enum E {
134-
LL | | Fn(u8),
135-
LL | | Struct {
136-
LL | | s: u8,
137-
LL | | },
138-
LL | | Unit,
139-
LL | | }
140-
| |_____- similarly named enum `E` defined here
123+
LL | pub enum E {
124+
| ---------- similarly named enum `E` defined here
141125
...
142-
LL | let _: Z = m::n::Z;
143-
| ^
126+
LL | let _: Z = m::n::Z;
127+
| ^
144128
|
145129
help: an enum with a similar name exists
146130
|
@@ -169,17 +153,11 @@ LL | let _: Z = m::Z::Unit;
169153
error[E0412]: cannot find type `Z` in this scope
170154
--> $DIR/privacy-enum-ctor.rs:61:12
171155
|
172-
LL | / pub enum E {
173-
LL | | Fn(u8),
174-
LL | | Struct {
175-
LL | | s: u8,
176-
LL | | },
177-
LL | | Unit,
178-
LL | | }
179-
| |_____- similarly named enum `E` defined here
156+
LL | pub enum E {
157+
| ---------- similarly named enum `E` defined here
180158
...
181-
LL | let _: Z = m::n::Z::Fn;
182-
| ^
159+
LL | let _: Z = m::n::Z::Fn;
160+
| ^
183161
|
184162
help: an enum with a similar name exists
185163
|
@@ -193,17 +171,11 @@ LL | use m::n::Z;
193171
error[E0412]: cannot find type `Z` in this scope
194172
--> $DIR/privacy-enum-ctor.rs:64:12
195173
|
196-
LL | / pub enum E {
197-
LL | | Fn(u8),
198-
LL | | Struct {
199-
LL | | s: u8,
200-
LL | | },
201-
LL | | Unit,
202-
LL | | }
203-
| |_____- similarly named enum `E` defined here
174+
LL | pub enum E {
175+
| ---------- similarly named enum `E` defined here
204176
...
205-
LL | let _: Z = m::n::Z::Struct;
206-
| ^
177+
LL | let _: Z = m::n::Z::Struct;
178+
| ^
207179
|
208180
help: an enum with a similar name exists
209181
|
@@ -228,17 +200,11 @@ LL | let _: Z = m::n::Z::Struct;
228200
error[E0412]: cannot find type `Z` in this scope
229201
--> $DIR/privacy-enum-ctor.rs:68:12
230202
|
231-
LL | / pub enum E {
232-
LL | | Fn(u8),
233-
LL | | Struct {
234-
LL | | s: u8,
235-
LL | | },
236-
LL | | Unit,
237-
LL | | }
238-
| |_____- similarly named enum `E` defined here
203+
LL | pub enum E {
204+
| ---------- similarly named enum `E` defined here
239205
...
240-
LL | let _: Z = m::n::Z::Unit {};
241-
| ^
206+
LL | let _: Z = m::n::Z::Unit {};
207+
| ^
242208
|
243209
help: an enum with a similar name exists
244210
|

src/test/ui/traits/trait-impl-for-module.stderr

+5-6
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
error[E0573]: expected type, found module `a`
22
--> $DIR/trait-impl-for-module.rs:7:12
33
|
4-
LL | / trait A {
5-
LL | | }
6-
| |_- similarly named trait `A` defined here
7-
LL |
8-
LL | impl A for a {
9-
| ^ help: a trait with a similar name exists: `A`
4+
LL | trait A {
5+
| ------- similarly named trait `A` defined here
6+
...
7+
LL | impl A for a {
8+
| ^ help: a trait with a similar name exists: `A`
109

1110
error: aborting due to previous error
1211

src/test/ui/ufcs/ufcs-partially-resolved.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ error[E0576]: cannot find method or associated constant `N` in trait `Tr`
3535
--> $DIR/ufcs-partially-resolved.rs:22:17
3636
|
3737
LL | fn Y() {}
38-
| --------- similarly named associated function `Y` defined here
38+
| ------ similarly named associated function `Y` defined here
3939
...
4040
LL | <u8 as Tr>::N;
4141
| ^ help: an associated function with a similar name exists: `Y`
@@ -181,7 +181,7 @@ error[E0575]: expected method or associated constant, found associated type `Dr:
181181
--> $DIR/ufcs-partially-resolved.rs:53:5
182182
|
183183
LL | fn Z() {}
184-
| --------- similarly named associated function `Z` defined here
184+
| ------ similarly named associated function `Z` defined here
185185
...
186186
LL | <u8 as Dr>::X;
187187
| ^^^^^^^^^^^^-

0 commit comments

Comments
 (0)