about summary refs log tree commit diff
path: root/example
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
commite4b0d3aff2451316d9650ce2e66557cfb75a5071 (patch)
tree94093ab942722c0b870b5c0f495c61f1814cf73a /example
parent0acd23c1da0a954fa177c195d89db98204bf4867 (diff)
parent1d3037a107dc30e3e7c299eb939c60b7340d97ba (diff)
downloadrust-e4b0d3aff2451316d9650ce2e66557cfb75a5071.tar.gz
rust-e4b0d3aff2451316d9650ce2e66557cfb75a5071.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.
Diffstat (limited to 'example')
-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 a8435287d9f..ddcbb0d9fc7 100644
--- a/example/mini_core.rs
+++ b/example/mini_core.rs
@@ -514,7 +514,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 69d591565ac..14fd9eeffa6 100644
--- a/example/mini_core_hello_world.rs
+++ b/example/mini_core_hello_world.rs
@@ -47,6 +47,11 @@ struct NoisyDrop {
     inner: NoisyDropInner,
 }
 
+struct NoisyDropUnsized {
+    inner: NoisyDropInner,
+    text: str,
+}
+
 struct NoisyDropInner;
 
 impl Drop for NoisyDrop {
@@ -184,7 +189,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: 0 as *const &str,