Skip to content

Commit 22f0741

Browse files
committed
Add tests for transmuting pattern types
1 parent ccc9ba5 commit 22f0741

File tree

2 files changed

+73
-0
lines changed

2 files changed

+73
-0
lines changed
+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#![feature(pattern_types)]
2+
#![feature(pattern_type_macro)]
3+
4+
use std::pat::pattern_type;
5+
6+
// ok
7+
fn create<const S: u32, const E: u32>(x: u32) -> pattern_type!(u32 is S..=E) {
8+
unsafe { std::mem::transmute(x) }
9+
//~^ ERROR types of different sizes
10+
}
11+
12+
// ok
13+
fn unwrap<const S: u32, const E: u32>(x: pattern_type!(u32 is S..=E)) -> u32 {
14+
unsafe { std::mem::transmute(x) }
15+
//~^ ERROR types of different sizes
16+
}
17+
18+
// bad, only when S != u32::MIN or E != u32::MAX will this ok
19+
fn non_base_ty_transmute<const S: u32, const E: u32>(
20+
x: Option<pattern_type!(u32 is S..=E)>,
21+
) -> u32 {
22+
unsafe { std::mem::transmute(x) }
23+
//~^ ERROR types of different sizes
24+
}
25+
26+
// bad, only when S = u32::MIN and E = u32::MAX will this ok
27+
fn wrapped_transmute<const S: u32, const E: u32>(
28+
x: Option<pattern_type!(u32 is S..=E)>,
29+
) -> Option<u32> {
30+
unsafe { std::mem::transmute(x) }
31+
//~^ ERROR types of different sizes
32+
}
33+
34+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
error[E0512]: cannot transmute between types of different sizes, or dependently-sized types
2+
--> $DIR/transmute.rs:8:14
3+
|
4+
LL | unsafe { std::mem::transmute(x) }
5+
| ^^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: source type: `u32` (32 bits)
8+
= note: target type: `(u32) is S..=E` (size can vary because of u32)
9+
10+
error[E0512]: cannot transmute between types of different sizes, or dependently-sized types
11+
--> $DIR/transmute.rs:14:14
12+
|
13+
LL | unsafe { std::mem::transmute(x) }
14+
| ^^^^^^^^^^^^^^^^^^^
15+
|
16+
= note: source type: `(u32) is S..=E` (size can vary because of u32)
17+
= note: target type: `u32` (32 bits)
18+
19+
error[E0512]: cannot transmute between types of different sizes, or dependently-sized types
20+
--> $DIR/transmute.rs:22:14
21+
|
22+
LL | unsafe { std::mem::transmute(x) }
23+
| ^^^^^^^^^^^^^^^^^^^
24+
|
25+
= note: source type: `Option<(u32) is S..=E>` (size can vary because of u32)
26+
= note: target type: `u32` (32 bits)
27+
28+
error[E0512]: cannot transmute between types of different sizes, or dependently-sized types
29+
--> $DIR/transmute.rs:30:14
30+
|
31+
LL | unsafe { std::mem::transmute(x) }
32+
| ^^^^^^^^^^^^^^^^^^^
33+
|
34+
= note: source type: `Option<(u32) is S..=E>` (size can vary because of u32)
35+
= note: target type: `Option<u32>` (64 bits)
36+
37+
error: aborting due to 4 previous errors
38+
39+
For more information about this error, try `rustc --explain E0512`.

0 commit comments

Comments
 (0)