mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-02 07:22:42 +00:00
Rollup merge of #117892 - estebank:fat-arrow-typo, r=compiler-errors
Detect more `=>` typos Handle and recover `match expr { pat >= { arm } }`.
This commit is contained in:
commit
92aba63d6b
@ -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,
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
|
7
tests/ui/parser/issues/recover-ge-as-fat-arrow.fixed
Normal file
7
tests/ui/parser/issues/recover-ge-as-fat-arrow.fixed
Normal file
@ -0,0 +1,7 @@
|
||||
// run-rustfix
|
||||
fn main() {
|
||||
match 1 {
|
||||
1 => {} //~ ERROR
|
||||
_ => { let _: u16 = 2u16; } //~ ERROR
|
||||
}
|
||||
}
|
7
tests/ui/parser/issues/recover-ge-as-fat-arrow.rs
Normal file
7
tests/ui/parser/issues/recover-ge-as-fat-arrow.rs
Normal file
@ -0,0 +1,7 @@
|
||||
// run-rustfix
|
||||
fn main() {
|
||||
match 1 {
|
||||
1 >= {} //~ ERROR
|
||||
_ => { let _: u16 = 2u8; } //~ ERROR
|
||||
}
|
||||
}
|
25
tests/ui/parser/issues/recover-ge-as-fat-arrow.stderr
Normal file
25
tests/ui/parser/issues/recover-ge-as-fat-arrow.stderr
Normal file
@ -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…
Reference in New Issue
Block a user