zeroize: support unsized types in Zeroizing#1318
Merged
Merged
Conversation
6a5c7cc to
c20be21
Compare
This commit adds ?Sized to the generic bounds on Zeroizing and many of its trait implementations. This makes it possible to form and use types like `Zeroizing<Box<[u8]>>` and `Zeroizing<Arc<[u8]>>`.
c20be21 to
e8007cb
Compare
ssanderson
commented
Dec 30, 2025
| // This is a weird way to use zeroizing, but it's technically allowed b/c | ||
| // unsized types can be stored inside Zeroizing, so make sure it works as | ||
| // expected. | ||
| #[test] |
Contributor
Author
There was a problem hiding this comment.
I think this is missing a feature = "alloc" guard since it uses Box, but it seems like the build is still passing. Are these guards actually required?
Member
There was a problem hiding this comment.
Since these tests are in tests/ they're in their own toplevel crate which links alloc and std by default.
You only need to gate alloc if it's using alloc-dependent functionality inside Zeroize. Since this is Box<Zeroizing<[u8]>> and not Zeroizing<Box<[u8]>> (which would need the Zeroize impl on Box) you're not actually dependent on zeroize having its alloc feature enabled.
Member
|
Going to go ahead and merge this. I might revisit the feature-gating myself. |
Merged
tarcieri
added a commit
that referenced
this pull request
Jun 12, 2026
## Added - `Zeroizing` is now `repr(transparent)` ([#1253]) - `optimization_barrier` function ([#1261]) - `Zeroizing` now supports `?Sized` ([#1318]) - `zeroize_stack` function ([#1331]) ## Changed - Edition changed to 2024 and MSRV bumped to 1.85 ([#1149]) - Replace `atomic_fence` with `optimization_barrier` ([#1252]) - Bump `zeroize_derive` to v1.5 ([#1492]) - Always enable AVX-512 support ([#1493]) [#1149]: #1149 [#1252]: #1252 [#1253]: #1253 [#1261]: #1261 [#1318]: #1318 [#1331]: #1331 [#1492]: #1492 [#1493]: #1493
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This commit adds
?Sizedto the generic bounds on Zeroizing and many of its trait implementations. This makes it possible to form and use types likeZeroizing<Box<[u8]>>andZeroizing<Arc<[u8]>>.This also allows forming more exotic types like
Zeroizing<dyn SomeTrait>whereSomeTrait: Zeroize. I've included a test for that case to ensure that nothing unexpected breaks if it's used in that way, but that usage is probably not to be recommended.See #1256 for more details.