Skip to content

Commit b5695c3

Browse files
authored
Rollup merge of rust-lang#142339 - oli-obk:not-null-pattern-types, r=BoxyUwU
Add NonNull pattern types These are the final piece missing for * rust-lang#136006 We cannot use the previous scheme of using an integer range for raw pointers, as we're not just changing the layout of raw pointers anymore, but also the type representation. And we can't represent "any provenance or NonZero<usize>" natively as patterns. So I created a new `!null` pattern. Since this is all unstable representation stuff for replacing rustc_layout_scalar_range_start with pattern types, the divergence from normal patterns is fine, especially since T-lang seems interested in exploring general negation patterns r? `@BoxyUwU`
2 parents cafda41 + 0f77acc commit b5695c3

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)