mirror of
https://github.com/rust-lang/rust
synced 2024-11-05 20:45:15 +00:00
868706d9b5
Anonymous structs or unions are only allowed in struct field definitions. Co-authored-by: carbotaniuman <41451839+carbotaniuman@users.noreply.github.com>
72 lines
1.2 KiB
Rust
72 lines
1.2 KiB
Rust
// check-pass
|
|
|
|
#![allow(non_camel_case_types)]
|
|
#![allow(non_upper_case_globals)]
|
|
|
|
mod union {
|
|
type union = i32;
|
|
|
|
pub struct Bar {
|
|
pub union: union,
|
|
}
|
|
|
|
pub fn union() -> Bar {
|
|
Bar {
|
|
union: 5
|
|
}
|
|
}
|
|
}
|
|
|
|
mod struct_union {
|
|
pub struct union {
|
|
pub union: u32
|
|
}
|
|
static union: union = union { union: 0 };
|
|
|
|
impl union {
|
|
pub fn union<'union>() -> &'union union {
|
|
&union
|
|
}
|
|
}
|
|
impl union {}
|
|
trait Foo {}
|
|
impl Foo for union {}
|
|
trait Bar {
|
|
fn bar() {}
|
|
}
|
|
impl Bar for union {}
|
|
}
|
|
|
|
mod union_union {
|
|
pub union union {
|
|
pub union: u32
|
|
}
|
|
const union: union = union { union: 0 };
|
|
impl union {
|
|
pub fn union() -> union {
|
|
union
|
|
}
|
|
}
|
|
}
|
|
|
|
mod trait_union {
|
|
pub trait union {
|
|
fn union() {}
|
|
}
|
|
impl union for () {}
|
|
}
|
|
|
|
macro_rules! ty {
|
|
($ty:ty { $($field:ident:$field_ty:ty)* }) => {};
|
|
}
|
|
|
|
fn main() {
|
|
let union = union::union();
|
|
let _ = union.union;
|
|
let _ = struct_union::union::union().union;
|
|
let union = union_union::union::union();
|
|
let _ = unsafe { union.union };
|
|
<() as trait_union::union>::union();
|
|
ty!(union {});
|
|
ty!(union { union: union });
|
|
}
|