Rollup merge of #88775 - pnkfelix:revert-anon-union-parsing, r=davidtwco
Revert anon union parsing Revert PR #84571 and #85515, which implemented anonymous union parsing in a manner that broke the context-sensitivity for the `union` keyword and thus broke stable Rust code. Fix #88583.
This commit is contained in:
commit
fb2d7dff80
21 changed files with 50 additions and 595 deletions
|
|
@ -1,24 +0,0 @@
|
|||
// Test for issue 85480
|
||||
// Pretty print anonymous struct and union types
|
||||
|
||||
// pp-exact
|
||||
// pretty-compare-only
|
||||
|
||||
struct Foo {
|
||||
_: union {
|
||||
_: struct {
|
||||
a: u8,
|
||||
b: u16,
|
||||
},
|
||||
c: u32,
|
||||
},
|
||||
d: u64,
|
||||
e: f32,
|
||||
}
|
||||
|
||||
type A =
|
||||
struct {
|
||||
field: u8,
|
||||
};
|
||||
|
||||
fn main() { }
|
||||
|
|
@ -1,27 +0,0 @@
|
|||
struct Foo {
|
||||
foo: u8,
|
||||
_: union { //~ ERROR unnamed fields are not yet fully implemented [E0658]
|
||||
//~^ ERROR unnamed fields are not yet fully implemented [E0658]
|
||||
//~| ERROR anonymous unions are unimplemented
|
||||
bar: u8,
|
||||
baz: u16
|
||||
}
|
||||
}
|
||||
|
||||
union Bar {
|
||||
foobar: u8,
|
||||
_: struct { //~ ERROR unnamed fields are not yet fully implemented [E0658]
|
||||
//~^ ERROR unnamed fields are not yet fully implemented [E0658]
|
||||
//~| ERROR anonymous structs are unimplemented
|
||||
//~| ERROR unions may not contain fields that need dropping [E0740]
|
||||
foobaz: u8,
|
||||
barbaz: u16
|
||||
}
|
||||
}
|
||||
|
||||
struct S;
|
||||
struct Baz {
|
||||
_: S //~ ERROR unnamed fields are not yet fully implemented [E0658]
|
||||
}
|
||||
|
||||
fn main(){}
|
||||
|
|
@ -1,111 +0,0 @@
|
|||
error[E0658]: unnamed fields are not yet fully implemented
|
||||
--> $DIR/feature-gate-unnamed_fields.rs:3:5
|
||||
|
|
||||
LL | _: union {
|
||||
| ^
|
||||
|
|
||||
= note: see issue #49804 <https://github.com/rust-lang/rust/issues/49804> for more information
|
||||
= help: add `#![feature(unnamed_fields)]` to the crate attributes to enable
|
||||
|
||||
error[E0658]: unnamed fields are not yet fully implemented
|
||||
--> $DIR/feature-gate-unnamed_fields.rs:3:8
|
||||
|
|
||||
LL | _: union {
|
||||
| ________^
|
||||
LL | |
|
||||
LL | |
|
||||
LL | | bar: u8,
|
||||
LL | | baz: u16
|
||||
LL | | }
|
||||
| |_____^
|
||||
|
|
||||
= note: see issue #49804 <https://github.com/rust-lang/rust/issues/49804> for more information
|
||||
= help: add `#![feature(unnamed_fields)]` to the crate attributes to enable
|
||||
|
||||
error[E0658]: unnamed fields are not yet fully implemented
|
||||
--> $DIR/feature-gate-unnamed_fields.rs:13:5
|
||||
|
|
||||
LL | _: struct {
|
||||
| ^
|
||||
|
|
||||
= note: see issue #49804 <https://github.com/rust-lang/rust/issues/49804> for more information
|
||||
= help: add `#![feature(unnamed_fields)]` to the crate attributes to enable
|
||||
|
||||
error[E0658]: unnamed fields are not yet fully implemented
|
||||
--> $DIR/feature-gate-unnamed_fields.rs:13:8
|
||||
|
|
||||
LL | _: struct {
|
||||
| ________^
|
||||
LL | |
|
||||
LL | |
|
||||
LL | |
|
||||
LL | | foobaz: u8,
|
||||
LL | | barbaz: u16
|
||||
LL | | }
|
||||
| |_____^
|
||||
|
|
||||
= note: see issue #49804 <https://github.com/rust-lang/rust/issues/49804> for more information
|
||||
= help: add `#![feature(unnamed_fields)]` to the crate attributes to enable
|
||||
|
||||
error[E0658]: unnamed fields are not yet fully implemented
|
||||
--> $DIR/feature-gate-unnamed_fields.rs:24:5
|
||||
|
|
||||
LL | _: S
|
||||
| ^
|
||||
|
|
||||
= note: see issue #49804 <https://github.com/rust-lang/rust/issues/49804> for more information
|
||||
= help: add `#![feature(unnamed_fields)]` to the crate attributes to enable
|
||||
|
||||
error: anonymous unions are unimplemented
|
||||
--> $DIR/feature-gate-unnamed_fields.rs:3:8
|
||||
|
|
||||
LL | _: union {
|
||||
| ________^
|
||||
LL | |
|
||||
LL | |
|
||||
LL | | bar: u8,
|
||||
LL | | baz: u16
|
||||
LL | | }
|
||||
| |_____^
|
||||
|
||||
error: anonymous structs are unimplemented
|
||||
--> $DIR/feature-gate-unnamed_fields.rs:13:8
|
||||
|
|
||||
LL | _: struct {
|
||||
| ________^
|
||||
LL | |
|
||||
LL | |
|
||||
LL | |
|
||||
LL | | foobaz: u8,
|
||||
LL | | barbaz: u16
|
||||
LL | | }
|
||||
| |_____^
|
||||
|
||||
error[E0740]: unions may not contain fields that need dropping
|
||||
--> $DIR/feature-gate-unnamed_fields.rs:13:5
|
||||
|
|
||||
LL | / _: struct {
|
||||
LL | |
|
||||
LL | |
|
||||
LL | |
|
||||
LL | | foobaz: u8,
|
||||
LL | | barbaz: u16
|
||||
LL | | }
|
||||
| |_____^
|
||||
|
|
||||
note: `std::mem::ManuallyDrop` can be used to wrap the type
|
||||
--> $DIR/feature-gate-unnamed_fields.rs:13:5
|
||||
|
|
||||
LL | / _: struct {
|
||||
LL | |
|
||||
LL | |
|
||||
LL | |
|
||||
LL | | foobaz: u8,
|
||||
LL | | barbaz: u16
|
||||
LL | | }
|
||||
| |_____^
|
||||
|
||||
error: aborting due to 8 previous errors
|
||||
|
||||
Some errors have detailed explanations: E0658, E0740.
|
||||
For more information about an error, try `rustc --explain E0658`.
|
||||
15
src/test/ui/parser/issue-88583-union-as-ident.rs
Normal file
15
src/test/ui/parser/issue-88583-union-as-ident.rs
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
// check-pass
|
||||
|
||||
#![allow(non_camel_case_types)]
|
||||
|
||||
struct union;
|
||||
|
||||
impl union {
|
||||
pub fn new() -> Self {
|
||||
union { }
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let _u = union::new();
|
||||
}
|
||||
|
|
@ -1,52 +0,0 @@
|
|||
#![allow(incomplete_features)]
|
||||
#![feature(unnamed_fields)]
|
||||
|
||||
fn f() -> struct { field: u8 } {} //~ ERROR anonymous structs are not allowed outside of unnamed struct or union fields
|
||||
//~^ ERROR anonymous structs are unimplemented
|
||||
|
||||
fn f2(a: struct { field: u8 } ) {} //~ ERROR anonymous structs are not allowed outside of unnamed struct or union fields
|
||||
//~^ ERROR anonymous structs are unimplemented
|
||||
|
||||
union G {
|
||||
field: struct { field: u8 } //~ ERROR anonymous structs are not allowed outside of unnamed struct or union fields
|
||||
//~^ ERROR anonymous structs are unimplemented
|
||||
}
|
||||
//~| ERROR unions may not contain fields that need dropping [E0740]
|
||||
|
||||
struct H { _: u8 } // Should error after hir checks
|
||||
|
||||
struct I(struct { field: u8 }, u8); //~ ERROR anonymous structs are not allowed outside of unnamed struct or union fields
|
||||
//~^ ERROR anonymous structs are unimplemented
|
||||
|
||||
enum J {
|
||||
K(struct { field: u8 }), //~ ERROR anonymous structs are not allowed outside of unnamed struct or union fields
|
||||
//~^ ERROR anonymous structs are unimplemented
|
||||
L {
|
||||
_ : struct { field: u8 } //~ ERROR anonymous structs are not allowed outside of unnamed struct or union fields
|
||||
//~^ ERROR anonymous fields are not allowed outside of structs or unions
|
||||
//~| ERROR anonymous structs are unimplemented
|
||||
},
|
||||
M {
|
||||
_ : u8 //~ ERROR anonymous fields are not allowed outside of structs or unions
|
||||
}
|
||||
}
|
||||
|
||||
static M: union { field: u8 } = 0; //~ ERROR anonymous unions are not allowed outside of unnamed struct or union fields
|
||||
//~^ ERROR anonymous unions are unimplemented
|
||||
|
||||
type N = union { field: u8 }; //~ ERROR anonymous unions are not allowed outside of unnamed struct or union fields
|
||||
//~^ ERROR anonymous unions are unimplemented
|
||||
|
||||
fn main() {
|
||||
const O: struct { field: u8 } = 0; //~ ERROR anonymous structs are not allowed outside of unnamed struct or union fields
|
||||
//~^ ERROR anonymous structs are unimplemented
|
||||
|
||||
let p: [struct { field: u8 }; 1]; //~ ERROR anonymous structs are not allowed outside of unnamed struct or union fields
|
||||
//~^ ERROR anonymous structs are unimplemented
|
||||
|
||||
let q: (struct { field: u8 }, u8); //~ ERROR anonymous structs are not allowed outside of unnamed struct or union fields
|
||||
//~^ ERROR anonymous structs are unimplemented
|
||||
|
||||
let cl = || -> struct { field: u8 } {}; //~ ERROR anonymous structs are not allowed outside of unnamed struct or union fields
|
||||
//~^ ERROR anonymous structs are unimplemented
|
||||
}
|
||||
|
|
@ -1,175 +0,0 @@
|
|||
error: anonymous structs are not allowed outside of unnamed struct or union fields
|
||||
--> $DIR/restrict_anonymous.rs:4:11
|
||||
|
|
||||
LL | fn f() -> struct { field: u8 } {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^ anonymous struct declared here
|
||||
|
||||
error: anonymous structs are not allowed outside of unnamed struct or union fields
|
||||
--> $DIR/restrict_anonymous.rs:7:10
|
||||
|
|
||||
LL | fn f2(a: struct { field: u8 } ) {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^ anonymous struct declared here
|
||||
|
||||
error: anonymous structs are not allowed outside of unnamed struct or union fields
|
||||
--> $DIR/restrict_anonymous.rs:11:12
|
||||
|
|
||||
LL | field: struct { field: u8 }
|
||||
| ^^^^^^^^^^^^^^^^^^^^ anonymous struct declared here
|
||||
|
||||
error: anonymous structs are not allowed outside of unnamed struct or union fields
|
||||
--> $DIR/restrict_anonymous.rs:18:10
|
||||
|
|
||||
LL | struct I(struct { field: u8 }, u8);
|
||||
| ^^^^^^^^^^^^^^^^^^^^ anonymous struct declared here
|
||||
|
||||
error: anonymous structs are not allowed outside of unnamed struct or union fields
|
||||
--> $DIR/restrict_anonymous.rs:22:7
|
||||
|
|
||||
LL | K(struct { field: u8 }),
|
||||
| ^^^^^^^^^^^^^^^^^^^^ anonymous struct declared here
|
||||
|
||||
error: anonymous fields are not allowed outside of structs or unions
|
||||
--> $DIR/restrict_anonymous.rs:25:9
|
||||
|
|
||||
LL | _ : struct { field: u8 }
|
||||
| -^^^^^^^^^^^^^^^^^^^^^^^
|
||||
| |
|
||||
| anonymous field declared here
|
||||
|
||||
error: anonymous structs are not allowed outside of unnamed struct or union fields
|
||||
--> $DIR/restrict_anonymous.rs:25:13
|
||||
|
|
||||
LL | _ : struct { field: u8 }
|
||||
| ^^^^^^^^^^^^^^^^^^^^ anonymous struct declared here
|
||||
|
||||
error: anonymous fields are not allowed outside of structs or unions
|
||||
--> $DIR/restrict_anonymous.rs:30:9
|
||||
|
|
||||
LL | _ : u8
|
||||
| -^^^^^
|
||||
| |
|
||||
| anonymous field declared here
|
||||
|
||||
error: anonymous unions are not allowed outside of unnamed struct or union fields
|
||||
--> $DIR/restrict_anonymous.rs:34:11
|
||||
|
|
||||
LL | static M: union { field: u8 } = 0;
|
||||
| ^^^^^^^^^^^^^^^^^^^ anonymous union declared here
|
||||
|
||||
error: anonymous unions are not allowed outside of unnamed struct or union fields
|
||||
--> $DIR/restrict_anonymous.rs:37:10
|
||||
|
|
||||
LL | type N = union { field: u8 };
|
||||
| ^^^^^^^^^^^^^^^^^^^ anonymous union declared here
|
||||
|
||||
error: anonymous structs are not allowed outside of unnamed struct or union fields
|
||||
--> $DIR/restrict_anonymous.rs:41:14
|
||||
|
|
||||
LL | const O: struct { field: u8 } = 0;
|
||||
| ^^^^^^^^^^^^^^^^^^^^ anonymous struct declared here
|
||||
|
||||
error: anonymous structs are not allowed outside of unnamed struct or union fields
|
||||
--> $DIR/restrict_anonymous.rs:44:13
|
||||
|
|
||||
LL | let p: [struct { field: u8 }; 1];
|
||||
| ^^^^^^^^^^^^^^^^^^^^ anonymous struct declared here
|
||||
|
||||
error: anonymous structs are not allowed outside of unnamed struct or union fields
|
||||
--> $DIR/restrict_anonymous.rs:47:13
|
||||
|
|
||||
LL | let q: (struct { field: u8 }, u8);
|
||||
| ^^^^^^^^^^^^^^^^^^^^ anonymous struct declared here
|
||||
|
||||
error: anonymous structs are not allowed outside of unnamed struct or union fields
|
||||
--> $DIR/restrict_anonymous.rs:50:20
|
||||
|
|
||||
LL | let cl = || -> struct { field: u8 } {};
|
||||
| ^^^^^^^^^^^^^^^^^^^^ anonymous struct declared here
|
||||
|
||||
error: anonymous structs are unimplemented
|
||||
--> $DIR/restrict_anonymous.rs:4:11
|
||||
|
|
||||
LL | fn f() -> struct { field: u8 } {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: anonymous structs are unimplemented
|
||||
--> $DIR/restrict_anonymous.rs:7:10
|
||||
|
|
||||
LL | fn f2(a: struct { field: u8 } ) {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: anonymous structs are unimplemented
|
||||
--> $DIR/restrict_anonymous.rs:11:12
|
||||
|
|
||||
LL | field: struct { field: u8 }
|
||||
| ^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: anonymous structs are unimplemented
|
||||
--> $DIR/restrict_anonymous.rs:18:10
|
||||
|
|
||||
LL | struct I(struct { field: u8 }, u8);
|
||||
| ^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: anonymous structs are unimplemented
|
||||
--> $DIR/restrict_anonymous.rs:22:7
|
||||
|
|
||||
LL | K(struct { field: u8 }),
|
||||
| ^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: anonymous structs are unimplemented
|
||||
--> $DIR/restrict_anonymous.rs:25:13
|
||||
|
|
||||
LL | _ : struct { field: u8 }
|
||||
| ^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: anonymous unions are unimplemented
|
||||
--> $DIR/restrict_anonymous.rs:34:11
|
||||
|
|
||||
LL | static M: union { field: u8 } = 0;
|
||||
| ^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: anonymous unions are unimplemented
|
||||
--> $DIR/restrict_anonymous.rs:37:10
|
||||
|
|
||||
LL | type N = union { field: u8 };
|
||||
| ^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: anonymous structs are unimplemented
|
||||
--> $DIR/restrict_anonymous.rs:44:13
|
||||
|
|
||||
LL | let p: [struct { field: u8 }; 1];
|
||||
| ^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: anonymous structs are unimplemented
|
||||
--> $DIR/restrict_anonymous.rs:47:13
|
||||
|
|
||||
LL | let q: (struct { field: u8 }, u8);
|
||||
| ^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: anonymous structs are unimplemented
|
||||
--> $DIR/restrict_anonymous.rs:50:20
|
||||
|
|
||||
LL | let cl = || -> struct { field: u8 } {};
|
||||
| ^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: anonymous structs are unimplemented
|
||||
--> $DIR/restrict_anonymous.rs:41:14
|
||||
|
|
||||
LL | const O: struct { field: u8 } = 0;
|
||||
| ^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error[E0740]: unions may not contain fields that need dropping
|
||||
--> $DIR/restrict_anonymous.rs:11:5
|
||||
|
|
||||
LL | field: struct { field: u8 }
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
note: `std::mem::ManuallyDrop` can be used to wrap the type
|
||||
--> $DIR/restrict_anonymous.rs:11:5
|
||||
|
|
||||
LL | field: struct { field: u8 }
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to 27 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0740`.
|
||||
Loading…
Add table
Add a link
Reference in a new issue