Skip to content

Commit 82545d7

Browse files
committed
Add regression test
1 parent 12f35ad commit 82545d7

2 files changed

Lines changed: 23 additions & 0 deletions

File tree

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
//! After the use of pattern types inside `NonNull`,
2+
//! transmuting between a niche optimized enum wrapping a
3+
//! generic `NonNull` and raw pointers stopped working.
4+
5+
use std::ptr::NonNull;
6+
pub const fn is_null<'a, T: ?Sized>(ptr: *const T) -> bool {
7+
unsafe { matches!(core::mem::transmute::<*const T, Option<NonNull<T>>>(ptr), None) }
8+
//~^ ERROR: cannot transmute
9+
}
10+
11+
fn main() {}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
error[E0512]: cannot transmute between types of different sizes, or dependently-sized types
2+
--> $DIR/raw-ptr-non-null.rs:7:23
3+
|
4+
LL | unsafe { matches!(core::mem::transmute::<*const T, Option<NonNull<T>>>(ptr), None) }
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: source type: `*const T` (pointer to `T`)
8+
= note: target type: `Option<NonNull<T>>` (size can vary because of <T as Pointee>::Metadata)
9+
10+
error: aborting due to 1 previous error
11+
12+
For more information about this error, try `rustc --explain E0512`.

0 commit comments

Comments
 (0)