Use suggestions instead of notes ref mismatches

On type mismatch errors, use a suggestion when encountering minimal
differences in type differences due to refs, instead of a note.
This commit is contained in:
Esteban Küber 2017-11-25 06:00:26 -08:00
parent e3ed21272d
commit 36faafee8d
8 changed files with 58 additions and 36 deletions

View file

@ -17,31 +17,37 @@ error[E0308]: mismatched types
--> $DIR/deref-suggestion.rs:23:10
|
23 | foo3(u); //~ ERROR mismatched types
| ^ expected u32, found &u32
| ^
| |
| expected u32, found &u32
| help: consider dereferencing the borrow: `*u`
|
= note: expected type `u32`
found type `&u32`
= help: try with `*u`
error[E0308]: mismatched types
--> $DIR/deref-suggestion.rs:30:9
|
30 | foo(&"aaa".to_owned()); //~ ERROR mismatched types
| ^^^^^^^^^^^^^^^^^ expected struct `std::string::String`, found reference
| ^^^^^^^^^^^^^^^^^
| |
| expected struct `std::string::String`, found reference
| help: consider removing the borrow: `"aaa".to_owned()`
|
= note: expected type `std::string::String`
found type `&std::string::String`
= help: try with `"aaa".to_owned()`
error[E0308]: mismatched types
--> $DIR/deref-suggestion.rs:31:9
|
31 | foo(&mut "aaa".to_owned()); //~ ERROR mismatched types
| ^^^^^^^^^^^^^^^^^^^^^ expected struct `std::string::String`, found mutable reference
| ^^^^^^^^^^^^^^^^^^^^^
| |
| expected struct `std::string::String`, found mutable reference
| help: consider removing the borrow: `"aaa".to_owned()`
|
= note: expected type `std::string::String`
found type `&mut std::string::String`
= help: try with `"aaa".to_owned()`
error[E0308]: mismatched types
--> $DIR/deref-suggestion.rs:12:20

View file

@ -23,7 +23,7 @@ fn main() {
//~^ ERROR E0308
//~| NOTE expected &str, found struct `std::string::String`
//~| NOTE expected type `&str`
//~| HELP try with `&String::new()`
//~| HELP consider borrowing here
let y = String::new();
test(&y);
//~^ ERROR E0308

View file

@ -14,11 +14,13 @@ error[E0308]: mismatched types
--> $DIR/coerce-suggestions.rs:22:19
|
22 | let x: &str = String::new();
| ^^^^^^^^^^^^^ expected &str, found struct `std::string::String`
| ^^^^^^^^^^^^^
| |
| expected &str, found struct `std::string::String`
| help: consider borrowing here: `&String::new()`
|
= note: expected type `&str`
found type `std::string::String`
= help: try with `&String::new()`
error[E0308]: mismatched types
--> $DIR/coerce-suggestions.rs:28:10
@ -48,11 +50,13 @@ error[E0308]: mismatched types
--> $DIR/coerce-suggestions.rs:42:9
|
42 | s = format!("foo");
| ^^^^^^^^^^^^^^ expected mutable reference, found struct `std::string::String`
| ^^^^^^^^^^^^^^
| |
| expected mutable reference, found struct `std::string::String`
| help: consider mutably borrowing here: `&mut format!("foo")`
|
= note: expected type `&mut std::string::String`
found type `std::string::String`
= help: try with `&mut format!("foo")`
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
error: aborting due to 6 previous errors

View file

@ -2,31 +2,37 @@ error[E0308]: mismatched types
--> $DIR/str-lit-type-mismatch.rs:13:20
|
13 | let x: &[u8] = "foo"; //~ ERROR mismatched types
| ^^^^^ expected slice, found str
| ^^^^^
| |
| expected slice, found str
| help: consider adding a leading `b`: `b"foo"`
|
= note: expected type `&[u8]`
found type `&'static str`
= help: try `b"foo"`
error[E0308]: mismatched types
--> $DIR/str-lit-type-mismatch.rs:14:23
|
14 | let y: &[u8; 4] = "baaa"; //~ ERROR mismatched types
| ^^^^^^ expected array of 4 elements, found str
| ^^^^^^
| |
| expected array of 4 elements, found str
| help: consider adding a leading `b`: `b"baaa"`
|
= note: expected type `&[u8; 4]`
found type `&'static str`
= help: try `b"baaa"`
error[E0308]: mismatched types
--> $DIR/str-lit-type-mismatch.rs:15:19
|
15 | let z: &str = b"foo"; //~ ERROR mismatched types
| ^^^^^^ expected str, found array of 3 elements
| ^^^^^^
| |
| expected str, found array of 3 elements
| help: consider removing the leading `b`: `"foo"`
|
= note: expected type `&str`
found type `&'static [u8; 3]`
= help: try `"foo"`
error: aborting due to 3 previous errors

View file

@ -28,5 +28,5 @@ fn main() { //~ NOTE expected `()` because of default return type
//~^ ERROR mismatched types
//~| NOTE expected &str, found str
//~| NOTE expected type
//~| HELP try with `&s[..2]`
//~| HELP consider borrowing here
}

View file

@ -34,11 +34,13 @@ error[E0308]: mismatched types
--> $DIR/str-array-assignment.rs:27:17
|
27 | let w: &str = s[..2];
| ^^^^^^ expected &str, found str
| ^^^^^^
| |
| expected &str, found str
| help: consider borrowing here: `&s[..2]`
|
= note: expected type `&str`
found type `str`
= help: try with `&s[..2]`
error: aborting due to 4 previous errors