Skip to content

Commit 20dca62

Browse files
authored
Rollup merge of #142339 - oli-obk:not-null-pattern-types, r=BoxyUwU
Add NonNull pattern types These are the final piece missing for * rust-lang/rust#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 45c17e4 + c4ff3c4 commit 20dca62

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

tests/pass/pattern-types.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#![feature(pattern_types, pattern_type_macro, sized_hierarchy)]
2+
#![allow(dead_code)]
3+
4+
use std::marker::PointeeSized;
5+
use std::mem::transmute;
6+
7+
pub struct NonNull<T: PointeeSized> {
8+
pointer: std::pat::pattern_type!(*const T is !null),
9+
}
10+
11+
trait Trait {}
12+
impl Trait for () {}
13+
14+
fn main() {
15+
unsafe {
16+
let _: NonNull<dyn Trait> = NonNull { pointer: transmute(&mut () as *mut dyn Trait) };
17+
}
18+
}

0 commit comments

Comments
 (0)