Emit fewer errors on patterns with possible type ascription
This commit is contained in:
parent
2d82420665
commit
c847a01a3b
5 changed files with 8 additions and 29 deletions
|
@ -2500,6 +2500,8 @@ impl<'a> Parser<'a> {
|
||||||
Ok(ty) => {
|
Ok(ty) => {
|
||||||
err.span_label(ty.span, "specifying the type of a pattern isn't supported");
|
err.span_label(ty.span, "specifying the type of a pattern isn't supported");
|
||||||
self.restore_snapshot(snapshot_type);
|
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();
|
err.emit();
|
||||||
|
|
|
@ -3,7 +3,6 @@ fn foo(x: bool | i32) -> i32 | f64 {
|
||||||
//~| ERROR anonymous enums are not supported
|
//~| ERROR anonymous enums are not supported
|
||||||
match x {
|
match x {
|
||||||
x: i32 => x, //~ ERROR expected
|
x: i32 => x, //~ ERROR expected
|
||||||
//~^ ERROR failed to resolve
|
|
||||||
true => 42.,
|
true => 42.,
|
||||||
false => 0.333,
|
false => 0.333,
|
||||||
}
|
}
|
||||||
|
@ -14,6 +13,5 @@ fn main() {
|
||||||
42: i32 => (), //~ ERROR expected
|
42: i32 => (), //~ ERROR expected
|
||||||
_: f64 => (), //~ ERROR expected
|
_: f64 => (), //~ ERROR expected
|
||||||
x: i32 => (), //~ ERROR expected
|
x: i32 => (), //~ ERROR expected
|
||||||
//~^ ERROR failed to resolve
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,7 +36,7 @@ LL | x::i32 => x,
|
||||||
| ~~
|
| ~~
|
||||||
|
|
||||||
error: expected one of `...`, `..=`, `..`, or `|`, found `:`
|
error: expected one of `...`, `..=`, `..`, or `|`, found `:`
|
||||||
--> $DIR/anon-enums.rs:14:11
|
--> $DIR/anon-enums.rs:13:11
|
||||||
|
|
|
|
||||||
LL | 42: i32 => (),
|
LL | 42: i32 => (),
|
||||||
| ^ --- specifying the type of a pattern isn't supported
|
| ^ --- specifying the type of a pattern isn't supported
|
||||||
|
@ -44,7 +44,7 @@ LL | 42: i32 => (),
|
||||||
| expected one of `...`, `..=`, `..`, or `|`
|
| expected one of `...`, `..=`, `..`, or `|`
|
||||||
|
|
||||||
error: expected `|`, found `:`
|
error: expected `|`, found `:`
|
||||||
--> $DIR/anon-enums.rs:15:10
|
--> $DIR/anon-enums.rs:14:10
|
||||||
|
|
|
|
||||||
LL | _: f64 => (),
|
LL | _: f64 => (),
|
||||||
| ^ --- specifying the type of a pattern isn't supported
|
| ^ --- specifying the type of a pattern isn't supported
|
||||||
|
@ -52,7 +52,7 @@ LL | _: f64 => (),
|
||||||
| expected `|`
|
| expected `|`
|
||||||
|
|
||||||
error: expected one of `@` or `|`, found `:`
|
error: expected one of `@` or `|`, found `:`
|
||||||
--> $DIR/anon-enums.rs:16:10
|
--> $DIR/anon-enums.rs:15:10
|
||||||
|
|
|
|
||||||
LL | x: i32 => (),
|
LL | x: i32 => (),
|
||||||
| ^ --- specifying the type of a pattern isn't supported
|
| ^ --- specifying the type of a pattern isn't supported
|
||||||
|
@ -64,18 +64,5 @@ help: maybe write a path separator here
|
||||||
LL | x::i32 => (),
|
LL | x::i32 => (),
|
||||||
| ~~
|
| ~~
|
||||||
|
|
||||||
error[E0433]: failed to resolve: use of undeclared crate or module `x`
|
error: aborting due to 6 previous errors
|
||||||
--> $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
|
|
||||||
|
|
||||||
For more information about this error, try `rustc --explain E0433`.
|
|
||||||
|
|
|
@ -68,7 +68,6 @@ fn main() {
|
||||||
Foo:Bar::Baz => {}
|
Foo:Bar::Baz => {}
|
||||||
//~^ ERROR: expected one of
|
//~^ ERROR: expected one of
|
||||||
//~| HELP: maybe write a path separator here
|
//~| HELP: maybe write a path separator here
|
||||||
//~| ERROR: failed to resolve: `Bar` is a variant, not a module
|
|
||||||
}
|
}
|
||||||
match myfoo {
|
match myfoo {
|
||||||
Foo::Bar => {}
|
Foo::Bar => {}
|
||||||
|
|
|
@ -103,7 +103,7 @@ LL | Foo::Bar::Baz => {}
|
||||||
| ~~
|
| ~~
|
||||||
|
|
||||||
error: expected one of `@` or `|`, found `:`
|
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 => {}
|
LL | Foo:Bar => {}
|
||||||
| ^--- specifying the type of a pattern isn't supported
|
| ^--- specifying the type of a pattern isn't supported
|
||||||
|
@ -115,12 +115,5 @@ help: maybe write a path separator here
|
||||||
LL | Foo::Bar => {}
|
LL | Foo::Bar => {}
|
||||||
| ~~
|
| ~~
|
||||||
|
|
||||||
error[E0433]: failed to resolve: `Bar` is a variant, not a module
|
error: aborting due to 9 previous errors
|
||||||
--> $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
|
|
||||||
|
|
||||||
For more information about this error, try `rustc --explain E0433`.
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue