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 https://github.com/rust-lang/rust/pull/97676.
This commit is contained in:
Yuki Okushi 2022-06-17 07:16:55 +09:00 committed by GitHub
commit 449b309f2b
2 changed files with 8 additions and 1 deletions

View File

@ -567,7 +567,7 @@ pub mod intrinsics {
pub fn copy<T>(src: *const T, dst: *mut T, count: usize);
pub fn transmute<T, U>(e: T) -> U;
pub fn ctlz_nonzero<T>(x: T) -> T;
pub fn needs_drop<T>() -> bool;
pub fn needs_drop<T: ?::Sized>() -> bool;
pub fn bitreverse<T>(x: T) -> T;
pub fn bswap<T>(x: T) -> T;
pub fn write_bytes<T>(dst: *mut T, val: u8, count: usize);

View File

@ -55,6 +55,11 @@ struct NoisyDrop {
inner: NoisyDropInner,
}
struct NoisyDropUnsized {
inner: NoisyDropInner,
text: str,
}
struct NoisyDropInner;
impl Drop for NoisyDrop {
@ -170,7 +175,9 @@ fn main() {
assert_eq!(intrinsics::min_align_of_val(&a) as u8, intrinsics::min_align_of::<&str>() as u8);
assert!(!intrinsics::needs_drop::<u8>());
assert!(!intrinsics::needs_drop::<[u8]>());
assert!(intrinsics::needs_drop::<NoisyDrop>());
assert!(intrinsics::needs_drop::<NoisyDropUnsized>());
Unique {
pointer: NonNull(1 as *mut &str),