Skip to content

Commit 0f77acc

Browse files
committed
Allow unsizing pattern types with pointer base
1 parent 030ec9a commit 0f77acc

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

core/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@
116116
#![feature(link_cfg)]
117117
#![feature(offset_of_enum)]
118118
#![feature(panic_internals)]
119+
#![feature(pattern_type_macro)]
119120
#![feature(ptr_alignment_type)]
120121
#![feature(ptr_metadata)]
121122
#![feature(set_ptr_value)]
@@ -171,6 +172,7 @@
171172
#![feature(never_type)]
172173
#![feature(no_core)]
173174
#![feature(optimize_attribute)]
175+
#![feature(pattern_types)]
174176
#![feature(prelude_import)]
175177
#![feature(reborrow)]
176178
#![feature(repr_simd)]

core/src/pat.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
//! Helper module for exporting the `pattern_type` macro
22
3+
use crate::marker::{Freeze, PointeeSized, Unsize};
4+
use crate::ops::{CoerceUnsized, DispatchFromDyn};
5+
36
/// Creates a pattern type.
47
/// ```ignore (cannot test this from within core yet)
58
/// type Positive = std::pat::pattern_type!(i32 is 1..);
@@ -73,3 +76,16 @@ impl const RangePattern for char {
7376
}
7477
}
7578
}
79+
80+
impl<T: PointeeSized, U: PointeeSized> CoerceUnsized<pattern_type!(*const U is !null)> for pattern_type!(*const T is !null) where
81+
T: Unsize<U>
82+
{
83+
}
84+
85+
impl<T: DispatchFromDyn<U>, U> DispatchFromDyn<pattern_type!(U is !null)> for pattern_type!(T is !null) {}
86+
87+
impl<T: PointeeSized> Unpin for pattern_type!(*const T is !null) {}
88+
89+
unsafe impl<T: PointeeSized> Freeze for pattern_type!(*const T is !null) {}
90+
91+
unsafe impl<T: PointeeSized> Freeze for pattern_type!(*mut T is !null) {}

0 commit comments

Comments
 (0)