Skip to content

Commit d9865d7

Browse files
committed
Test validity of pattern types
1 parent 633a3fe commit d9865d7

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//! Check that pattern types have their validity checked
2+
3+
#![feature(pattern_types)]
4+
#![feature(pattern_type_macro)]
5+
6+
use std::pat::pattern_type;
7+
8+
const BAD: pattern_type!(u32 is 1..) = unsafe { std::mem::transmute(0) };
9+
//~^ ERROR: it is undefined behavior to use this value
10+
11+
const BAD_AGGREGATE: (pattern_type!(u32 is 1..), u32) = (unsafe { std::mem::transmute(0) }, 0);
12+
//~^ ERROR: it is undefined behavior to use this value
13+
14+
struct Foo(Bar);
15+
struct Bar(pattern_type!(u32 is 1..));
16+
17+
const BAD_FOO: Foo = Foo(Bar(unsafe { std::mem::transmute(0) }));
18+
//~^ ERROR: it is undefined behavior to use this value
19+
20+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
error[E0080]: it is undefined behavior to use this value
2+
--> $DIR/validity.rs:8:1
3+
|
4+
LL | const BAD: pattern_type!(u32 is 1..) = unsafe { std::mem::transmute(0) };
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered 0, but expected something greater or equal to 1
6+
|
7+
= note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior.
8+
= note: the raw bytes of the constant (size: 4, align: 4) {
9+
00 00 00 00 │ ....
10+
}
11+
12+
error[E0080]: it is undefined behavior to use this value
13+
--> $DIR/validity.rs:11:1
14+
|
15+
LL | const BAD_AGGREGATE: (pattern_type!(u32 is 1..), u32) = (unsafe { std::mem::transmute(0) }, 0);
16+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .0: encountered 0, but expected something greater or equal to 1
17+
|
18+
= note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior.
19+
= note: the raw bytes of the constant (size: 8, align: 4) {
20+
00 00 00 00 00 00 00 00 │ ........
21+
}
22+
23+
error[E0080]: it is undefined behavior to use this value
24+
--> $DIR/validity.rs:17:1
25+
|
26+
LL | const BAD_FOO: Foo = Foo(Bar(unsafe { std::mem::transmute(0) }));
27+
| ^^^^^^^^^^^^^^^^^^ constructing invalid value at .0.0: encountered 0, but expected something greater or equal to 1
28+
|
29+
= note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior.
30+
= note: the raw bytes of the constant (size: 4, align: 4) {
31+
00 00 00 00 │ ....
32+
}
33+
34+
error: aborting due to 3 previous errors
35+
36+
For more information about this error, try `rustc --explain E0080`.

0 commit comments

Comments
 (0)