1
Fork 0

Add #[derive(Clone, Copy)] to anonymous adts

Fix the `AssertBoundIsClone` error for anonymous adts.
This commit is contained in:
Frank King 2024-01-20 12:55:21 +08:00
parent 822d6dc5fd
commit 2b04ca94bb
5 changed files with 193 additions and 176 deletions

View file

@ -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,

View file

@ -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)]);