mirror of
https://github.com/rust-lang/rust.git
synced 2024-10-31 22:41:50 +00:00
Add #[derive(Clone, Copy)]
to anonymous adts
Fix the `AssertBoundIsClone` error for anonymous adts.
This commit is contained in:
parent
822d6dc5fd
commit
2b04ca94bb
@ -2161,6 +2161,10 @@ impl TyKind {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_anon_adt(&self) -> bool {
|
||||
matches!(self, TyKind::AnonStruct(..) | TyKind::AnonUnion(..))
|
||||
}
|
||||
}
|
||||
|
||||
/// Syntax used to declare a trait object.
|
||||
|
@ -110,7 +110,9 @@ fn cs_clone_simple(
|
||||
&& !seen_type_names.insert(name)
|
||||
{
|
||||
// Already produced an assertion for this type.
|
||||
} else {
|
||||
// Anonymous structs or unions must be eliminated as they cannot be
|
||||
// type parameters.
|
||||
} else if !field.ty.kind.is_anon_adt() {
|
||||
// let _: AssertParamIsClone<FieldTy>;
|
||||
super::assert_ty_bounds(
|
||||
cx,
|
||||
|
@ -123,6 +123,8 @@ fn assert_ty_bounds(
|
||||
span: Span,
|
||||
assert_path: &[Symbol],
|
||||
) {
|
||||
// Deny anonymous structs or unions to avoid wierd errors.
|
||||
assert!(!ty.kind.is_anon_adt(), "Anonymous structs or unions cannot be type parameters");
|
||||
// Generate statement `let _: assert_path<ty>;`.
|
||||
let span = cx.with_def_site_ctxt(span);
|
||||
let assert_path = cx.path_all(span, true, cx.std_path(assert_path), vec![GenericArg::Type(ty)]);
|
||||
|
@ -1,11 +1,13 @@
|
||||
#![allow(incomplete_features)]
|
||||
#![feature(unnamed_fields)]
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
#[repr(C)]
|
||||
struct Foo {
|
||||
a: u8,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
#[repr(C)]
|
||||
struct Bar {
|
||||
_: union {
|
||||
@ -15,6 +17,7 @@ struct Bar {
|
||||
|
||||
|
||||
// duplicated with a normal field
|
||||
#[derive(Clone, Copy)]
|
||||
#[repr(C)]
|
||||
union A {
|
||||
// referent field
|
||||
@ -44,6 +47,7 @@ union A {
|
||||
}
|
||||
|
||||
// duplicated with a nested field
|
||||
#[derive(Clone, Copy)]
|
||||
#[repr(C)]
|
||||
struct B {
|
||||
_: union {
|
||||
@ -95,6 +99,7 @@ struct B {
|
||||
}
|
||||
|
||||
// duplicated with a more nested field
|
||||
#[derive(Clone, Copy)]
|
||||
#[repr(C)]
|
||||
union C {
|
||||
_: struct {
|
||||
@ -168,6 +173,7 @@ union C {
|
||||
}
|
||||
|
||||
// duplicated with a nested field in a named adt
|
||||
#[derive(Clone, Copy)]
|
||||
#[repr(C)]
|
||||
struct D {
|
||||
// referent field `a`
|
||||
@ -196,6 +202,7 @@ struct D {
|
||||
}
|
||||
|
||||
// duplicated with a nested field in a nested field of a named adt
|
||||
#[derive(Clone, Copy)]
|
||||
#[repr(C)]
|
||||
union D2 {
|
||||
// referent field `a`
|
||||
@ -224,6 +231,7 @@ union D2 {
|
||||
}
|
||||
|
||||
// duplicated with a nested field in a named adt in an anonymous adt
|
||||
#[derive(Clone, Copy)]
|
||||
#[repr(C)]
|
||||
struct E {
|
||||
_: struct {
|
||||
@ -276,6 +284,7 @@ struct E {
|
||||
|
||||
// duplicated with a nested field in a named adt in an anonymous adt
|
||||
#[repr(C)]
|
||||
#[derive(Clone, Copy)]
|
||||
union E2 {
|
||||
_: struct {
|
||||
// referent field `a`
|
||||
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user