From ec790d6fcc426e13431cbb7510c62864515a3ef8 Mon Sep 17 00:00:00 2001 From: Huon Wilson Date: Tue, 13 Jan 2015 15:18:55 +1100 Subject: [PATCH] Tweak chained comparison errors. Lower case and give a more precise span: from operator to operator, not just the last one. --- src/libsyntax/parse/parser.rs | 7 ++++--- .../compile-fail/require-parens-for-chained-comparison.rs | 8 ++++---- src/test/compile-fail/unsized2.rs | 4 ++-- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 15254988ce0..759e5e8229a 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -2882,12 +2882,13 @@ impl<'a> Parser<'a> { debug_assert!(ast_util::is_comparison_binop(outer_op)); match lhs.node { ExprBinary(op, _, _) if ast_util::is_comparison_binop(op.node) => { - let op_span = self.span; + // respan to include both operators + let op_span = mk_sp(op.span.lo, self.span.hi); self.span_err(op_span, - "Chained comparison operators require parentheses"); + "chained comparison operators require parentheses"); if op.node == BiLt && outer_op == BiGt { self.span_help(op_span, - "use ::< instead of < if you meant to specify type arguments"); + "use `::<...>` instead of `<...>` if you meant to specify type arguments"); } } _ => {} diff --git a/src/test/compile-fail/require-parens-for-chained-comparison.rs b/src/test/compile-fail/require-parens-for-chained-comparison.rs index f5d8c574814..f2705f58331 100644 --- a/src/test/compile-fail/require-parens-for-chained-comparison.rs +++ b/src/test/compile-fail/require-parens-for-chained-comparison.rs @@ -12,12 +12,12 @@ fn f() {} fn main() { false == false == false; - //~^ ERROR: Chained comparison operators require parentheses + //~^ ERROR: chained comparison operators require parentheses false == 0 < 2; - //~^ ERROR: Chained comparison operators require parentheses + //~^ ERROR: chained comparison operators require parentheses f(); - //~^ ERROR: Chained comparison operators require parentheses - //~^^ HELP: use ::< instead of < if you meant to specify type arguments + //~^ ERROR: chained comparison operators require parentheses + //~^^ HELP: use `::<...>` instead of `<...>` } diff --git a/src/test/compile-fail/unsized2.rs b/src/test/compile-fail/unsized2.rs index a47d81e38cc..b2eb2064aeb 100644 --- a/src/test/compile-fail/unsized2.rs +++ b/src/test/compile-fail/unsized2.rs @@ -15,6 +15,6 @@ fn f() {} pub fn main() { f(); //~^ ERROR expected identifier, found keyword `type` - //~^^ ERROR: Chained comparison operators require parentheses - //~^^^ HELP: use ::< instead of < if you meant to specify type arguments + //~^^ ERROR: chained comparison + //~^^^ HELP: use `::< }