Skip to content

Commit 449b309

Browse files
authoredJun 16, 2022
Rollup merge of #97675 - nvzqz:unsized-needs-drop, r=dtolnay
Make `std::mem::needs_drop` accept `?Sized` This change attempts to make `needs_drop` work with types like `[u8]` and `str`. This enables code in types like `Arc<T>` that was not possible before, such as rust-lang/rust#97676.
2 parents 9096b3e + eb5f237 commit 449b309

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed
 

‎example/mini_core.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,7 @@ pub mod intrinsics {
567567
pub fn copy<T>(src: *const T, dst: *mut T, count: usize);
568568
pub fn transmute<T, U>(e: T) -> U;
569569
pub fn ctlz_nonzero<T>(x: T) -> T;
570-
pub fn needs_drop<T>() -> bool;
570+
pub fn needs_drop<T: ?::Sized>() -> bool;
571571
pub fn bitreverse<T>(x: T) -> T;
572572
pub fn bswap<T>(x: T) -> T;
573573
pub fn write_bytes<T>(dst: *mut T, val: u8, count: usize);

‎example/mini_core_hello_world.rs

+7
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ struct NoisyDrop {
5555
inner: NoisyDropInner,
5656
}
5757

58+
struct NoisyDropUnsized {
59+
inner: NoisyDropInner,
60+
text: str,
61+
}
62+
5863
struct NoisyDropInner;
5964

6065
impl Drop for NoisyDrop {
@@ -170,7 +175,9 @@ fn main() {
170175
assert_eq!(intrinsics::min_align_of_val(&a) as u8, intrinsics::min_align_of::<&str>() as u8);
171176

172177
assert!(!intrinsics::needs_drop::<u8>());
178+
assert!(!intrinsics::needs_drop::<[u8]>());
173179
assert!(intrinsics::needs_drop::<NoisyDrop>());
180+
assert!(intrinsics::needs_drop::<NoisyDropUnsized>());
174181

175182
Unique {
176183
pointer: NonNull(1 as *mut &str),

0 commit comments

Comments
 (0)