about summary refs log tree commit diff
path: root/src/libsyntax
diff options
context:
space:
mode:
authorIlija Tovilo <ilija.tovilo@me.com>2019-08-11 23:37:05 +0200
committerIlija Tovilo <ilija.tovilo@me.com>2019-08-12 10:46:34 +0200
commit91af5c2daf950bd6f99e17dd2e0d23e7cd45e131 (patch)
tree13fb64542b04e830c2efb178ede757abe0891a99 /src/libsyntax
parent72f8043d44a8925e469daf5c10e2630c80c2a7d4 (diff)
downloadrust-91af5c2daf950bd6f99e17dd2e0d23e7cd45e131.tar.gz
rust-91af5c2daf950bd6f99e17dd2e0d23e7cd45e131.zip
Bring back suggestion for splitting `<-` into `< -`
Closes #62632
Diffstat (limited to 'src/libsyntax')
-rw-r--r--src/libsyntax/parse/parser/expr.rs17
-rw-r--r--src/libsyntax/util/parser.rs2
2 files changed, 19 insertions, 0 deletions
diff --git a/src/libsyntax/parse/parser/expr.rs b/src/libsyntax/parse/parser/expr.rs
index 4432c1329cb..4fdb000ed90 100644
--- a/src/libsyntax/parse/parser/expr.rs
+++ b/src/libsyntax/parse/parser/expr.rs
@@ -224,6 +224,10 @@ impl<'a> Parser<'a> {
                 self.err_dotdotdot_syntax(self.token.span);
             }
 
+            if self.token == token::LArrow {
+                self.err_larrow_operator(self.token.span);
+            }
+
             self.bump();
             if op.is_comparison() {
                 self.check_no_chained_comparison(&lhs, &op);
@@ -1702,6 +1706,19 @@ impl<'a> Parser<'a> {
             .emit();
     }
 
+    fn err_larrow_operator(&self, span: Span) {
+        self.struct_span_err(
+            span,
+            "unexpected token: `<-`"
+        ).span_suggestion(
+            span,
+            "if you meant to write a comparison against a negative value, add a \
+             space in between `<` and `-`",
+            "< -".to_string(),
+            Applicability::MaybeIncorrect
+        ).emit();
+    }
+
     fn mk_assign_op(&self, binop: BinOp, lhs: P<Expr>, rhs: P<Expr>) -> ExprKind {
         ExprKind::AssignOp(binop, lhs, rhs)
     }
diff --git a/src/libsyntax/util/parser.rs b/src/libsyntax/util/parser.rs
index d71358f45c4..a501541c959 100644
--- a/src/libsyntax/util/parser.rs
+++ b/src/libsyntax/util/parser.rs
@@ -97,6 +97,8 @@ impl AssocOp {
             // DotDotDot is no longer supported, but we need some way to display the error
             token::DotDotDot => Some(DotDotEq),
             token::Colon => Some(Colon),
+            // `<-` should probably be `< -`
+            token::LArrow => Some(Less),
             _ if t.is_keyword(kw::As) => Some(As),
             _ => None
         }