Skip to content

Commit c847a01

Browse files
committed
Emit fewer errors on patterns with possible type ascription
1 parent 2d82420 commit c847a01

File tree

5 files changed

+8
-29
lines changed

5 files changed

+8
-29
lines changed

compiler/rustc_parse/src/parser/diagnostics.rs

+2
Original file line numberDiff line numberDiff line change
@@ -2500,6 +2500,8 @@ impl<'a> Parser<'a> {
25002500
Ok(ty) => {
25012501
err.span_label(ty.span, "specifying the type of a pattern isn't supported");
25022502
self.restore_snapshot(snapshot_type);
2503+
let new_span = first_pat.span.to(ty.span);
2504+
first_pat = self.mk_pat(new_span, PatKind::Wild);
25032505
}
25042506
}
25052507
err.emit();

tests/ui/parser/anon-enums.rs

-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ fn foo(x: bool | i32) -> i32 | f64 {
33
//~| ERROR anonymous enums are not supported
44
match x {
55
x: i32 => x, //~ ERROR expected
6-
//~^ ERROR failed to resolve
76
true => 42.,
87
false => 0.333,
98
}
@@ -14,6 +13,5 @@ fn main() {
1413
42: i32 => (), //~ ERROR expected
1514
_: f64 => (), //~ ERROR expected
1615
x: i32 => (), //~ ERROR expected
17-
//~^ ERROR failed to resolve
1816
}
1917
}

tests/ui/parser/anon-enums.stderr

+4-17
Original file line numberDiff line numberDiff line change
@@ -36,23 +36,23 @@ LL | x::i32 => x,
3636
| ~~
3737

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

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

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

67-
error[E0433]: failed to resolve: use of undeclared crate or module `x`
68-
--> $DIR/anon-enums.rs:5:9
69-
|
70-
LL | x: i32 => x,
71-
| ^ use of undeclared crate or module `x`
72-
73-
error[E0433]: failed to resolve: use of undeclared crate or module `x`
74-
--> $DIR/anon-enums.rs:16:9
75-
|
76-
LL | x: i32 => (),
77-
| ^ use of undeclared crate or module `x`
78-
79-
error: aborting due to 8 previous errors
67+
error: aborting due to 6 previous errors
8068

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

tests/ui/parser/issues/issue-87086-colon-path-sep.rs

-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ fn main() {
6868
Foo:Bar::Baz => {}
6969
//~^ ERROR: expected one of
7070
//~| HELP: maybe write a path separator here
71-
//~| ERROR: failed to resolve: `Bar` is a variant, not a module
7271
}
7372
match myfoo {
7473
Foo::Bar => {}

tests/ui/parser/issues/issue-87086-colon-path-sep.stderr

+2-9
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ LL | Foo::Bar::Baz => {}
103103
| ~~
104104

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

118-
error[E0433]: failed to resolve: `Bar` is a variant, not a module
119-
--> $DIR/issue-87086-colon-path-sep.rs:68:13
120-
|
121-
LL | Foo:Bar::Baz => {}
122-
| ^^^ `Bar` is a variant, not a module
123-
124-
error: aborting due to 10 previous errors
118+
error: aborting due to 9 previous errors
125119

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

0 commit comments

Comments
 (0)