Skip to content

Commit

Permalink
Rollup merge of #64933 - sam09:master, r=estebank
Browse files Browse the repository at this point in the history
Fixes #64919. Suggest fix based on operator precendence.

Fixes #64919
  • Loading branch information
tmandry committed Oct 1, 2019
2 parents 3ab24e6 + 9e4eb46 commit d452213
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 7 deletions.
7 changes: 6 additions & 1 deletion src/librustc_typeck/check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/conversion-methods.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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]`
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/infinite/infinite-autoderef.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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
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
}


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`.
2 changes: 1 addition & 1 deletion src/test/ui/occurs-check-2.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/occurs-check.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/span/coerce-suggestions.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d452213

Please sign in to comment.