Rollup merge of #128438 - Bryanskiy:empty-array-dropck, r=lcnr

Add special-case for [T, 0] in dropck_outlives

implements/fixes #110288.

r? `@lcnr`
This commit is contained in:
Matthias Krüger 2024-07-31 23:20:12 +02:00 committed by GitHub
commit b22c48ed6e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 32 additions and 2 deletions

View file

@ -42,8 +42,15 @@ pub fn trivial_dropck_outlives<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> bool {
| ty::Foreign(..)
| ty::Error(_) => true,
// `T is PAT`, `[T; N]`, and `[T]` have same properties as T.
ty::Pat(ty, _) | ty::Array(ty, _) | ty::Slice(ty) => trivial_dropck_outlives(tcx, *ty),
// `T is PAT` and `[T]` have same properties as T.
ty::Pat(ty, _) | ty::Slice(ty) => trivial_dropck_outlives(tcx, *ty),
ty::Array(ty, size) => {
// Empty array never has a dtor. See issue #110288.
match size.try_to_target_usize(tcx) {
Some(0) => true,
_ => trivial_dropck_outlives(tcx, *ty),
}
}
// (T1..Tn) and closures have same properties as T1..Tn --
// check if *all* of them are trivial.