Fixes #64919. Suggest fix based on operator precendence.

This commit is contained in:
Sam Radhakrishnan 2019-09-30 17:45:31 -04:00
parent 22bc9e1d9c
commit c9baaa70be
3 changed files with 43 additions and 2 deletions

View file

@ -4344,7 +4344,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let max_len = receiver.rfind(".").unwrap();
format!("{}{}", &receiver[..max_len], method_call)
} else {
format!("{}{}", receiver, method_call)
match &expr.kind {
ExprKind::Binary(_,_,_) => format!("({}){}", receiver, method_call),
ExprKind::Unary(_,_) => format!("({}){}", receiver, method_call),
_ => format!("{}{}", receiver, method_call),
}
};
Some(if is_struct_pat_shorthand_field {
format!("{}: {}", receiver, sugg)

View file

@ -50,4 +50,13 @@ fn e() -> X<X<String, String>, String> {
x //~ ERROR mismatched types
}
fn f() -> String {
1+2 //~ ERROR mismatched types
}
fn g() -> String {
-2 //~ ERROR mismatched types
}
fn main() {}

View file

@ -66,6 +66,34 @@ LL | x
= note: expected type `X<X<_, std::string::String>, _>`
found type `X<X<_, {integer}>, _>`
error: aborting due to 6 previous errors
error[E0308]: mismatched types
--> $DIR/abridged.rs:54:5
|
LL | fn f() -> String {
| ------ expected `std::string::String` because of return type
LL | 1+2
| ^^^
| |
| expected struct `std::string::String`, found integer
| help: try using a conversion method: `(1+2).to_string()`
|
= note: expected type `std::string::String`
found type `{integer}`
error[E0308]: mismatched types
--> $DIR/abridged.rs:59:5
|
LL | fn g() -> String {
| ------ expected `std::string::String` because of return type
LL | -2
| ^^
| |
| expected struct `std::string::String`, found integer
| help: try using a conversion method: `(-2).to_string()`
|
= note: expected type `std::string::String`
found type `{integer}`
error: aborting due to 8 previous errors
For more information about this error, try `rustc --explain E0308`.