This repository was archived by the owner on May 28, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +14
-5
lines changed
compiler/rustc_mir/src/const_eval Expand file tree Collapse file tree 2 files changed +14
-5
lines changed Original file line number Diff line number Diff line change @@ -14,7 +14,7 @@ use rustc_middle::ty::print::with_no_trimmed_paths;
14
14
use rustc_middle:: ty:: { self , subst:: Subst , TyCtxt } ;
15
15
use rustc_span:: source_map:: Span ;
16
16
use rustc_target:: abi:: { Abi , LayoutOf } ;
17
- use std:: convert:: TryInto ;
17
+ use std:: convert:: { TryFrom , TryInto } ;
18
18
19
19
pub fn note_on_undefined_behavior_error ( ) -> & ' static str {
20
20
"The rules on what exactly is undefined behavior aren't clear, \
@@ -148,10 +148,10 @@ pub(super) fn op_to_const<'tcx>(
148
148
Scalar :: Raw { data, .. } => {
149
149
assert ! ( mplace. layout. is_zst( ) ) ;
150
150
assert_eq ! (
151
- data,
152
- mplace . layout . align . abi . bytes ( ) . into ( ) ,
153
- "this MPlaceTy must come from `try_as_mplace` being used on a zst, so we know what
154
- value this integer address must have " ,
151
+ u64 :: try_from ( data) . unwrap ( ) % mplace . layout . align . abi . bytes ( ) ,
152
+ 0 ,
153
+ "this MPlaceTy must come from a validated constant, thus we can assume the \
154
+ alignment is correct ",
155
155
) ;
156
156
ConstValue :: Scalar ( Scalar :: zst ( ) )
157
157
}
Original file line number Diff line number Diff line change
1
+ // check-pass
2
+
3
+ const FOO : isize = 10 ;
4
+ const ZST : & ( ) = unsafe { std:: mem:: transmute ( FOO ) } ;
5
+ fn main ( ) {
6
+ match & ( ) {
7
+ ZST => 9 ,
8
+ } ;
9
+ }
You can’t perform that action at this time.
0 commit comments