Skip to content

Commit 9e4eb46

Browse files
committed
Change to use exprPrecedence instead of exprKind.
1 parent c9baaa7 commit 9e4eb46

File tree

6 files changed

+10
-9
lines changed

6 files changed

+10
-9
lines changed

src/librustc_typeck/check/mod.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ use syntax::attr;
128128
use syntax::feature_gate::{GateIssue, emit_feature_err};
129129
use syntax::source_map::{DUMMY_SP, original_sp};
130130
use syntax::symbol::{kw, sym};
131+
use syntax::util::parser::ExprPrecedence;
131132

132133
use std::cell::{Cell, RefCell, Ref, RefMut};
133134
use std::collections::hash_map::Entry;
@@ -4344,10 +4345,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
43444345
let max_len = receiver.rfind(".").unwrap();
43454346
format!("{}{}", &receiver[..max_len], method_call)
43464347
} else {
4347-
match &expr.kind {
4348-
ExprKind::Binary(_,_,_) => format!("({}){}", receiver, method_call),
4349-
ExprKind::Unary(_,_) => format!("({}){}", receiver, method_call),
4350-
_ => format!("{}{}", receiver, method_call),
4348+
if expr.precedence().order() < ExprPrecedence::MethodCall.order() {
4349+
format!("({}){}", receiver, method_call)
4350+
} else {
4351+
format!("{}{}", receiver, method_call)
43514352
}
43524353
};
43534354
Some(if is_struct_pat_shorthand_field {

src/test/ui/conversion-methods.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ LL | let _prove_piercing_earnest: Vec<usize> = &[1, 2, 3];
4141
| ^^^^^^^^^^
4242
| |
4343
| expected struct `std::vec::Vec`, found reference
44-
| help: try using a conversion method: `&[1, 2, 3].to_vec()`
44+
| help: try using a conversion method: `(&[1, 2, 3]).to_vec()`
4545
|
4646
= note: expected type `std::vec::Vec<usize>`
4747
found type `&[{integer}; 3]`

src/test/ui/infinite/infinite-autoderef.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ LL | x = box x;
55
| ^^^^^
66
| |
77
| cyclic type of infinite size
8-
| help: try using a conversion method: `box x.to_string()`
8+
| help: try using a conversion method: `(box x).to_string()`
99

1010
error[E0055]: reached the recursion limit while auto-dereferencing `Foo`
1111
--> $DIR/infinite-autoderef.rs:25:5

src/test/ui/occurs-check-2.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ LL | f = box g;
55
| ^^^^^
66
| |
77
| cyclic type of infinite size
8-
| help: try using a conversion method: `box g.to_string()`
8+
| help: try using a conversion method: `(box g).to_string()`
99

1010
error: aborting due to previous error
1111

src/test/ui/occurs-check.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ LL | f = box f;
55
| ^^^^^
66
| |
77
| cyclic type of infinite size
8-
| help: try using a conversion method: `box f.to_string()`
8+
| help: try using a conversion method: `(box f).to_string()`
99

1010
error: aborting due to previous error
1111

src/test/ui/span/coerce-suggestions.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ LL | f = box f;
4444
| ^^^^^
4545
| |
4646
| cyclic type of infinite size
47-
| help: try using a conversion method: `box f.to_string()`
47+
| help: try using a conversion method: `(box f).to_string()`
4848

4949
error[E0308]: mismatched types
5050
--> $DIR/coerce-suggestions.rs:21:9

0 commit comments

Comments
 (0)