Lower anonymous structs or unions to HIR

This commit is contained in:
Frank King 2024-01-04 21:53:06 +08:00
parent 084ce5bdb5
commit 879a1e5713
38 changed files with 288 additions and 174 deletions

View file

@ -181,6 +181,11 @@ pub(in crate::solve) fn instantiate_constituent_tys_for_copy_clone_trait<'tcx>(
| ty::Ref(_, _, Mutability::Not)
| ty::Array(..) => Err(NoSolution),
// Check for anonymous adts.
ty::Adt(adt, generics) if adt.is_anonymous() => {
Ok(adt.all_fields().map(|f| f.ty(ecx.tcx(), generics)).collect())
}
ty::Dynamic(..)
| ty::Str
| ty::Slice(_)

View file

@ -2212,6 +2212,16 @@ impl<'tcx> SelectionContext<'_, 'tcx> {
// FIXME(async_closures): These are never clone, for now.
ty::CoroutineClosure(_, _) => None,
// `Copy` and `Clone` are automatically impelemented for an anonymous adt
// if all of its fields are `Copy` and `Clone`
ty::Adt(adt, args) if adt.is_anonymous() => {
// (*) binder moved here
Where(
obligation
.predicate
.rebind(adt.all_fields().map(|f| f.ty(self.tcx(), args)).collect()),
)
}
ty::Adt(..) | ty::Alias(..) | ty::Param(..) | ty::Placeholder(..) => {
// Fallback to whatever user-defined impls exist in this case.