Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bring back suggestion for splitting <- into < - #63475

Merged
merged 1 commit into from
Aug 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/libsyntax/parse/parser/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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)
}
Expand Down
2 changes: 2 additions & 0 deletions src/libsyntax/util/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/obsolete-in-place/bad.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

fn foo() {
let (x, y) = (0, 0);
x <- y; //~ ERROR expected one of
x <- y; //~ ERROR unexpected token: `<-`
}

fn main() {
Expand Down
8 changes: 6 additions & 2 deletions src/test/ui/obsolete-in-place/bad.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
error: expected one of `!`, `.`, `::`, `;`, `?`, `{`, `}`, or an operator, found `<-`
error: unexpected token: `<-`
--> $DIR/bad.rs:5:7
|
LL | x <- y;
| ^^ expected one of 8 possible tokens here
| ^^
help: if you meant to write a comparison against a negative value, add a space in between `<` and `-`
|
LL | x < - y;
| ^^^

error: expected expression, found keyword `in`
--> $DIR/bad.rs:10:5
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/placement-syntax.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
fn main() {
let x = -5;
if x<-1 { //~ ERROR expected `{`, found `<-`
if x<-1 { //~ ERROR unexpected token: `<-`
println!("ok");
}
}
10 changes: 6 additions & 4 deletions src/test/ui/placement-syntax.stderr
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
error: expected `{`, found `<-`
error: unexpected token: `<-`
--> $DIR/placement-syntax.rs:3:9
|
LL | if x<-1 {
| -- ^^ expected `{`
| |
| this `if` statement has a condition, but no block
| ^^
help: if you meant to write a comparison against a negative value, add a space in between `<` and `-`
|
LL | if x< -1 {
| ^^^

error: aborting due to previous error