Uh oh!
There was an error while loading. Please reload this page.
Fix: Drop ZST elements properly in array::map and array::try_map - #152248
Fix: Drop ZST elements properly in array::map and array::try_map#152248TusharB-07 wants to merge 2 commits into
Conversation
Fixesrust-lang#152211 Previously, the Drain::drop implementation would skip dropping zero-sized types entirely, causing Drop implementations on ZSTs to never run when a closure panicked or exited early. This fix adds a zst_processed counter to track how many ZST elements have been processed, ensuring that remaining unprocessed ZSTs are properly dropped when the Drain is dropped. For ZSTs, conjure_zst() creates new values rather than moving from the array, so all N original elements remain and must be accounted for.
rustbot
commented
Feb 6, 2026
r? @scottmcm rustbot has assigned @scottmcm. Use Why was this reviewer chosen?The reviewer was selected based on:
|
rustbot
commented
Feb 6, 2026
|
This comment has been minimized.
This comment has been minimized.
scottmcm
commented
Feb 6, 2026
Ah, I see, this got screwed up in the const hackery. It originally used a Until the bots and CI are happy, |
rustbot
commented
Feb 6, 2026
Reminder, once the PR becomes ready for a review, use |
lqd
commented
Feb 6, 2026
There also already is another PR for this issue, in #152220 |
TusharB-07
commented
Feb 8, 2026
@rustbot ready |
TusharB-07
commented
Feb 9, 2026
@rustbot claim |
theemathas
commented
Feb 10, 2026
@workingjubilee This PR is now assigned to nobody. Is this intended? |
core: drop unmapped ZSTs in array `map` Fixesrust-lang#152211. Alternative to rust-lang#152220 and rust-lang#152248. This makes the `Drain` type use the same ZST-handling strategy as `slice::IterMut`, which stores the remaining length instead of a one-past-the-end pointer when the type is a ZST. I've also removed the const-generic `N` parameter from `Drain` to avoid unnecessary monomorphizations.
core: drop unmapped ZSTs in array `map` Fixesrust-lang#152211. Alternative to rust-lang#152220 and rust-lang#152248. This makes the `Drain` type use the same ZST-handling strategy as `slice::IterMut`, which stores the remaining length instead of a one-past-the-end pointer when the type is a ZST. I've also removed the const-generic `N` parameter from `Drain` to avoid unnecessary monomorphizations.
core: drop unmapped ZSTs in array `map` Fixes#152211. Alternative to #152220 and #152248. This makes the `Drain` type use the same ZST-handling strategy as `slice::IterMut`, which stores the remaining length instead of a one-past-the-end pointer when the type is a ZST. I've also removed the const-generic `N` parameter from `Drain` to avoid unnecessary monomorphizations.
core: drop unmapped ZSTs in array `map` Fixesrust-lang#152211. Alternative to rust-lang#152220 and rust-lang#152248. This makes the `Drain` type use the same ZST-handling strategy as `slice::IterMut`, which stores the remaining length instead of a one-past-the-end pointer when the type is a ZST. I've also removed the const-generic `N` parameter from `Drain` to avoid unnecessary monomorphizations.
joboet
commented
May 7, 2026
I do prefer my own approach in #152487 so I'm going to close this PR. But thank you for your work regardless! |
core: drop unmapped ZSTs in array `map` Fixesrust-lang#152211. Alternative to rust-lang#152220 and rust-lang#152248. This makes the `Drain` type use the same ZST-handling strategy as `slice::IterMut`, which stores the remaining length instead of a one-past-the-end pointer when the type is a ZST. I've also removed the const-generic `N` parameter from `Drain` to avoid unnecessary monomorphizations.
core: drop unmapped ZSTs in array `map` Fixesrust-lang#152211. Alternative to rust-lang#152220 and rust-lang#152248. This makes the `Drain` type use the same ZST-handling strategy as `slice::IterMut`, which stores the remaining length instead of a one-past-the-end pointer when the type is a ZST. I've also removed the const-generic `N` parameter from `Drain` to avoid unnecessary monomorphizations.
Rollup merge of #152487 - joboet:array_map_zst, r=oli-obk core: drop unmapped ZSTs in array `map` Fixes#152211. Alternative to #152220 and #152248. This makes the `Drain` type use the same ZST-handling strategy as `slice::IterMut`, which stores the remaining length instead of a one-past-the-end pointer when the type is a ZST. I've also removed the const-generic `N` parameter from `Drain` to avoid unnecessary monomorphizations.
core: drop unmapped ZSTs in array `map` Fixesrust-lang/rust#152211. Alternative to rust-lang/rust#152220 and rust-lang/rust#152248. This makes the `Drain` type use the same ZST-handling strategy as `slice::IterMut`, which stores the remaining length instead of a one-past-the-end pointer when the type is a ZST. I've also removed the const-generic `N` parameter from `Drain` to avoid unnecessary monomorphizations.
Fixes#152211
Previously, the Drain::drop implementation would skip dropping zero-sized types entirely, causing Drop implementations on ZSTs to never run when a closure panicked or exited early.
This fix adds a zst_processed counter to track how many ZST elements have been processed, ensuring that remaining unprocessed ZSTs are properly dropped when the Drain is dropped.
For ZSTs, conjure_zst() creates new values rather than moving from the array, so all N original elements remain and must be accounted for.