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

Detect more => typos #117892

Merged
merged 1 commit into from
Nov 17, 2023
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
3 changes: 2 additions & 1 deletion compiler/rustc_ast/src/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,8 @@ impl TokenKind {
match *self {
Comma => Some(vec![Dot, Lt, Semi]),
Semi => Some(vec![Colon, Comma]),
FatArrow => Some(vec![Eq, RArrow]),
Colon => Some(vec![Semi]),
FatArrow => Some(vec![Eq, RArrow, Ge, Gt]),
_ => None,
}
}
Expand Down
19 changes: 10 additions & 9 deletions compiler/rustc_parse/src/parser/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2904,15 +2904,16 @@ impl<'a> Parser<'a> {
"=>",
Applicability::MachineApplicable,
);
err.emit();
this.bump();
} else if matches!(
(&this.prev_token.kind, &this.token.kind),
(token::DotDotEq, token::Gt)
) {
// `error_inclusive_range_match_arrow` handles cases like `0..=> {}`,
// so we suppress the error here
err.delay_as_bug();
if matches!(
(&this.prev_token.kind, &this.token.kind),
(token::DotDotEq, token::Gt)
) {
// `error_inclusive_range_match_arrow` handles cases like `0..=> {}`,
// so we suppress the error here
err.delay_as_bug();
} else {
err.emit();
}
this.bump();
} else {
return Err(err);
Expand Down
7 changes: 7 additions & 0 deletions tests/ui/parser/issues/recover-ge-as-fat-arrow.fixed
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// run-rustfix
fn main() {
match 1 {
1 => {} //~ ERROR
_ => { let _: u16 = 2u16; } //~ ERROR
}
}
7 changes: 7 additions & 0 deletions tests/ui/parser/issues/recover-ge-as-fat-arrow.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// run-rustfix
fn main() {
match 1 {
1 >= {} //~ ERROR
_ => { let _: u16 = 2u8; } //~ ERROR
}
}
25 changes: 25 additions & 0 deletions tests/ui/parser/issues/recover-ge-as-fat-arrow.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
error: expected one of `...`, `..=`, `..`, `=>`, `if`, or `|`, found `>=`
--> $DIR/recover-ge-as-fat-arrow.rs:4:11
|
LL | 1 >= {}
| ^^
| |
| expected one of `...`, `..=`, `..`, `=>`, `if`, or `|`
| help: use a fat arrow to start a match arm: `=>`

error[E0308]: mismatched types
--> $DIR/recover-ge-as-fat-arrow.rs:5:29
|
LL | _ => { let _: u16 = 2u8; }
| --- ^^^ expected `u16`, found `u8`
| |
| expected due to this
|
help: change the type of the numeric literal from `u8` to `u16`
|
LL | _ => { let _: u16 = 2u16; }
| ~~~

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0308`.
Loading