-
-
Notifications
You must be signed in to change notification settings - Fork 14.7k
array::map and array::try_map do not drop ZSTs properly #152211
Copy link
Copy link
Open
Labels
A-ZSTArea: Zero-sized types (ZSTs).Area: Zero-sized types (ZSTs).A-arrayArea: `[T; N]`Area: `[T; N]`A-collectionsArea: `std::collections`Area: `std::collections`A-destructorsArea: Destructors (`Drop`, …)Area: Destructors (`Drop`, …)A-panicArea: Panicking machineryArea: Panicking machineryC-bugCategory: This is a bug.Category: This is a bug.T-libsRelevant to the library team, which will review and decide on the PR/issue.Relevant to the library team, which will review and decide on the PR/issue.
Metadata
Metadata
Assignees
Labels
A-ZSTArea: Zero-sized types (ZSTs).Area: Zero-sized types (ZSTs).A-arrayArea: `[T; N]`Area: `[T; N]`A-collectionsArea: `std::collections`Area: `std::collections`A-destructorsArea: Destructors (`Drop`, …)Area: Destructors (`Drop`, …)A-panicArea: Panicking machineryArea: Panicking machineryC-bugCategory: This is a bug.Category: This is a bug.T-libsRelevant to the library team, which will review and decide on the PR/issue.Relevant to the library team, which will review and decide on the PR/issue.
Type
Fields
Give feedbackNo fields configured for issues without a type.
array::mapandarray::try_mapdo not drop ZST elements properly if the closure panics.Additionally,
array::try_mapdoes not drop ZST elements properly if the closure "exits the loop" early.In both cases, the elements that the closure didn't get to are never dropped at all.
Panicking in array::map
Panicking in array::try_map
Early exit in array::try_map
Relevant code:
rust/library/core/src/array/drain.rs
Lines 92 to 108 in a3ceeeb
Meta
Reproducible on the playground with version
1.95.0-nightly (2026-02-05 f889772d6500faebcac5)