Skip to content

Commit

Permalink
Use structured suggestion in stead of notes
Browse files Browse the repository at this point in the history
  • Loading branch information
estebank committed Jan 21, 2019
1 parent e730697 commit 45a95b5
Show file tree
Hide file tree
Showing 12 changed files with 44 additions and 41 deletions.
14 changes: 12 additions & 2 deletions src/librustc_typeck/check/method/suggest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,12 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
);
if let Some(suggestion) = suggestion {
// enum variant
err.help(&format!("did you mean `{}`?", suggestion));
err.span_suggestion_with_applicability(
item_name.span,
"did you mean",
suggestion.to_string(),
Applicability::MaybeIncorrect,
);
}
err
}
Expand Down Expand Up @@ -440,7 +445,12 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
}

if let Some(lev_candidate) = lev_candidate {
err.help(&format!("did you mean `{}`?", lev_candidate.ident));
err.span_suggestion_with_applicability(
span,
"did you mean",
lev_candidate.ident.to_string(),
Applicability::MaybeIncorrect,
);
}
err.emit();
}
Expand Down
13 changes: 10 additions & 3 deletions src/libsyntax/parse/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7271,9 +7271,16 @@ impl<'a> Parser<'a> {
// CONST ITEM
if self.eat_keyword(keywords::Mut) {
let prev_span = self.prev_span;
self.diagnostic().struct_span_err(prev_span, "const globals cannot be mutable")
.help("did you mean to declare a static?")
.emit();
let mut err = self.diagnostic()
.struct_span_err(prev_span, "const globals cannot be mutable");
err.span_label(prev_span, "cannot be mutable");
err.span_suggestion_with_applicability(
const_span,
"you might want to declare a static instead",
"static".to_owned(),
Applicability::MaybeIncorrect,
);
err.emit();
}
let (ident, item_, extra_attrs) = self.parse_item_const(None)?;
let prev_span = self.prev_span;
Expand Down
3 changes: 1 addition & 2 deletions src/test/ui/auto-ref-slice-plus-ref.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ error[E0599]: no method named `test_mut` found for type `std::vec::Vec<{integer}
--> $DIR/auto-ref-slice-plus-ref.rs:7:7
|
LL | a.test_mut(); //~ ERROR no method named `test_mut` found
| ^^^^^^^^
| ^^^^^^^^ help: did you mean: `get_mut`
|
= help: items from traits can only be used if the trait is implemented and in scope
= note: the following trait defines an item `test_mut`, perhaps you need to implement it:
candidate #1: `MyIter`
= help: did you mean `get_mut`?

error[E0599]: no method named `test` found for type `std::vec::Vec<{integer}>` in the current scope
--> $DIR/auto-ref-slice-plus-ref.rs:8:7
Expand Down
4 changes: 1 addition & 3 deletions src/test/ui/block-result/issue-3563.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ error[E0599]: no method named `b` found for type `&Self` in the current scope
--> $DIR/issue-3563.rs:3:17
|
LL | || self.b()
| ^
|
= help: did you mean `a`?
| ^ help: did you mean: `a`

error: aborting due to previous error

Expand Down
10 changes: 4 additions & 6 deletions src/test/ui/empty/empty-struct-braces-expr.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -51,20 +51,18 @@ error[E0599]: no variant named `Empty3` found for type `empty_struct::XE` in the
|
LL | let xe3 = XE::Empty3; //~ ERROR no variant named `Empty3` found for type
| ----^^^^^^
| |
| | |
| | help: did you mean: `XEmpty3`
| variant not found in `empty_struct::XE`
|
= help: did you mean `XEmpty3`?

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

error: aborting due to 8 previous errors

Expand Down
5 changes: 2 additions & 3 deletions src/test/ui/issues/issue-23217.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ LL | pub enum SomeEnum {
| ----------------- variant `A` not found here
LL | B = SomeEnum::A,
| ----------^
| |
| | |
| | help: did you mean: `B`
| variant not found in `SomeEnum`
|
= help: did you mean `B`?

error: aborting due to previous error

Expand Down
6 changes: 2 additions & 4 deletions src/test/ui/issues/issue-28344.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ LL | let x: u8 = BitXor::bitor(0 as u8, 0 as u8);
| --------^^^^^
| |
| function or associated item not found in `dyn std::ops::BitXor<_>`
|
= help: did you mean `bitxor`?
| help: did you mean: `bitxor`

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

error: aborting due to 4 previous errors

Expand Down
7 changes: 4 additions & 3 deletions src/test/ui/issues/issue-28971.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ LL | enum Foo {
| -------- variant `Baz` not found here
...
LL | Foo::Baz(..) => (),
| -----^^^---- variant not found in `Foo`
|
= help: did you mean `Bar`?
| -----^^^----
| | |
| | help: did you mean: `Bar`
| variant not found in `Foo`

error: aborting due to previous error

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

error: aborting due to previous error

Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/parser/issue-17718-const-mut.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const
mut //~ ERROR: const globals cannot be mutable
//~^ HELP did you mean to declare a static?
//~^^ HELP you might want to declare a static instead
FOO: usize = 3;

fn main() {
Expand Down
6 changes: 3 additions & 3 deletions src/test/ui/parser/issue-17718-const-mut.stderr
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
error: const globals cannot be mutable
--> $DIR/issue-17718-const-mut.rs:2:1
|
LL | const
| ----- help: you might want to declare a static instead: `static`
LL | mut //~ ERROR: const globals cannot be mutable
| ^^^
|
= help: did you mean to declare a static?
| ^^^ cannot be mutable

error: aborting due to previous error

12 changes: 3 additions & 9 deletions src/test/ui/suggestions/suggest-methods.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,19 @@ LL | struct Foo;
| ----------- method `bat` not found for this
...
LL | f.bat(1.0); //~ ERROR no method named
| ^^^
|
= help: did you mean `bar`?
| ^^^ help: did you mean: `bar`

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

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

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

0 comments on commit 45a95b5

Please sign in to comment.