Skip to content

Commit

Permalink
Emit fewer errors on patterns with possible type ascription
Browse files Browse the repository at this point in the history
  • Loading branch information
estebank committed Jan 17, 2023
1 parent 2d82420 commit c847a01
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 29 deletions.
2 changes: 2 additions & 0 deletions compiler/rustc_parse/src/parser/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2500,6 +2500,8 @@ impl<'a> Parser<'a> {
Ok(ty) => {
err.span_label(ty.span, "specifying the type of a pattern isn't supported");
self.restore_snapshot(snapshot_type);
let new_span = first_pat.span.to(ty.span);
first_pat = self.mk_pat(new_span, PatKind::Wild);
}
}
err.emit();
Expand Down
2 changes: 0 additions & 2 deletions tests/ui/parser/anon-enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ fn foo(x: bool | i32) -> i32 | f64 {
//~| ERROR anonymous enums are not supported
match x {
x: i32 => x, //~ ERROR expected
//~^ ERROR failed to resolve
true => 42.,
false => 0.333,
}
Expand All @@ -14,6 +13,5 @@ fn main() {
42: i32 => (), //~ ERROR expected
_: f64 => (), //~ ERROR expected
x: i32 => (), //~ ERROR expected
//~^ ERROR failed to resolve
}
}
21 changes: 4 additions & 17 deletions tests/ui/parser/anon-enums.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -36,23 +36,23 @@ LL | x::i32 => x,
| ~~

error: expected one of `...`, `..=`, `..`, or `|`, found `:`
--> $DIR/anon-enums.rs:14:11
--> $DIR/anon-enums.rs:13:11
|
LL | 42: i32 => (),
| ^ --- specifying the type of a pattern isn't supported
| |
| expected one of `...`, `..=`, `..`, or `|`

error: expected `|`, found `:`
--> $DIR/anon-enums.rs:15:10
--> $DIR/anon-enums.rs:14:10
|
LL | _: f64 => (),
| ^ --- specifying the type of a pattern isn't supported
| |
| expected `|`

error: expected one of `@` or `|`, found `:`
--> $DIR/anon-enums.rs:16:10
--> $DIR/anon-enums.rs:15:10
|
LL | x: i32 => (),
| ^ --- specifying the type of a pattern isn't supported
Expand All @@ -64,18 +64,5 @@ help: maybe write a path separator here
LL | x::i32 => (),
| ~~

error[E0433]: failed to resolve: use of undeclared crate or module `x`
--> $DIR/anon-enums.rs:5:9
|
LL | x: i32 => x,
| ^ use of undeclared crate or module `x`

error[E0433]: failed to resolve: use of undeclared crate or module `x`
--> $DIR/anon-enums.rs:16:9
|
LL | x: i32 => (),
| ^ use of undeclared crate or module `x`

error: aborting due to 8 previous errors
error: aborting due to 6 previous errors

For more information about this error, try `rustc --explain E0433`.
1 change: 0 additions & 1 deletion tests/ui/parser/issues/issue-87086-colon-path-sep.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ fn main() {
Foo:Bar::Baz => {}
//~^ ERROR: expected one of
//~| HELP: maybe write a path separator here
//~| ERROR: failed to resolve: `Bar` is a variant, not a module
}
match myfoo {
Foo::Bar => {}
Expand Down
11 changes: 2 additions & 9 deletions tests/ui/parser/issues/issue-87086-colon-path-sep.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ LL | Foo::Bar::Baz => {}
| ~~

error: expected one of `@` or `|`, found `:`
--> $DIR/issue-87086-colon-path-sep.rs:75:12
--> $DIR/issue-87086-colon-path-sep.rs:74:12
|
LL | Foo:Bar => {}
| ^--- specifying the type of a pattern isn't supported
Expand All @@ -115,12 +115,5 @@ help: maybe write a path separator here
LL | Foo::Bar => {}
| ~~

error[E0433]: failed to resolve: `Bar` is a variant, not a module
--> $DIR/issue-87086-colon-path-sep.rs:68:13
|
LL | Foo:Bar::Baz => {}
| ^^^ `Bar` is a variant, not a module

error: aborting due to 10 previous errors
error: aborting due to 9 previous errors

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

0 comments on commit c847a01

Please sign in to comment.