@@ -128,6 +128,7 @@ use syntax::attr;
128128use syntax:: feature_gate:: { GateIssue , emit_feature_err} ;
129129use syntax:: source_map:: { DUMMY_SP , original_sp} ;
130130use syntax:: symbol:: { kw, sym} ;
131+ use syntax:: util:: parser:: ExprPrecedence ;
131132
132133use std:: cell:: { Cell , RefCell , Ref , RefMut } ;
133134use 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 {
0 commit comments