Skip to content

Commit da182a0

Browse files
authored
Rollup merge of rust-lang#57795 - estebank:did-you-mean, r=zackmdavis
Use structured suggestion in stead of notes
2 parents 8ef8d57 + 45a95b5 commit da182a0

File tree

12 files changed

+44
-41
lines changed

12 files changed

+44
-41
lines changed

src/librustc_typeck/check/method/suggest.rs

+12-2
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,12 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
304304
);
305305
if let Some(suggestion) = suggestion {
306306
// enum variant
307-
err.help(&format!("did you mean `{}`?", suggestion));
307+
err.span_suggestion_with_applicability(
308+
item_name.span,
309+
"did you mean",
310+
suggestion.to_string(),
311+
Applicability::MaybeIncorrect,
312+
);
308313
}
309314
err
310315
}
@@ -440,7 +445,12 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
440445
}
441446

442447
if let Some(lev_candidate) = lev_candidate {
443-
err.help(&format!("did you mean `{}`?", lev_candidate.ident));
448+
err.span_suggestion_with_applicability(
449+
span,
450+
"did you mean",
451+
lev_candidate.ident.to_string(),
452+
Applicability::MaybeIncorrect,
453+
);
444454
}
445455
err.emit();
446456
}

src/libsyntax/parse/parser.rs

