From 9e4eb46790435c38a613d7f9d5d3e0eb5f77fca1 Mon Sep 17 00:00:00 2001 From: Sam Radhakrishnan Date: Tue, 1 Oct 2019 05:00:22 -0400 Subject: [PATCH] Change to use exprPrecedence instead of exprKind. --- src/librustc_typeck/check/mod.rs | 9 +++++---- src/test/ui/conversion-methods.stderr | 2 +- src/test/ui/infinite/infinite-autoderef.stderr | 2 +- src/test/ui/occurs-check-2.stderr | 2 +- src/test/ui/occurs-check.stderr | 2 +- src/test/ui/span/coerce-suggestions.stderr | 2 +- 6 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index 3c825712217e6..aa443a69c5016 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -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; @@ -4344,10 +4345,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let max_len = receiver.rfind(".").unwrap(); format!("{}{}", &receiver[..max_len], method_call) } else { - match &expr.kind { - ExprKind::Binary(_,_,_) => format!("({}){}", receiver, method_call), - ExprKind::Unary(_,_) => format!("({}){}", receiver, method_call), - _ => 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 { diff --git a/src/test/ui/conversion-methods.stderr b/src/test/ui/conversion-methods.stderr index b9662e7607494..5c666afb89a33 100644 --- a/src/test/ui/conversion-methods.stderr +++ b/src/test/ui/conversion-methods.stderr @@ -41,7 +41,7 @@ LL | let _prove_piercing_earnest: Vec = &[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` found type `&[{integer}; 3]` diff --git a/src/test/ui/infinite/infinite-autoderef.stderr b/src/test/ui/infinite/infinite-autoderef.stderr index a2ad58a7e46fc..f4567554d0dbb 100644 --- a/src/test/ui/infinite/infinite-autoderef.stderr +++ b/src/test/ui/infinite/infinite-autoderef.stderr @@ -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 diff --git a/src/test/ui/occurs-check-2.stderr b/src/test/ui/occurs-check-2.stderr index 74e29a5aea728..7f93697c6f7a7 100644 --- a/src/test/ui/occurs-check-2.stderr +++ b/src/test/ui/occurs-check-2.stderr @@ -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 diff --git a/src/test/ui/occurs-check.stderr b/src/test/ui/occurs-check.stderr index 61ce61b1cbeb6..01e2b1f774910 100644 --- a/src/test/ui/occurs-check.stderr +++ b/src/test/ui/occurs-check.stderr @@ -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 diff --git a/src/test/ui/span/coerce-suggestions.stderr b/src/test/ui/span/coerce-suggestions.stderr index 996d80a07e058..0d15a2a753ed0 100644 --- a/src/test/ui/span/coerce-suggestions.stderr +++ b/src/test/ui/span/coerce-suggestions.stderr @@ -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