From 53007ddb8c5942a977e0b8faffe7a55a687730d5 Mon Sep 17 00:00:00 2001 From: Deadbeef Date: Sun, 3 Sep 2023 13:09:12 +0000 Subject: [PATCH] `needs_drop`: make more progress when given an array with variable length --- compiler/rustc_ty_utils/src/needs_drop.rs | 10 +++++++++- tests/ui/consts/issue-115410-drop-manuallydrop.rs | 5 +++++ 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 tests/ui/consts/issue-115410-drop-manuallydrop.rs diff --git a/compiler/rustc_ty_utils/src/needs_drop.rs b/compiler/rustc_ty_utils/src/needs_drop.rs index 34fd31e49e10d..9bc1ee35f7d5d 100644 --- a/compiler/rustc_ty_utils/src/needs_drop.rs +++ b/compiler/rustc_ty_utils/src/needs_drop.rs @@ -164,7 +164,15 @@ where queue_type(self, required); } } - ty::Alias(..) | ty::Array(..) | ty::Placeholder(_) | ty::Param(_) => { + ty::Array(ty, _) => { + // `needs_drop_components` above will look at the array and check if the array + // length is known to be zero. If it can't evalaute the constant it will throw + // the array back at us. Since we aren't smart enough to be able to foretell + // whether the array length will end up being zero, we have to make more progress + // by decomposing it to its inner type. + queue_type(self, ty); + } + ty::Alias(..) | ty::Placeholder(_) | ty::Param(_) => { if ty == component { // Return the type to the caller: they may be able // to normalize further than we can. diff --git a/tests/ui/consts/issue-115410-drop-manuallydrop.rs b/tests/ui/consts/issue-115410-drop-manuallydrop.rs new file mode 100644 index 0000000000000..f15f0661bbf6d --- /dev/null +++ b/tests/ui/consts/issue-115410-drop-manuallydrop.rs @@ -0,0 +1,5 @@ +// check-pass + +pub const fn f(_: [std::mem::MaybeUninit; N]) {} + +fn main() {}