@@ -128,6 +128,7 @@ use syntax::attr;
128
128
use syntax:: feature_gate:: { GateIssue , emit_feature_err} ;
129
129
use syntax:: source_map:: { DUMMY_SP , original_sp} ;
130
130
use syntax:: symbol:: { kw, sym} ;
131
+ use syntax:: util:: parser:: ExprPrecedence ;
131
132
132
133
use std:: cell:: { Cell , RefCell , Ref , RefMut } ;
133
134
use std:: collections:: hash_map:: Entry ;
@@ -4344,10 +4345,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
4344
4345
let max_len = receiver. rfind ( "." ) . unwrap ( ) ;
4345
4346
format ! ( "{}{}" , & receiver[ ..max_len] , method_call)
4346
4347
} 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)
4351
4352
}
4352
4353
} ;
4353
4354
Some ( if is_struct_pat_shorthand_field {
0 commit comments