+10-3
Original file line numberDiff line numberDiff line change
@@ -7349,9 +7349,16 @@ impl<'a> Parser<'a> {
73497349
// CONST ITEM
73507350
if self.eat_keyword(keywords::Mut) {
73517351
let prev_span = self.prev_span;
7352-
self.diagnostic().struct_span_err(prev_span, "const globals cannot be mutable")
7353-
.help("did you mean to declare a static?")
7354-
.emit();
7352+
let mut err = self.diagnostic()
7353+
.struct_span_err(prev_span, "const globals cannot be mutable");
7354+
err.span_label(prev_span, "cannot be mutable");
7355+
err.span_suggestion_with_applicability(
7356+
const_span,
7357+
"you might want to declare a static instead",
7358+
"static".to_owned(),
7359+
Applicability::MaybeIncorrect,
7360+
);
7361+
err.emit();
73557362
}
73567363
let (ident, item_, extra_attrs) = self.parse_item_const(None)?;
73577364
let prev_span = self.prev_span;

src/test/ui/auto-ref-slice-plus-ref.stderr

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@ error[E0599]: no method named `test_mut` found for type `std::vec::Vec<{integer}
22
--> $DIR/auto-ref-slice-plus-ref.rs:7:7
33
|
44
LL | a.test_mut(); //~ ERROR no method named `test_mut` found
5-
| ^^^^^^^^
5+
| ^^^^^^^^ help: did you mean: `get_mut`
66
|
77
= help: items from traits can only be used if the trait is implemented and in scope
88
= note: the following trait defines an item `test_mut`, perhaps you need to implement it:
99
candidate #1: `MyIter`
10-
= help: did you mean `get_mut`?
1110

1211
error[E0599]: no method named `test` found for type `std::vec::Vec<{integer}>` in the current scope
1312
--> $DIR/auto-ref-slice-plus-ref.rs:8:7

src/test/ui/block-result/issue-3563.stderr

+1-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@ error[E0599]: no method named `b` found for type `&Self` in the current scope
22
--> $DIR/issue-3563.rs:3:17
33
|
44
LL | || self.b()
5-
| ^
6-
|
7-
= help: did you mean `a`?
5+
| ^ help: did you mean: `a`
86

97
error: aborting due to previous error
108

src/test/ui/empty/empty-struct-braces-expr.stderr

+4-6
Original file line numberDiff line numberDiff line change
@@ -51,20 +51,18 @@ error[E0599]: no variant named `Empty3` found for type `empty_struct::XE` in the
5151
|
5252
LL | let xe3 = XE::Empty3; //~ ERROR no variant named `Empty3` found for type
5353
| ----^^^^^^
54-
| |
54+
| | |
55+
| | help: did you mean: `XEmpty3`
5556
| variant not found in `empty_struct::XE`
56-
|
57-
= help: did you mean `XEmpty3`?
5857

5958
error[E0599]: no variant named `Empty3` found for type `empty_struct::XE` in the current scope
6059
--> $DIR/empty-struct-braces-expr.rs:23:19
6160
|
6261
LL | let xe3 = XE::Empty3(); //~ ERROR no variant named `Empty3` found for type
6362
| ----^^^^^^
64-
| |
63+
| | |
64+
| | help: did you mean: `XEmpty3`
6565
| variant not found in `empty_struct::XE`
66-
|
67-
= help: did you mean `XEmpty3`?
6866

6967
error: aborting due to 8 previous errors
7068

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

+2-3
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,9 @@ LL | pub enum SomeEnum {
55
| ----------------- variant `A` not found here
66
LL | B = SomeEnum::A,
77
| ----------^
8-
| |
8+
| | |
9+
| | help: did you mean: `B`
910
| variant not found in `SomeEnum`
10-
|
11-
= help: did you mean `B`?
1211

1312
error: aborting due to previous error
1413

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

+2-4
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ LL | let x: u8 = BitXor::bitor(0 as u8, 0 as u8);
1111
| --------^^^^^
1212
| |
1313
| function or associated item not found in `dyn std::ops::BitXor<_>`
14-
|
15-
= help: did you mean `bitxor`?
14+
| help: did you mean: `bitxor`
1615

1716
error[E0191]: the value of the associated type `Output` (from the trait `std::ops::BitXor`) must be specified
1817
--> $DIR/issue-28344.rs:8:13
@@ -27,8 +26,7 @@ LL | let g = BitXor::bitor;
2726
| --------^^^^^
2827
| |
2928
| function or associated item not found in `dyn std::ops::BitXor<_>`
30-
|
31-
= help: did you mean `bitxor`?
29+
| help: did you mean: `bitxor`
3230

3331
error: aborting due to 4 previous errors
3432

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

+4-3
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@ LL | enum Foo {
55
| -------- variant `Baz` not found here
66
...
77
LL | Foo::Baz(..) => (),
8-
| -----^^^---- variant not found in `Foo`
9-
|
10-
= help: did you mean `Bar`?
8+
| -----^^^----
9+
| | |
10+
| | help: did you mean: `Bar`
11+
| variant not found in `Foo`
1112

1213
error: aborting due to previous error
1314

src/test/ui/issues/issue-50264-inner-deref-trait/result-deref-err.stderr

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@ error[E0599]: no method named `deref_err` found for type `std::result::Result<_,
22
--> $DIR/result-deref-err.rs:4:28
33
|
44
LL | let _result = &Err(41).deref_err();
5-
| ^^^^^^^^^
5+
| ^^^^^^^^^ help: did you mean: `deref_ok`
66
|
77
= note: the method `deref_err` exists but the following trait bounds were not satisfied:
88
`{integer} : std::ops::Deref`
9-
= help: did you mean `deref_ok`?
109

1110
error: aborting due to previous error
1211

src/test/ui/parser/issue-17718-const-mut.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const
22
mut //~ ERROR: const globals cannot be mutable
3-
//~^ HELP did you mean to declare a static?
3+
//~^^ HELP you might want to declare a static instead
44
FOO: usize = 3;
55

66
fn main() {
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
error: const globals cannot be mutable
22
--> $DIR/issue-17718-const-mut.rs:2:1
33
|
4+
LL | const
5+
| ----- help: you might want to declare a static instead: `static`
46
LL | mut //~ ERROR: const globals cannot be mutable
5-
| ^^^
6-
|
7-
= help: did you mean to declare a static?
7+
| ^^^ cannot be mutable
88

99
error: aborting due to previous error
1010

src/test/ui/suggestions/suggest-methods.stderr

+3-9
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,19 @@ LL | struct Foo;
55
| ----------- method `bat` not found for this
66
...
77
LL | f.bat(1.0); //~ ERROR no method named
8-
| ^^^
9-
|
10-
= help: did you mean `bar`?
8+
| ^^^ help: did you mean: `bar`
119

1210
error[E0599]: no method named `is_emtpy` found for type `std::string::String` in the current scope
1311
--> $DIR/suggest-methods.rs:21:15
1412
|
1513
LL | let _ = s.is_emtpy(); //~ ERROR no method named
16-
| ^^^^^^^^
17-
|
18-
= help: did you mean `is_empty`?
14+
| ^^^^^^^^ help: did you mean: `is_empty`
1915

2016
error[E0599]: no method named `count_eos` found for type `u32` in the current scope
2117
--> $DIR/suggest-methods.rs:25:19
2218
|
2319
LL | let _ = 63u32.count_eos(); //~ ERROR no method named
24-
| ^^^^^^^^^
25-
|
26-
= help: did you mean `count_zeros`?
20+
| ^^^^^^^^^ help: did you mean: `count_zeros`
2721

2822
error[E0599]: no method named `count_o` found for type `u32` in the current scope
2923
--> $DIR/suggest-methods.rs:28:19

0 commit comments

Comments
 (0)