about summary refs log tree commit diff
diff options
context:
space:
mode:
authorYuki Okushi <jtitor@2k36.org>2022-06-17 07:16:55 +0900
committerGitHub <noreply@github.com>2022-06-17 07:16:55 +0900
commit449b309f2ba2d1293e1473ed2489f65e778c4358 (patch)
tree3bd4a5963981311b0b89e302cc0a5c528e861895
parent9096b3e44f6261791e79af851172eebf89a0c2cc (diff)
parenteb5f23737bb8fd70f52b4359c9b6acd81f3d7909 (diff)
downloadrust-449b309f2ba2d1293e1473ed2489f65e778c4358.tar.gz
rust-449b309f2ba2d1293e1473ed2489f65e778c4358.zip
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.
-rw-r--r--example/mini_core.rs2
-rw-r--r--example/mini_core_hello_world.rs7
2 files changed, 8 insertions, 1 deletions
diff --git a/example/mini_core.rs b/example/mini_core.rs
index 8da705e0cb0..489259d1a6b 100644
--- a/example/mini_core.rs
+++ b/example/mini_core.rs
@@ -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);
diff --git a/example/mini_core_hello_world.rs b/example/mini_core_hello_world.rs
index 85ca908d0a2..0f1245c2758 100644
--- a/example/mini_core_hello_world.rs
+++ b/example/mini_core_hello_world.rs
@@ -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),