Skip to content

Commit d7868c4

Browse files
committed
Make confusable suggestions verbose
1 parent 75f7b55 commit d7868c4

14 files changed

+126
-43
lines changed

compiler/rustc_hir_typeck/src/method/suggest.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1280,7 +1280,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
12801280
{
12811281
// We found a method with the same number of arguments as the method
12821282
// call expression the user wrote.
1283-
err.span_suggestion(
1283+
err.span_suggestion_verbose(
12841284
span,
12851285
format!("there is {an} method with a similar name"),
12861286
similar_candidate.name,
@@ -1307,7 +1307,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
13071307
{
13081308
// We have fn call expression and the argument count match the associated
13091309
// function we found.
1310-
err.span_suggestion(
1310+
err.span_suggestion_verbose(
13111311
span,
13121312
format!(
13131313
"there is {an} {} with a similar name",
@@ -1328,7 +1328,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
13281328
}
13291329
} else if let Mode::Path = mode {
13301330
// We have an associated item syntax and we found something that isn't an fn.
1331-
err.span_suggestion(
1331+
err.span_suggestion_verbose(
13321332
span,
13331333
format!(
13341334
"there is {an} {} with a similar name",

tests/ui/associated-item/associated-item-enum.stderr

+18-12
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@ LL | enum Enum { Variant }
55
| --------- variant or associated item `mispellable` not found for this enum
66
...
77
LL | Enum::mispellable();
8-
| ^^^^^^^^^^^
9-
| |
10-
| variant or associated item not found in `Enum`
11-
| help: there is an associated function with a similar name: `misspellable`
8+
| ^^^^^^^^^^^ variant or associated item not found in `Enum`
9+
|
10+
help: there is an associated function with a similar name
11+
|
12+
LL | Enum::misspellable();
13+
| ~~~~~~~~~~~~
1214

1315
error[E0599]: no variant or associated item named `mispellable_trait` found for enum `Enum` in the current scope
1416
--> $DIR/associated-item-enum.rs:18:11
@@ -17,10 +19,12 @@ LL | enum Enum { Variant }
1719
| --------- variant or associated item `mispellable_trait` not found for this enum
1820
...
1921
LL | Enum::mispellable_trait();
20-
| ^^^^^^^^^^^^^^^^^
21-
| |
22-
| variant or associated item not found in `Enum`
23-
| help: there is an associated function with a similar name: `misspellable_trait`
22+
| ^^^^^^^^^^^^^^^^^ variant or associated item not found in `Enum`
23+
|
24+
help: there is an associated function with a similar name
25+
|
26+
LL | Enum::misspellable_trait();
27+
| ~~~~~~~~~~~~~~~~~~
2428

2529
error[E0599]: no variant or associated item named `MISPELLABLE` found for enum `Enum` in the current scope
2630
--> $DIR/associated-item-enum.rs:19:11
@@ -29,10 +33,12 @@ LL | enum Enum { Variant }
2933
| --------- variant or associated item `MISPELLABLE` not found for this enum
3034
...
3135
LL | Enum::MISPELLABLE;
32-
| ^^^^^^^^^^^
33-
| |
34-
| variant or associated item not found in `Enum`
35-
| help: there is an associated constant with a similar name: `MISSPELLABLE`
36+
| ^^^^^^^^^^^ variant or associated item not found in `Enum`
37+
|
38+
help: there is an associated constant with a similar name
39+
|
40+
LL | Enum::MISSPELLABLE;
41+
| ~~~~~~~~~~~~
3642

3743
error: aborting due to 3 previous errors
3844

tests/ui/attributes/rustc_confusables.stderr

+6-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,12 @@ error[E0599]: no method named `inser` found for struct `rustc_confusables_across
3131
--> $DIR/rustc_confusables.rs:12:7
3232
|
3333
LL | x.inser();
34-
| ^^^^^ help: there is a method with a similar name: `insert`
34+
| ^^^^^
35+
|
36+
help: there is a method with a similar name
37+
|
38+
LL | x.insert();
39+
| ~~~~~~
3540

3641
error[E0599]: no method named `foo` found for struct `rustc_confusables_across_crate::BTreeSet` in the current scope
3742
--> $DIR/rustc_confusables.rs:15:7

tests/ui/block-result/issue-3563.stderr

+6-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@ error[E0599]: no method named `b` found for reference `&Self` in the current sco
22
--> $DIR/issue-3563.rs:3:17
33
|
44
LL | || self.b()
5-
| ^ help: there is a method with a similar name: `a`
5+
| ^
6+
|
7+
help: there is a method with a similar name
8+
|
9+
LL | || self.a()
10+
| ~
611

712
error: aborting due to 1 previous error
813

tests/ui/methods/issues/issue-105732.stderr

+6-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,12 @@ error[E0599]: no method named `g` found for reference `&Self` in the current sco
1010
--> $DIR/issue-105732.rs:10:14
1111
|
1212
LL | self.g();
13-
| ^ help: there is a method with a similar name: `f`
13+
| ^
14+
|
15+
help: there is a method with a similar name
16+
|
17+
LL | self.f();
18+
| ~
1419

1520
error: aborting due to 2 previous errors
1621

tests/ui/methods/method-not-found-but-doc-alias.stderr

+6-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,12 @@ LL | struct Foo;
55
| ---------- method `quux` not found for this struct
66
...
77
LL | Foo.quux();
8-
| ^^^^ help: there is a method with a similar name: `bar`
8+
| ^^^^
9+
|
10+
help: there is a method with a similar name
11+
|
12+
LL | Foo.bar();
13+
| ~~~
914

1015
error: aborting due to 1 previous error
1116

tests/ui/object-pointer-types.stderr

+6-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,12 @@ LL | fn owned(self: Box<Self>);
55
| --------- the method might not be found because of this arbitrary self type
66
...
77
LL | x.owned();
8-
| ^^^^^ help: there is a method with a similar name: `to_owned`
8+
| ^^^^^
9+
|
10+
help: there is a method with a similar name
11+
|
12+
LL | x.to_owned();
13+
| ~~~~~~~~
914

1015
error[E0599]: no method named `owned` found for mutable reference `&mut dyn Foo` in the current scope
1116
--> $DIR/object-pointer-types.rs:17:7

tests/ui/parser/emoji-identifiers.stderr

+5-4
Original file line numberDiff line numberDiff line change
@@ -71,16 +71,17 @@ LL | struct 👀;
7171
| --------- function or associated item `full_of✨` not found for this struct
7272
...
7373
LL | 👀::full_of✨()
74-
| ^^^^^^^^^
75-
| |
76-
| function or associated item not found in `👀`
77-
| help: there is an associated function with a similar name: `full_of_✨`
74+
| ^^^^^^^^^ function or associated item not found in `👀`
7875
|
7976
note: if you're trying to build a new `👀`, consider using `👀::full_of_✨` which returns `👀`
8077
--> $DIR/emoji-identifiers.rs:4:5
8178
|
8279
LL | fn full_of_✨() -> 👀 {
8380
| ^^^^^^^^^^^^^^^^^^^^^
81+
help: there is an associated function with a similar name
82+
|
83+
LL | 👀::full_of_✨()
84+
| ~~~~~~~~~~
8485

8586
error[E0425]: cannot find function `i_like_to_😄_a_lot` in this scope
8687
--> $DIR/emoji-identifiers.rs:13:13

tests/ui/resolve/typo-suggestion-mistyped-in-path.stderr

+6-4
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,12 @@ LL | struct Struct;
1414
| ------------- function or associated item `fob` not found for this struct
1515
...
1616
LL | Struct::fob();
17-
| ^^^
18-
| |
19-
| function or associated item not found in `Struct`
20-
| help: there is an associated function with a similar name: `foo`
17+
| ^^^ function or associated item not found in `Struct`
18+
|
19+
help: there is an associated function with a similar name
20+
|
21+
LL | Struct::foo();
22+
| ~~~
2123

2224
error[E0433]: failed to resolve: use of undeclared type `Struc`
2325
--> $DIR/typo-suggestion-mistyped-in-path.rs:27:5

tests/ui/rust-2018/trait-import-suggestions.stderr

+6-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,12 @@ error[E0599]: no method named `baz` found for type `u32` in the current scope
4040
--> $DIR/trait-import-suggestions.rs:29:7
4141
|
4242
LL | x.baz();
43-
| ^^^ help: there is a method with a similar name: `bar`
43+
| ^^^
44+
|
45+
help: there is a method with a similar name
46+
|
47+
LL | x.bar();
48+
| ~~~
4449

4550
error[E0599]: no function or associated item named `from_str` found for type `u32` in the current scope
4651
--> $DIR/trait-import-suggestions.rs:30:18

tests/ui/self/arbitrary_self_type_mut_difference.stderr

+10-2
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,33 @@ error[E0599]: no method named `x` found for struct `Pin<&S>` in the current scop
22
--> $DIR/arbitrary_self_type_mut_difference.rs:11:18
33
|
44
LL | Pin::new(&S).x();
5-
| ^ help: there is a method with a similar name: `y`
5+
| ^
66
|
77
note: method is available for `Pin<&mut S>`
88
--> $DIR/arbitrary_self_type_mut_difference.rs:6:5
99
|
1010
LL | fn x(self: Pin<&mut Self>) {}
1111
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
12+
help: there is a method with a similar name
13+
|
14+
LL | Pin::new(&S).y();
15+
| ~
1216

1317
error[E0599]: no method named `y` found for struct `Pin<&mut S>` in the current scope
1418
--> $DIR/arbitrary_self_type_mut_difference.rs:12:22
1519
|
1620
LL | Pin::new(&mut S).y();
17-
| ^ help: there is a method with a similar name: `x`
21+
| ^
1822
|
1923
note: method is available for `Pin<&S>`
2024
--> $DIR/arbitrary_self_type_mut_difference.rs:7:5
2125
|
2226
LL | fn y(self: Pin<&Self>) {}
2327
| ^^^^^^^^^^^^^^^^^^^^^^
28+
help: there is a method with a similar name
29+
|
30+
LL | Pin::new(&mut S).x();
31+
| ~
2432

2533
error: aborting due to 2 previous errors
2634

tests/ui/suggestions/issue-109291.stderr

+5-4
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,18 @@ error[E0599]: no function or associated item named `forced_capture` found for st
22
--> $DIR/issue-109291.rs:2:65
33
|
44
LL | println!("Custom backtrace: {}", std::backtrace::Backtrace::forced_capture());
5-
| ^^^^^^^^^^^^^^
6-
| |
7-
| function or associated item not found in `Backtrace`
8-
| help: there is an associated function with a similar name: `force_capture`
5+
| ^^^^^^^^^^^^^^ function or associated item not found in `Backtrace`
96
|
107
note: if you're trying to build a new `Backtrace` consider using one of the following associated functions:
118
Backtrace::capture
129
Backtrace::force_capture
1310
Backtrace::disabled
1411
Backtrace::create
1512
--> $SRC_DIR/std/src/backtrace.rs:LL:COL
13+
help: there is an associated function with a similar name
14+
|
15+
LL | println!("Custom backtrace: {}", std::backtrace::Backtrace::force_capture());
16+
| ~~~~~~~~~~~~~
1617

1718
error: aborting due to 1 previous error
1819

tests/ui/suggestions/suggest-methods.stderr

+18-3
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,34 @@ error[E0599]: no method named `is_emtpy` found for struct `String` in the curren
1717
--> $DIR/suggest-methods.rs:22:15
1818
|
1919
LL | let _ = s.is_emtpy();
20-
| ^^^^^^^^ help: there is a method with a similar name: `is_empty`
20+
| ^^^^^^^^
21+
|
22+
help: there is a method with a similar name
23+
|
24+
LL | let _ = s.is_empty();
25+
| ~~~~~~~~
2126

2227
error[E0599]: no method named `count_eos` found for type `u32` in the current scope
2328
--> $DIR/suggest-methods.rs:27:19
2429
|
2530
LL | let _ = 63u32.count_eos();
26-
| ^^^^^^^^^ help: there is a method with a similar name: `count_zeros`
31+
| ^^^^^^^^^
32+
|
33+
help: there is a method with a similar name
34+
|
35+
LL | let _ = 63u32.count_zeros();
36+
| ~~~~~~~~~~~
2737

2838
error[E0599]: no method named `count_o` found for type `u32` in the current scope
2939
--> $DIR/suggest-methods.rs:30:19
3040
|
3141
LL | let _ = 63u32.count_o();
32-
| ^^^^^^^ help: there is a method with a similar name: `count_ones`
42+
| ^^^^^^^
43+
|
44+
help: there is a method with a similar name
45+
|
46+
LL | let _ = 63u32.count_ones();
47+
| ~~~~~~~~~~
3348

3449
error: aborting due to 4 previous errors
3550

tests/ui/traits/trait-upcasting/subtrait-method.stderr

+25-5
Original file line numberDiff line numberDiff line change
@@ -2,66 +2,86 @@ error[E0599]: no method named `c` found for reference `&dyn Bar` in the current
22
--> $DIR/subtrait-method.rs:55:9
33
|
44
LL | bar.c();
5-
| ^ help: there is a method with a similar name: `a`
5+
| ^
66
|
77
= help: items from traits can only be used if the trait is implemented and in scope
88
note: `Baz` defines an item `c`, perhaps you need to implement it
99
--> $DIR/subtrait-method.rs:27:1
1010
|
1111
LL | trait Baz: Bar {
1212
| ^^^^^^^^^^^^^^
13+
help: there is a method with a similar name
14+
|
15+
LL | bar.a();
16+
| ~
1317

1418
error[E0599]: no method named `b` found for reference `&dyn Foo` in the current scope
1519
--> $DIR/subtrait-method.rs:59:9
1620
|
1721
LL | foo.b();
18-
| ^ help: there is a method with a similar name: `a`
22+
| ^
1923
|
2024
= help: items from traits can only be used if the trait is implemented and in scope
2125
note: `Bar` defines an item `b`, perhaps you need to implement it
2226
--> $DIR/subtrait-method.rs:17:1
2327
|
2428
LL | trait Bar: Foo {
2529
| ^^^^^^^^^^^^^^
30+
help: there is a method with a similar name
31+
|
32+
LL | foo.a();
33+
| ~
2634

2735
error[E0599]: no method named `c` found for reference `&dyn Foo` in the current scope
2836
--> $DIR/subtrait-method.rs:61:9
2937
|
3038
LL | foo.c();
31-
| ^ help: there is a method with a similar name: `a`
39+
| ^
3240
|
3341
= help: items from traits can only be used if the trait is implemented and in scope
3442
note: `Baz` defines an item `c`, perhaps you need to implement it
3543
--> $DIR/subtrait-method.rs:27:1
3644
|
3745
LL | trait Baz: Bar {
3846
| ^^^^^^^^^^^^^^
47+
help: there is a method with a similar name
48+
|
49+
LL | foo.a();
50+
| ~
3951

4052
error[E0599]: no method named `b` found for reference `&dyn Foo` in the current scope
4153
--> $DIR/subtrait-method.rs:65:9
4254
|
4355
LL | foo.b();
44-
| ^ help: there is a method with a similar name: `a`
56+
| ^
4557
|
4658
= help: items from traits can only be used if the trait is implemented and in scope
4759
note: `Bar` defines an item `b`, perhaps you need to implement it
4860
--> $DIR/subtrait-method.rs:17:1
4961
|
5062
LL | trait Bar: Foo {
5163
| ^^^^^^^^^^^^^^
64+
help: there is a method with a similar name
65+
|
66+
LL | foo.a();
67+
| ~
5268

5369
error[E0599]: no method named `c` found for reference `&dyn Foo` in the current scope
5470
--> $DIR/subtrait-method.rs:67:9
5571
|
5672
LL | foo.c();
57-
| ^ help: there is a method with a similar name: `a`
73+
| ^
5874
|
5975
= help: items from traits can only be used if the trait is implemented and in scope
6076
note: `Baz` defines an item `c`, perhaps you need to implement it
6177
--> $DIR/subtrait-method.rs:27:1
6278
|
6379
LL | trait Baz: Bar {
6480
| ^^^^^^^^^^^^^^
81+
help: there is a method with a similar name
82+
|
83+
LL | foo.a();
84+
| ~
6585

6686
error: aborting due to 5 previous errors
6787

0 commit comments

Comments
 (0)