Skip to content

Commit e4b0d3a

Browse files
authored
Rollup merge of rust-lang#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#97676.
2 parents 0acd23c + 1d3037a commit e4b0d3a

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

example/mini_core.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,7 @@ pub mod intrinsics {
514514
pub fn copy<T>(src: *const T, dst: *mut T, count: usize);
515515
pub fn transmute<T, U>(e: T) -> U;
516516
pub fn ctlz_nonzero<T>(x: T) -> T;
517-
pub fn needs_drop<T>() -> bool;
517+
pub fn needs_drop<T: ?::Sized>() -> bool;
518518
pub fn bitreverse<T>(x: T) -> T;
519519
pub fn bswap<T>(x: T) -> T;
520520
pub fn write_bytes<T>(dst: *mut T, val: u8, count: usize);

example/mini_core_hello_world.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ struct NoisyDrop {
4747
inner: NoisyDropInner,
4848
}
4949

50+
struct NoisyDropUnsized {
51+
inner: NoisyDropInner,
52+
text: str,
53+
}
54+
5055
struct NoisyDropInner;
5156

5257
impl Drop for NoisyDrop {
@@ -184,7 +189,9 @@ fn main() {
184189
assert_eq!(intrinsics::min_align_of_val(&a) as u8, intrinsics::min_align_of::<&str>() as u8);
185190

186191
assert!(!intrinsics::needs_drop::<u8>());
192+
assert!(!intrinsics::needs_drop::<[u8]>());
187193
assert!(intrinsics::needs_drop::<NoisyDrop>());
194+
assert!(intrinsics::needs_drop::<NoisyDropUnsized>());
188195

189196
Unique {
190197
pointer: 0 as *const &str,

0 commit comments

Comments
 (0)