Skip to content

Commit

Permalink
Rollup merge of rust-lang#70227 - LeSeulArtichaut:typo-def, r=Centril
Browse files Browse the repository at this point in the history
Only display definition when suggesting a typo

Closes rust-lang#70206
r? @Centril
  • Loading branch information
Centril authored Mar 22, 2020
2 parents 520dbfe + cb7a2c1 commit 2d25f71
Show file tree
Hide file tree
Showing 13 changed files with 69 additions and 116 deletions.
2 changes: 1 addition & 1 deletion src/librustc_resolve/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -797,7 +797,7 @@ impl<'a> Resolver<'a> {
});
if let Some(span) = def_span {
err.span_label(
span,
self.session.source_map().def_span(span),
&format!(
"similarly named {} `{}` defined here",
suggestion.res.descr(),
Expand Down
21 changes: 9 additions & 12 deletions src/test/ui/error-codes/E0423.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,17 @@ LL | for _ in (std::ops::Range { start: 0, end: 10 }) {}
error[E0423]: expected function, tuple struct or tuple variant, found struct `Foo`
--> $DIR/E0423.rs:4:13
|
LL | struct Foo { a: bool };
| ---------------------- `Foo` defined here
LL | struct Foo { a: bool };
| ---------------------- `Foo` defined here
LL |
LL | let f = Foo();
| ^^^
| |
| did you mean `Foo { /* fields */ }`?
| help: a function with a similar name exists (notice the capitalization): `foo`
LL | let f = Foo();
| ^^^
| |
| did you mean `Foo { /* fields */ }`?
| help: a function with a similar name exists (notice the capitalization): `foo`
...
LL | / fn foo() {
LL | | for _ in std::ops::Range { start: 0, end: 10 } {}
LL | |
LL | | }
| |_- similarly named function `foo` defined here
LL | fn foo() {
| -------- similarly named function `foo` defined here

error[E0423]: expected value, found struct `T`
--> $DIR/E0423.rs:14:8
Expand Down
6 changes: 3 additions & 3 deletions src/test/ui/glob-resolve1.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ error[E0412]: cannot find type `A` in this scope
--> $DIR/glob-resolve1.rs:28:11
|
LL | pub enum B { B1 }
| ----------------- similarly named enum `B` defined here
| ---------- similarly named enum `B` defined here
...
LL | foo::<A>();
| ^
Expand All @@ -65,7 +65,7 @@ error[E0412]: cannot find type `C` in this scope
--> $DIR/glob-resolve1.rs:29:11
|
LL | pub enum B { B1 }
| ----------------- similarly named enum `B` defined here
| ---------- similarly named enum `B` defined here
...
LL | foo::<C>();
| ^
Expand All @@ -83,7 +83,7 @@ error[E0412]: cannot find type `D` in this scope
--> $DIR/glob-resolve1.rs:30:11
|
LL | pub enum B { B1 }
| ----------------- similarly named enum `B` defined here
| ---------- similarly named enum `B` defined here
...
LL | foo::<D>();
| ^
Expand Down
9 changes: 4 additions & 5 deletions src/test/ui/issues/issue-31845.stderr
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
error[E0425]: cannot find function `g` in this scope
--> $DIR/issue-31845.rs:7:12
|
LL | / fn h() {
LL | | g();
| | ^ help: a function with a similar name exists: `h`
LL | | }
| |_________- similarly named function `h` defined here
LL | fn h() {
| ------ similarly named function `h` defined here
LL | g();
| ^ help: a function with a similar name exists: `h`

error: aborting due to previous error

Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/issues/issue-46332.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ error[E0422]: cannot find struct, variant or union type `TyUInt` in this scope
--> $DIR/issue-46332.rs:9:5
|
LL | struct TyUint {}
| ---------------- similarly named struct `TyUint` defined here
| ------------- similarly named struct `TyUint` defined here
...
LL | TyUInt {};
| ^^^^^^ help: a struct with a similar name exists (notice the capitalization): `TyUint`
Expand Down
10 changes: 4 additions & 6 deletions src/test/ui/macros/macro_undefined.stderr
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
error: cannot find macro `k` in this scope
--> $DIR/macro_undefined.rs:11:5
|
LL | / macro_rules! kl {
LL | | () => ()
LL | | }
| |_____- similarly named macro `kl` defined here
LL | macro_rules! kl {
| --------------- similarly named macro `kl` defined here
...
LL | k!();
| ^ help: a macro with a similar name exists: `kl`
LL | k!();
| ^ help: a macro with a similar name exists: `kl`

error: aborting due to previous error

10 changes: 4 additions & 6 deletions src/test/ui/privacy/legacy-ctor-visibility.stderr
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
error[E0423]: expected function, tuple struct or tuple variant, found struct `S`
--> $DIR/legacy-ctor-visibility.rs:9:13
|
LL | / fn f() {
LL | | S(10);
| | ^ help: a function with a similar name exists: `f`
LL | |
LL | | }
| |_________- similarly named function `f` defined here
LL | fn f() {
| ------ similarly named function `f` defined here
LL | S(10);
| ^ help: a function with a similar name exists: `f`

error: aborting due to previous error

Expand Down
20 changes: 8 additions & 12 deletions src/test/ui/proc-macro/resolve-error.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,20 @@ LL | Dlona!();
error: cannot find macro `attr_proc_macra` in this scope
--> $DIR/resolve-error.rs:58:5
|
LL | / macro_rules! attr_proc_mac {
LL | | () => {}
LL | | }
| |_- similarly named macro `attr_proc_mac` defined here
LL | macro_rules! attr_proc_mac {
| -------------------------- similarly named macro `attr_proc_mac` defined here
...
LL | attr_proc_macra!();
| ^^^^^^^^^^^^^^^ help: a macro with a similar name exists: `attr_proc_mac`
LL | attr_proc_macra!();
| ^^^^^^^^^^^^^^^ help: a macro with a similar name exists: `attr_proc_mac`

error: cannot find macro `FooWithLongNama` in this scope
--> $DIR/resolve-error.rs:55:5
|
LL | / macro_rules! FooWithLongNam {
LL | | () => {}
LL | | }
| |_- similarly named macro `FooWithLongNam` defined here
LL | macro_rules! FooWithLongNam {
| --------------------------- similarly named macro `FooWithLongNam` defined here
...
LL | FooWithLongNama!();
| ^^^^^^^^^^^^^^^ help: a macro with a similar name exists: `FooWithLongNam`
LL | FooWithLongNama!();
| ^^^^^^^^^^^^^^^ help: a macro with a similar name exists: `FooWithLongNam`

error: cannot find derive macro `attr_proc_macra` in this scope
--> $DIR/resolve-error.rs:49:10
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/resolve/issue-5035.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ error[E0404]: expected trait, found type alias `K`
--> $DIR/issue-5035.rs:3:6
|
LL | trait I {}
| ---------- similarly named trait `I` defined here
| ------- similarly named trait `I` defined here
LL | type K = dyn I;
LL | impl K for isize {}
| ^
Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/resolve/levenshtein.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ error[E0412]: cannot find type `Baz` in this scope
--> $DIR/levenshtein.rs:14:10
|
LL | enum Bar { }
| ------------ similarly named enum `Bar` defined here
| -------- similarly named enum `Bar` defined here
LL |
LL | type A = Baz; // Misspelled type name.
| ^^^ help: an enum with a similar name exists: `Bar`
Expand Down Expand Up @@ -43,7 +43,7 @@ error[E0425]: cannot find function `foobar` in this scope
--> $DIR/levenshtein.rs:30:5
|
LL | fn foo_bar() {}
| --------------- similarly named function `foo_bar` defined here
| ------------ similarly named function `foo_bar` defined here
...
LL | foobar(); // Misspelled function name.
| ^^^^^^ help: a function with a similar name exists: `foo_bar`
Expand Down
84 changes: 25 additions & 59 deletions src/test/ui/resolve/privacy-enum-ctor.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,11 @@ LL | m::Z::Unit;
error[E0423]: expected value, found enum `Z`
--> $DIR/privacy-enum-ctor.rs:25:9
|
LL | / fn f() {
LL | | n::Z;
LL | |
LL | | Z;
| | ^
... |
LL | | // This is ok, it is equivalent to not having braces
LL | | }
| |_____- similarly named function `f` defined here
LL | fn f() {
| ------ similarly named function `f` defined here
...
LL | Z;
| ^
|
help: a function with a similar name exists
|
Expand Down Expand Up @@ -53,17 +49,11 @@ LL | let _: Z = Z::Struct;
error[E0423]: expected value, found enum `m::E`
--> $DIR/privacy-enum-ctor.rs:41:16
|
LL | / fn f() {
LL | | n::Z;
LL | |
LL | | Z;
... |
LL | | // This is ok, it is equivalent to not having braces
LL | | }
| |_____- similarly named function `f` defined here
LL | fn f() {
| ------ similarly named function `f` defined here
...
LL | let _: E = m::E;
| ^^^^
LL | let _: E = m::E;
| ^^^^
|
help: a function with a similar name exists
|
Expand Down Expand Up @@ -130,17 +120,11 @@ LL | let _: E = E::Struct;
error[E0412]: cannot find type `Z` in this scope
--> $DIR/privacy-enum-ctor.rs:57:12
|
LL | / pub enum E {
LL | | Fn(u8),
LL | | Struct {
LL | | s: u8,
LL | | },
LL | | Unit,
LL | | }
| |_____- similarly named enum `E` defined here
LL | pub enum E {
| ---------- similarly named enum `E` defined here
...
LL | let _: Z = m::n::Z;
| ^
LL | let _: Z = m::n::Z;
| ^
|
help: an enum with a similar name exists
|
Expand Down Expand Up @@ -169,17 +153,11 @@ LL | let _: Z = m::Z::Unit;
error[E0412]: cannot find type `Z` in this scope
--> $DIR/privacy-enum-ctor.rs:61:12
|
LL | / pub enum E {
LL | | Fn(u8),
LL | | Struct {
LL | | s: u8,
LL | | },
LL | | Unit,
LL | | }
| |_____- similarly named enum `E` defined here
LL | pub enum E {
| ---------- similarly named enum `E` defined here
...
LL | let _: Z = m::n::Z::Fn;
| ^
LL | let _: Z = m::n::Z::Fn;
| ^
|
help: an enum with a similar name exists
|
Expand All @@ -193,17 +171,11 @@ LL | use m::n::Z;
error[E0412]: cannot find type `Z` in this scope
--> $DIR/privacy-enum-ctor.rs:64:12
|
LL | / pub enum E {
LL | | Fn(u8),
LL | | Struct {
LL | | s: u8,
LL | | },
LL | | Unit,
LL | | }
| |_____- similarly named enum `E` defined here
LL | pub enum E {
| ---------- similarly named enum `E` defined here
...
LL | let _: Z = m::n::Z::Struct;
| ^
LL | let _: Z = m::n::Z::Struct;
| ^
|
help: an enum with a similar name exists
|
Expand All @@ -228,17 +200,11 @@ LL | let _: Z = m::n::Z::Struct;
error[E0412]: cannot find type `Z` in this scope
--> $DIR/privacy-enum-ctor.rs:68:12
|
LL | / pub enum E {
LL | | Fn(u8),
LL | | Struct {
LL | | s: u8,
LL | | },
LL | | Unit,
LL | | }
| |_____- similarly named enum `E` defined here
LL | pub enum E {
| ---------- similarly named enum `E` defined here
...
LL | let _: Z = m::n::Z::Unit {};
| ^
LL | let _: Z = m::n::Z::Unit {};
| ^
|
help: an enum with a similar name exists
|
Expand Down
11 changes: 5 additions & 6 deletions src/test/ui/traits/trait-impl-for-module.stderr
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
error[E0573]: expected type, found module `a`
--> $DIR/trait-impl-for-module.rs:7:12
|
LL | / trait A {
LL | | }
| |_- similarly named trait `A` defined here
LL |
LL | impl A for a {
| ^ help: a trait with a similar name exists: `A`
LL | trait A {
| ------- similarly named trait `A` defined here
...
LL | impl A for a {
| ^ help: a trait with a similar name exists: `A`

error: aborting due to previous error

Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/ufcs/ufcs-partially-resolved.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ error[E0576]: cannot find method or associated constant `N` in trait `Tr`
--> $DIR/ufcs-partially-resolved.rs:22:17
|
LL | fn Y() {}
| --------- similarly named associated function `Y` defined here
| ------ similarly named associated function `Y` defined here
...
LL | <u8 as Tr>::N;
| ^ help: an associated function with a similar name exists: `Y`
Expand Down Expand Up @@ -181,7 +181,7 @@ error[E0575]: expected method or associated constant, found associated type `Dr:
--> $DIR/ufcs-partially-resolved.rs:53:5
|
LL | fn Z() {}
| --------- similarly named associated function `Z` defined here
| ------ similarly named associated function `Z` defined here
...
LL | <u8 as Dr>::X;
| ^^^^^^^^^^^^-
Expand Down

0 comments on commit 2d25f71

Please sign in to comment.