Skip to content

Commit ec790d6

Browse files
committed
Tweak chained comparison errors.
Lower case and give a more precise span: from operator to operator, not just the last one.
1 parent 2e888d0 commit ec790d6

File tree

3 files changed

+10
-9
lines changed

3 files changed

+10
-9
lines changed

src/libsyntax/parse/parser.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2882,12 +2882,13 @@ impl<'a> Parser<'a> {
28822882
debug_assert!(ast_util::is_comparison_binop(outer_op));
28832883
match lhs.node {
28842884
ExprBinary(op, _, _) if ast_util::is_comparison_binop(op.node) => {
2885-
let op_span = self.span;
2885+
// respan to include both operators
2886+
let op_span = mk_sp(op.span.lo, self.span.hi);
28862887
self.span_err(op_span,
2887-
"Chained comparison operators require parentheses");
2888+
"chained comparison operators require parentheses");
28882889
if op.node == BiLt && outer_op == BiGt {
28892890
self.span_help(op_span,
2890-
"use ::< instead of < if you meant to specify type arguments");
2891+
"use `::<...>` instead of `<...>` if you meant to specify type arguments");
28912892
}
28922893
}
28932894
_ => {}

src/test/compile-fail/require-parens-for-chained-comparison.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ fn f<T>() {}
1212

1313
fn main() {
1414
false == false == false;
15-
//~^ ERROR: Chained comparison operators require parentheses
15+
//~^ ERROR: chained comparison operators require parentheses
1616

1717
false == 0 < 2;
18-
//~^ ERROR: Chained comparison operators require parentheses
18+
//~^ ERROR: chained comparison operators require parentheses
1919

2020
f<X>();
21-
//~^ ERROR: Chained comparison operators require parentheses
22-
//~^^ HELP: use ::< instead of < if you meant to specify type arguments
21+
//~^ ERROR: chained comparison operators require parentheses
22+
//~^^ HELP: use `::<...>` instead of `<...>`
2323
}

src/test/compile-fail/unsized2.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ fn f<X>() {}
1515
pub fn main() {
1616
f<type>();
1717
//~^ ERROR expected identifier, found keyword `type`
18-
//~^^ ERROR: Chained comparison operators require parentheses
19-
//~^^^ HELP: use ::< instead of < if you meant to specify type arguments
18+
//~^^ ERROR: chained comparison
19+
//~^^^ HELP: use `::<
2020
}

0 commit comments

Comments
 (0)