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;
1414use rustc_middle:: ty:: { self , subst:: Subst , TyCtxt } ;
1515use rustc_span:: source_map:: Span ;
1616use rustc_target:: abi:: { Abi , LayoutOf } ;
17- use std:: convert:: TryInto ;
17+ use std:: convert:: { TryFrom , TryInto } ;
1818
1919pub fn note_on_undefined_behavior_error ( ) -> & ' static str {
2020 "The rules on what exactly is undefined behavior aren't clear, \
@@ -148,10 +148,10 @@ pub(super) fn op_to_const<'tcx>(
148148 Scalar :: Raw { data, .. } => {
149149 assert ! ( mplace. layout. is_zst( ) ) ;
150150 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 ",
155155 ) ;
156156 ConstValue :: Scalar ( Scalar :: zst ( ) )
157157 }
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