Skip to content

Commit 92aba63

Browse files
authored
Rollup merge of #117892 - estebank:fat-arrow-typo, r=compiler-errors
Detect more `=>` typos Handle and recover `match expr { pat >= { arm } }`.
2 parents a577704 + f830fe3 commit 92aba63

File tree

5 files changed

+51
-10
lines changed

5 files changed

+51
-10
lines changed

compiler/rustc_ast/src/token.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,8 @@ impl TokenKind {
388388
match *self {
389389
Comma => Some(vec![Dot, Lt, Semi]),
390390
Semi => Some(vec![Colon, Comma]),
391-
FatArrow => Some(vec![Eq, RArrow]),
391+
Colon => Some(vec![Semi]),
392+
FatArrow => Some(vec![Eq, RArrow, Ge, Gt]),
392393
_ => None,
393394
}
394395
}

compiler/rustc_parse/src/parser/expr.rs

+10-9
Original file line numberDiff line numberDiff line change
@@ -2904,15 +2904,16 @@ impl<'a> Parser<'a> {
29042904
"=>",
29052905
Applicability::MachineApplicable,
29062906
);
2907-
err.emit();
2908-
this.bump();
2909-
} else if matches!(
2910-
(&this.prev_token.kind, &this.token.kind),
2911-
(token::DotDotEq, token::Gt)
2912-
) {
2913-
// `error_inclusive_range_match_arrow` handles cases like `0..=> {}`,
2914-
// so we suppress the error here
2915-
err.delay_as_bug();
2907+
if matches!(
2908+
(&this.prev_token.kind, &this.token.kind),
2909+
(token::DotDotEq, token::Gt)
2910+
) {
2911+
// `error_inclusive_range_match_arrow` handles cases like `0..=> {}`,
2912+
// so we suppress the error here
2913+
err.delay_as_bug();
2914+
} else {
2915+
err.emit();
2916+
}
29162917
this.bump();
29172918
} else {
29182919
return Err(err);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// run-rustfix
2+
fn main() {
3+
match 1 {
4+
1 => {} //~ ERROR
5+
_ => { let _: u16 = 2u16; } //~ ERROR
6+
}
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// run-rustfix
2+
fn main() {
3+
match 1 {
4+
1 >= {} //~ ERROR
5+
_ => { let _: u16 = 2u8; } //~ ERROR
6+
}
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
error: expected one of `...`, `..=`, `..`, `=>`, `if`, or `|`, found `>=`
2+
--> $DIR/recover-ge-as-fat-arrow.rs:4:11
3+
|
4+
LL | 1 >= {}
5+
| ^^
6+
| |
7+
| expected one of `...`, `..=`, `..`, `=>`, `if`, or `|`
8+
| help: use a fat arrow to start a match arm: `=>`
9+
10+
error[E0308]: mismatched types
11+
--> $DIR/recover-ge-as-fat-arrow.rs:5:29
12+
|
13+
LL | _ => { let _: u16 = 2u8; }
14+
| --- ^^^ expected `u16`, found `u8`
15+
| |
16+
| expected due to this
17+
|
18+
help: change the type of the numeric literal from `u8` to `u16`
19+
|
20+
LL | _ => { let _: u16 = 2u16; }
21+
| ~~~
22+
23+
error: aborting due to 2 previous errors
24+
25+
For more information about this error, try `rustc --explain E0308`.

0 commit comments

Comments
 (0)