Skip to content

needs_drop: make more progress when given an array with variable length #115508

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion compiler/rustc_ty_utils/src/needs_drop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
5 changes: 5 additions & 0 deletions tests/ui/consts/issue-115410-drop-manuallydrop.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// check-pass

pub const fn f<T, const N: usize>(_: [std::mem::MaybeUninit<T>; N]) {}

fn main() {}