diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2024-07-31 23:20:12 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-07-31 23:20:12 +0200 |
| commit | b22c48ed6ece1064d8f27da14cd27ed58d77086b (patch) | |
| tree | 38b17776f77924220d2561857ec72e6abc97c59c | |
| parent | 1ef8a4cbea6aff402f95015dfbc3727eb1f4ddac (diff) | |
| parent | 34fcf92ea003e401606552907516d08f1c3b94da (diff) | |
| download | rust-b22c48ed6ece1064d8f27da14cd27ed58d77086b.tar.gz rust-b22c48ed6ece1064d8f27da14cd27ed58d77086b.zip | |
Rollup merge of #128438 - Bryanskiy:empty-array-dropck, r=lcnr
Add special-case for [T, 0] in dropck_outlives implements/fixes #110288. r? `@lcnr`
| -rw-r--r-- | compiler/rustc_trait_selection/src/traits/query/dropck_outlives.rs | 11 | ||||
| -rw-r--r-- | tests/ui/dropck/dropck-empty-array.rs | 23 |
2 files changed, 32 insertions, 2 deletions
diff --git a/compiler/rustc_trait_selection/src/traits/query/dropck_outlives.rs b/compiler/rustc_trait_selection/src/traits/query/dropck_outlives.rs index 37a16a43acd..d3a1ed52d2e 100644 --- a/compiler/rustc_trait_selection/src/traits/query/dropck_outlives.rs +++ b/compiler/rustc_trait_selection/src/traits/query/dropck_outlives.rs @@ -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. diff --git a/tests/ui/dropck/dropck-empty-array.rs b/tests/ui/dropck/dropck-empty-array.rs new file mode 100644 index 00000000000..f3eca6aed8d --- /dev/null +++ b/tests/ui/dropck/dropck-empty-array.rs @@ -0,0 +1,23 @@ +//@ run-pass + +#[allow(dead_code)] +struct Struct<'s>(&'s str); + +impl<'s> Drop for Struct<'s> { + fn drop(&mut self) {} +} + +fn to_array_zero<T>(_: T) -> [T; 0] { + [] +} + +pub fn array_zero_in_tuple() { + let mut x = ([], String::new()); + { + let s = String::from("temporary"); + let p = Struct(&s); + x.0 = to_array_zero(p); + } +} + +fn main() {} |
