Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #64919. Suggest fix based on operator precendence. #64933

Merged
merged 2 commits into from
Oct 2, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/librustc_typeck/check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
estebank marked this conversation as resolved.
Show resolved Hide resolved
};
Some(if is_struct_pat_shorthand_field {
format!("{}: {}", receiver, sugg)
Expand Down
9 changes: 9 additions & 0 deletions src/test/ui/mismatched_types/abridged.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,13 @@ fn e() -> X<X<String, String>, String> {
x //~ ERROR mismatched types
}

fn f() -> String {
1+2 //~ ERROR mismatched types
sam09 marked this conversation as resolved.
Show resolved Hide resolved
}


fn g() -> String {
-2 //~ ERROR mismatched types
}

fn main() {}
30 changes: 29 additions & 1 deletion src/test/ui/mismatched_types/abridged.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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`.