Auto merge of #107478 - compiler-errors:anon-enum-tys-are-ambiguous, r=estebank
Revert "Teach parser to understand fake anonymous enum syntax" and related commits anonymous enum types are currently ambiguous in positions like: * `|` operator: `a as fn() -> B | C` * closure args: `|_: as fn() -> A | B` I first tried to thread around `RecoverAnonEnum` into all these positions, but the resulting complexity in the compiler is IMO not worth it, or at least worth a bit more thinking time. In the mean time, let's revert this syntax for now, so we can go back to the drawing board. Fixes #107461 cc: `@estebank` `@cjgillot` #106960 --- ### Squashed revert commits: Revert "review comment: Remove AST AnonTy" This reverts commit020cca8d36
. Revert "Ensure macros are not affected" This reverts commit12d18e4031
. Revert "Emit fewer errors on patterns with possible type ascription" This reverts commitc847a01a3b
. Revert "Teach parser to understand fake anonymous enum syntax" This reverts commit2d82420665
.
This commit is contained in:
commit
97872b792c
10 changed files with 73 additions and 266 deletions
26
tests/ui/parser/anon-enums-are-ambiguous.rs
Normal file
26
tests/ui/parser/anon-enums-are-ambiguous.rs
Normal file
|
@ -0,0 +1,26 @@
|
|||
// check-pass
|
||||
|
||||
macro_rules! test_expr {
|
||||
($expr:expr) => {};
|
||||
}
|
||||
|
||||
macro_rules! test_ty {
|
||||
($a:ty | $b:ty) => {};
|
||||
}
|
||||
|
||||
fn main() {
|
||||
test_expr!(a as fn() -> B | C);
|
||||
// Do not break the `|` operator.
|
||||
|
||||
test_expr!(|_: fn() -> B| C | D);
|
||||
// Do not break `-> Ret` in closure args.
|
||||
|
||||
test_ty!(A | B);
|
||||
// We can't support anon enums in arbitrary positions.
|
||||
|
||||
test_ty!(fn() -> A | B);
|
||||
// Don't break fn ptrs.
|
||||
|
||||
test_ty!(impl Fn() -> A | B);
|
||||
// Don't break parenthesized generics.
|
||||
}
|
|
@ -1,17 +0,0 @@
|
|||
fn foo(x: bool | i32) -> i32 | f64 {
|
||||
//~^ ERROR anonymous enums are not supported
|
||||
//~| ERROR anonymous enums are not supported
|
||||
match x {
|
||||
x: i32 => x, //~ ERROR expected
|
||||
true => 42.,
|
||||
false => 0.333,
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
match foo(true) {
|
||||
42: i32 => (), //~ ERROR expected
|
||||
_: f64 => (), //~ ERROR expected
|
||||
x: i32 => (), //~ ERROR expected
|
||||
}
|
||||
}
|
|
@ -1,68 +0,0 @@
|
|||
error: anonymous enums are not supported
|
||||
--> $DIR/anon-enums.rs:1:16
|
||||
|
|
||||
LL | fn foo(x: bool | i32) -> i32 | f64 {
|
||||
| ---- ^ ---
|
||||
|
|
||||
= help: create a named `enum` and use it here instead:
|
||||
enum Name {
|
||||
Variant1(bool),
|
||||
Variant2(i32),
|
||||
}
|
||||
|
||||
error: anonymous enums are not supported
|
||||
--> $DIR/anon-enums.rs:1:30
|
||||
|
|
||||
LL | fn foo(x: bool | i32) -> i32 | f64 {
|
||||
| --- ^ ---
|
||||
|
|
||||
= help: create a named `enum` and use it here instead:
|
||||
enum Name {
|
||||
Variant1(i32),
|
||||
Variant2(f64),
|
||||
}
|
||||
|
||||
error: expected one of `@` or `|`, found `:`
|
||||
--> $DIR/anon-enums.rs:5:10
|
||||
|
|
||||
LL | x: i32 => x,
|
||||
| ^ --- specifying the type of a pattern isn't supported
|
||||
| |
|
||||
| expected one of `@` or `|`
|
||||
|
|
||||
help: maybe write a path separator here
|
||||
|
|
||||
LL | x::i32 => x,
|
||||
| ~~
|
||||
|
||||
error: expected one of `...`, `..=`, `..`, or `|`, found `:`
|
||||
--> $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:14:10
|
||||
|
|
||||
LL | _: f64 => (),
|
||||
| ^ --- specifying the type of a pattern isn't supported
|
||||
| |
|
||||
| expected `|`
|
||||
|
||||
error: expected one of `@` or `|`, found `:`
|
||||
--> $DIR/anon-enums.rs:15:10
|
||||
|
|
||||
LL | x: i32 => (),
|
||||
| ^ --- specifying the type of a pattern isn't supported
|
||||
| |
|
||||
| expected one of `@` or `|`
|
||||
|
|
||||
help: maybe write a path separator here
|
||||
|
|
||||
LL | x::i32 => (),
|
||||
| ~~
|
||||
|
||||
error: aborting due to 6 previous errors
|
||||
|
|
@ -1,20 +0,0 @@
|
|||
// build-pass
|
||||
macro_rules! check_ty {
|
||||
($Z:ty) => { compile_error!("triggered"); };
|
||||
($X:ty | $Y:ty) => { $X };
|
||||
}
|
||||
|
||||
macro_rules! check {
|
||||
($Z:ty) => { compile_error!("triggered"); };
|
||||
($X:ty | $Y:ty) => { };
|
||||
}
|
||||
|
||||
check! { i32 | u8 }
|
||||
|
||||
fn foo(x: check_ty! { i32 | u8 }) -> check_ty! { i32 | u8 } {
|
||||
x
|
||||
}
|
||||
fn main() {
|
||||
let x: check_ty! { i32 | u8 } = 42;
|
||||
let _: check_ty! { i32 | u8 } = foo(x);
|
||||
}
|
|
@ -68,6 +68,7 @@ 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 => {}
|
||||
|
|
|
@ -2,118 +2,89 @@ error: expected one of `@` or `|`, found `:`
|
|||
--> $DIR/issue-87086-colon-path-sep.rs:17:12
|
||||
|
|
||||
LL | Foo:Bar => {}
|
||||
| ^--- specifying the type of a pattern isn't supported
|
||||
| ^
|
||||
| |
|
||||
| expected one of `@` or `|`
|
||||
|
|
||||
help: maybe write a path separator here
|
||||
|
|
||||
LL | Foo::Bar => {}
|
||||
| ~~
|
||||
| help: maybe write a path separator here: `::`
|
||||
|
||||
error: expected one of `!`, `(`, `...`, `..=`, `..`, `::`, `{`, or `|`, found `:`
|
||||
--> $DIR/issue-87086-colon-path-sep.rs:23:17
|
||||
|
|
||||
LL | qux::Foo:Bar => {}
|
||||
| ^--- specifying the type of a pattern isn't supported
|
||||
| ^
|
||||
| |
|
||||
| expected one of 8 possible tokens
|
||||
|
|
||||
help: maybe write a path separator here
|
||||
|
|
||||
LL | qux::Foo::Bar => {}
|
||||
| ~~
|
||||
| help: maybe write a path separator here: `::`
|
||||
|
||||
error: expected one of `@` or `|`, found `:`
|
||||
--> $DIR/issue-87086-colon-path-sep.rs:29:12
|
||||
|
|
||||
LL | qux:Foo::Baz => {}
|
||||
| ^-------- specifying the type of a pattern isn't supported
|
||||
| ^
|
||||
| |
|
||||
| expected one of `@` or `|`
|
||||
|
|
||||
help: maybe write a path separator here
|
||||
|
|
||||
LL | qux::Foo::Baz => {}
|
||||
| ~~
|
||||
| help: maybe write a path separator here: `::`
|
||||
|
||||
error: expected one of `@` or `|`, found `:`
|
||||
--> $DIR/issue-87086-colon-path-sep.rs:35:12
|
||||
|
|
||||
LL | qux: Foo::Baz if true => {}
|
||||
| ^ -------- specifying the type of a pattern isn't supported
|
||||
| ^
|
||||
| |
|
||||
| expected one of `@` or `|`
|
||||
|
|
||||
help: maybe write a path separator here
|
||||
|
|
||||
LL | qux::Foo::Baz if true => {}
|
||||
| ~~
|
||||
| help: maybe write a path separator here: `::`
|
||||
|
||||
error: expected one of `@` or `|`, found `:`
|
||||
--> $DIR/issue-87086-colon-path-sep.rs:40:15
|
||||
|
|
||||
LL | if let Foo:Bar = f() {
|
||||
| ^--- specifying the type of a pattern isn't supported
|
||||
| ^
|
||||
| |
|
||||
| expected one of `@` or `|`
|
||||
|
|
||||
help: maybe write a path separator here
|
||||
|
|
||||
LL | if let Foo::Bar = f() {
|
||||
| ~~
|
||||
| help: maybe write a path separator here: `::`
|
||||
|
||||
error: expected one of `@` or `|`, found `:`
|
||||
--> $DIR/issue-87086-colon-path-sep.rs:48:16
|
||||
|
|
||||
LL | ref qux: Foo::Baz => {}
|
||||
| ^ -------- specifying the type of a pattern isn't supported
|
||||
| ^
|
||||
| |
|
||||
| expected one of `@` or `|`
|
||||
|
|
||||
help: maybe write a path separator here
|
||||
|
|
||||
LL | ref qux::Foo::Baz => {}
|
||||
| ~~
|
||||
| help: maybe write a path separator here: `::`
|
||||
|
||||
error: expected one of `@` or `|`, found `:`
|
||||
--> $DIR/issue-87086-colon-path-sep.rs:57:16
|
||||
|
|
||||
LL | mut qux: Foo::Baz => {}
|
||||
| ^ -------- specifying the type of a pattern isn't supported
|
||||
| ^
|
||||
| |
|
||||
| expected one of `@` or `|`
|
||||
|
|
||||
help: maybe write a path separator here
|
||||
|
|
||||
LL | mut qux::Foo::Baz => {}
|
||||
| ~~
|
||||
| help: maybe write a path separator here: `::`
|
||||
|
||||
error: expected one of `@` or `|`, found `:`
|
||||
--> $DIR/issue-87086-colon-path-sep.rs:68:12
|
||||
|
|
||||
LL | Foo:Bar::Baz => {}
|
||||
| ^-------- specifying the type of a pattern isn't supported
|
||||
| ^
|
||||
| |
|
||||
| expected one of `@` or `|`
|
||||
|
|
||||
help: maybe write a path separator here
|
||||
|
|
||||
LL | Foo::Bar::Baz => {}
|
||||
| ~~
|
||||
| help: maybe write a path separator here: `::`
|
||||
|
||||
error: expected one of `@` or `|`, found `:`
|
||||
--> $DIR/issue-87086-colon-path-sep.rs:74:12
|
||||
--> $DIR/issue-87086-colon-path-sep.rs:75:12
|
||||
|
|
||||
LL | Foo:Bar => {}
|
||||
| ^--- specifying the type of a pattern isn't supported
|
||||
| ^
|
||||
| |
|
||||
| expected one of `@` or `|`
|
||||
|
|
||||
help: maybe write a path separator here
|
||||
|
|
||||
LL | Foo::Bar => {}
|
||||
| ~~
|
||||
| help: maybe write a path separator here: `::`
|
||||
|
||||
error: aborting due to 9 previous errors
|
||||
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
|
||||
|
||||
For more information about this error, try `rustc --explain E0433`.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue