Rollup merge of #64933 - sam09:master, r=estebank

Fixes #64919. Suggest fix based on operator precendence.

Fixes https://github.com/rust-lang/rust/issues/64919
This commit is contained in:
Mazdak Farrokhzad 2019-10-01 23:56:24 +02:00 committed by GitHub
commit 67cbeee9ee
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 49 additions and 7 deletions

View file

@ -128,6 +128,7 @@ use syntax::attr;
use syntax::feature_gate::{GateIssue, emit_feature_err};
use syntax::source_map::{DUMMY_SP, original_sp};
use syntax::symbol::{kw, sym};
use syntax::util::parser::ExprPrecedence;
use std::cell::{Cell, RefCell, Ref, RefMut};
use std::collections::hash_map::Entry;
@ -4345,7 +4346,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let max_len = receiver.rfind(".").unwrap();
format!("{}{}", &receiver[..max_len], method_call)
} else {
format!("{}{}", receiver, method_call)
if expr.precedence().order() < ExprPrecedence::MethodCall.order() {
format!("({}){}", receiver, method_call)
} else {
format!("{}{}", receiver, method_call)
}
};
Some(if is_struct_pat_shorthand_field {
format!("{}: {}", receiver, sugg)

View file

@ -41,7 +41,7 @@ LL | let _prove_piercing_earnest: Vec<usize> = &[1, 2, 3];
| ^^^^^^^^^^
| |
| expected struct `std::vec::Vec`, found reference
| help: try using a conversion method: `&[1, 2, 3].to_vec()`
| help: try using a conversion method: `(&[1, 2, 3]).to_vec()`
|
= note: expected type `std::vec::Vec<usize>`
found type `&[{integer}; 3]`

View file

@ -5,7 +5,7 @@ LL | x = box x;
| ^^^^^
| |
| cyclic type of infinite size
| help: try using a conversion method: `box x.to_string()`
| help: try using a conversion method: `(box x).to_string()`
error[E0055]: reached the recursion limit while auto-dereferencing `Foo`
--> $DIR/infinite-autoderef.rs:25:5

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`.

View file

@ -5,7 +5,7 @@ LL | f = box g;
| ^^^^^
| |
| cyclic type of infinite size
| help: try using a conversion method: `box g.to_string()`
| help: try using a conversion method: `(box g).to_string()`
error: aborting due to previous error

View file

@ -5,7 +5,7 @@ LL | f = box f;
| ^^^^^
| |
| cyclic type of infinite size
| help: try using a conversion method: `box f.to_string()`
| help: try using a conversion method: `(box f).to_string()`
error: aborting due to previous error

View file

@ -44,7 +44,7 @@ LL | f = box f;
| ^^^^^
| |
| cyclic type of infinite size
| help: try using a conversion method: `box f.to_string()`
| help: try using a conversion method: `(box f).to_string()`
error[E0308]: mismatched types
--> $DIR/coerce-suggestions.rs:21:9