File tree 2 files changed +35
-0
lines changed
src/test/ui/consts/const-eval
2 files changed +35
-0
lines changed Original file line number Diff line number Diff line change
1
+ // issue-49296: Unsafe shenigans in constants can result in missing errors
2
+
3
+ #![ feature( const_fn) ]
4
+ #![ feature( const_fn_union) ]
5
+
6
+ const unsafe fn transmute < T : Copy , U : Copy > ( t : T ) -> U {
7
+ union Transmute < T : Copy , U : Copy > {
8
+ from : T ,
9
+ to : U ,
10
+ }
11
+
12
+ Transmute { from : t } . to
13
+ }
14
+
15
+ const fn wat ( x : u64 ) -> & ' static u64 {
16
+ unsafe { transmute ( & x) }
17
+ }
18
+ const X : u64 = * wat ( 42 ) ;
19
+ //~^ ERROR any use of this value will cause an error
20
+
21
+ fn main ( ) {
22
+ println ! ( "{}" , X ) ;
23
+ }
Original file line number Diff line number Diff line change
1
+ error: any use of this value will cause an error
2
+ --> $DIR/issue-49296.rs:18:1
3
+ |
4
+ LL | const X: u64 = *wat(42);
5
+ | ^^^^^^^^^^^^^^^--------^
6
+ | |
7
+ | dangling pointer was dereferenced
8
+ |
9
+ = note: #[deny(const_err)] on by default
10
+
11
+ error: aborting due to previous error
12
+
You can’t perform that action at this time.
0 commit comments