diff options
| author | Frank King <frankking1729@gmail.com> | 2023-08-23 20:53:47 +0800 |
|---|---|---|
| committer | Frank King <frankking1729@gmail.com> | 2023-08-24 11:17:54 +0800 |
| commit | 868706d9b50ddf27995a9ee4d863e163b78b7365 (patch) | |
| tree | 2ab997f259ea9cef60860e1a3407e8184a114cd7 /tests/ui/union | |
| parent | 439d066bcf9496b1b8c8dde8bef3bce607a621bb (diff) | |
| download | rust-868706d9b50ddf27995a9ee4d863e163b78b7365.tar.gz rust-868706d9b50ddf27995a9ee4d863e163b78b7365.zip | |
Parse unnamed fields and anonymous structs or unions
Anonymous structs or unions are only allowed in struct field definitions. Co-authored-by: carbotaniuman <41451839+carbotaniuman@users.noreply.github.com>
Diffstat (limited to 'tests/ui/union')
4 files changed, 230 insertions, 0 deletions
diff --git a/tests/ui/union/unnamed-fields/restrict_anonymous_structs.rs b/tests/ui/union/unnamed-fields/restrict_anonymous_structs.rs new file mode 100644 index 00000000000..192bbba5a5b --- /dev/null +++ b/tests/ui/union/unnamed-fields/restrict_anonymous_structs.rs @@ -0,0 +1,37 @@ +#![allow(incomplete_features)] +#![feature(unnamed_fields)] + +struct F { + field: struct { field: u8 }, //~ ERROR anonymous structs are not allowed outside of unnamed struct or union fields + //~^ ERROR anonymous structs are unimplemented + _: struct { field: u8 }, + //~^ ERROR anonymous structs are unimplemented +} + +struct G { + _: (u8, u8), //~ ERROR unnamed fields can only have struct or union types +} + +union H { + field: struct { field: u8 }, //~ ERROR anonymous structs are not allowed outside of unnamed struct or union fields + //~^ ERROR anonymous structs are unimplemented + _: struct { field: u8 }, + //~^ ERROR anonymous structs are unimplemented +} + +union I { + _: (u8, u8), //~ ERROR unnamed fields can only have struct or union types +} + +enum K { + M { + _ : struct { field: u8 }, //~ ERROR anonymous structs are not allowed outside of unnamed struct or union fields + //~^ ERROR unnamed fields are not allowed outside of structs or unions + //~| ERROR anonymous structs are unimplemented + }, + N { + _ : u8, //~ ERROR unnamed fields are not allowed outside of structs or unions + } +} + +fn main() {} diff --git a/tests/ui/union/unnamed-fields/restrict_anonymous_structs.stderr b/tests/ui/union/unnamed-fields/restrict_anonymous_structs.stderr new file mode 100644 index 00000000000..fd731766c01 --- /dev/null +++ b/tests/ui/union/unnamed-fields/restrict_anonymous_structs.stderr @@ -0,0 +1,78 @@ +error: anonymous structs are not allowed outside of unnamed struct or union fields + --> $DIR/restrict_anonymous_structs.rs:5:12 + | +LL | field: struct { field: u8 }, + | ^^^^^^^^^^^^^^^^^^^^ anonymous struct declared here + +error: unnamed fields can only have struct or union types + --> $DIR/restrict_anonymous_structs.rs:12:5 + | +LL | _: (u8, u8), + | ^ -------- not a struct or union + +error: anonymous structs are not allowed outside of unnamed struct or union fields + --> $DIR/restrict_anonymous_structs.rs:16:12 + | +LL | field: struct { field: u8 }, + | ^^^^^^^^^^^^^^^^^^^^ anonymous struct declared here + +error: unnamed fields can only have struct or union types + --> $DIR/restrict_anonymous_structs.rs:23:5 + | +LL | _: (u8, u8), + | ^ -------- not a struct or union + +error: unnamed fields are not allowed outside of structs or unions + --> $DIR/restrict_anonymous_structs.rs:28:9 + | +LL | _ : struct { field: u8 }, + | -^^^^^^^^^^^^^^^^^^^^^^^ + | | + | unnamed field declared here + +error: anonymous structs are not allowed outside of unnamed struct or union fields + --> $DIR/restrict_anonymous_structs.rs:28:13 + | +LL | _ : struct { field: u8 }, + | ^^^^^^^^^^^^^^^^^^^^ anonymous struct declared here + +error: unnamed fields are not allowed outside of structs or unions + --> $DIR/restrict_anonymous_structs.rs:33:9 + | +LL | _ : u8, + | -^^^^^ + | | + | unnamed field declared here + +error: anonymous structs are unimplemented + --> $DIR/restrict_anonymous_structs.rs:5:12 + | +LL | field: struct { field: u8 }, + | ^^^^^^^^^^^^^^^^^^^^ + +error: anonymous structs are unimplemented + --> $DIR/restrict_anonymous_structs.rs:7:8 + | +LL | _: struct { field: u8 }, + | ^^^^^^^^^^^^^^^^^^^^ + +error: anonymous structs are unimplemented + --> $DIR/restrict_anonymous_structs.rs:16:12 + | +LL | field: struct { field: u8 }, + | ^^^^^^^^^^^^^^^^^^^^ + +error: anonymous structs are unimplemented + --> $DIR/restrict_anonymous_structs.rs:18:8 + | +LL | _: struct { field: u8 }, + | ^^^^^^^^^^^^^^^^^^^^ + +error: anonymous structs are unimplemented + --> $DIR/restrict_anonymous_structs.rs:28:13 + | +LL | _ : struct { field: u8 }, + | ^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to 12 previous errors + diff --git a/tests/ui/union/unnamed-fields/restrict_anonymous_unions.rs b/tests/ui/union/unnamed-fields/restrict_anonymous_unions.rs new file mode 100644 index 00000000000..c69266089bb --- /dev/null +++ b/tests/ui/union/unnamed-fields/restrict_anonymous_unions.rs @@ -0,0 +1,37 @@ +#![allow(incomplete_features)] +#![feature(unnamed_fields)] + +struct F { + field: union { field: u8 }, //~ ERROR anonymous unions are not allowed outside of unnamed struct or union fields + //~^ ERROR anonymous unions are unimplemented + _: union { field: u8 }, + //~^ ERROR anonymous unions are unimplemented +} + +struct G { + _: (u8, u8), //~ ERROR unnamed fields can only have struct or union types +} + +union H { + field: union { field: u8 }, //~ ERROR anonymous unions are not allowed outside of unnamed struct or union fields + //~^ ERROR anonymous unions are unimplemented + _: union { field: u8 }, + //~^ ERROR anonymous unions are unimplemented +} + +union I { + _: (u8, u8), //~ ERROR unnamed fields can only have struct or union types +} + +enum K { + M { + _ : union { field: u8 }, //~ ERROR anonymous unions are not allowed outside of unnamed struct or union fields + //~^ ERROR unnamed fields are not allowed outside of structs or unions + //~| ERROR anonymous unions are unimplemented + }, + N { + _ : u8, //~ ERROR unnamed fields are not allowed outside of structs or unions + } +} + +fn main() {} diff --git a/tests/ui/union/unnamed-fields/restrict_anonymous_unions.stderr b/tests/ui/union/unnamed-fields/restrict_anonymous_unions.stderr new file mode 100644 index 00000000000..c65cad775a9 --- /dev/null +++ b/tests/ui/union/unnamed-fields/restrict_anonymous_unions.stderr @@ -0,0 +1,78 @@ +error: anonymous unions are not allowed outside of unnamed struct or union fields + --> $DIR/restrict_anonymous_unions.rs:5:12 + | +LL | field: union { field: u8 }, + | ^^^^^^^^^^^^^^^^^^^ anonymous union declared here + +error: unnamed fields can only have struct or union types + --> $DIR/restrict_anonymous_unions.rs:12:5 + | +LL | _: (u8, u8), + | ^ -------- not a struct or union + +error: anonymous unions are not allowed outside of unnamed struct or union fields + --> $DIR/restrict_anonymous_unions.rs:16:12 + | +LL | field: union { field: u8 }, + | ^^^^^^^^^^^^^^^^^^^ anonymous union declared here + +error: unnamed fields can only have struct or union types + --> $DIR/restrict_anonymous_unions.rs:23:5 + | +LL | _: (u8, u8), + | ^ -------- not a struct or union + +error: unnamed fields are not allowed outside of structs or unions + --> $DIR/restrict_anonymous_unions.rs:28:9 + | +LL | _ : union { field: u8 }, + | -^^^^^^^^^^^^^^^^^^^^^^ + | | + | unnamed field declared here + +error: anonymous unions are not allowed outside of unnamed struct or union fields + --> $DIR/restrict_anonymous_unions.rs:28:13 + | +LL | _ : union { field: u8 }, + | ^^^^^^^^^^^^^^^^^^^ anonymous union declared here + +error: unnamed fields are not allowed outside of structs or unions + --> $DIR/restrict_anonymous_unions.rs:33:9 + | +LL | _ : u8, + | -^^^^^ + | | + | unnamed field declared here + +error: anonymous unions are unimplemented + --> $DIR/restrict_anonymous_unions.rs:5:12 + | +LL | field: union { field: u8 }, + | ^^^^^^^^^^^^^^^^^^^ + +error: anonymous unions are unimplemented + --> $DIR/restrict_anonymous_unions.rs:7:8 + | +LL | _: union { field: u8 }, + | ^^^^^^^^^^^^^^^^^^^ + +error: anonymous unions are unimplemented + --> $DIR/restrict_anonymous_unions.rs:16:12 + | +LL | field: union { field: u8 }, + | ^^^^^^^^^^^^^^^^^^^ + +error: anonymous unions are unimplemented + --> $DIR/restrict_anonymous_unions.rs:18:8 + | +LL | _: union { field: u8 }, + | ^^^^^^^^^^^^^^^^^^^ + +error: anonymous unions are unimplemented + --> $DIR/restrict_anonymous_unions.rs:28:13 + | +LL | _ : union { field: u8 }, + | ^^^^^^^^^^^^^^^^^^^ + +error: aborting due to 12 previous errors + |
