@@ -14,11 +14,8 @@ use std::ptr;
1414
1515use rustc_ast:: Mutability ;
1616use rustc_data_structures:: fx:: { FxHashMap , FxHashSet } ;
17- use rustc_hir:: CRATE_HIR_ID ;
1817use rustc_middle:: mir:: display_allocation;
19- use rustc_middle:: mir:: interpret:: UndefinedBehaviorInfo ;
2018use rustc_middle:: ty:: { self , Instance , ParamEnv , Ty , TyCtxt } ;
21- use rustc_session:: lint:: builtin:: INVALID_ALIGNMENT ;
2219use rustc_target:: abi:: { Align , HasDataLayout , Size } ;
2320
2421use crate :: const_eval:: CheckAlignment ;
@@ -448,7 +445,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
448445 } else {
449446 // Check allocation alignment and offset alignment.
450447 if alloc_align. bytes ( ) < align. bytes ( ) {
451- self . alignment_check_failed ( alloc_align, align, check) ?;
448+ M :: alignment_check_failed ( self , alloc_align, align, check) ?;
452449 }
453450 self . check_offset_align ( offset. bytes ( ) , align, check) ?;
454451 }
@@ -472,43 +469,9 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
472469 } else {
473470 // The biggest power of two through which `offset` is divisible.
474471 let offset_pow2 = 1 << offset. trailing_zeros ( ) ;
475- self . alignment_check_failed ( Align :: from_bytes ( offset_pow2) . unwrap ( ) , align, check)
472+ M :: alignment_check_failed ( self , Align :: from_bytes ( offset_pow2) . unwrap ( ) , align, check)
476473 }
477474 }
478-
479- fn alignment_check_failed (
480- & self ,
481- has : Align ,
482- required : Align ,
483- check : CheckAlignment ,
484- ) -> InterpResult < ' tcx , ( ) > {
485- match check {
486- CheckAlignment :: Error => {
487- throw_ub ! ( AlignmentCheckFailed { has, required } )
488- }
489- CheckAlignment :: No => span_bug ! (
490- self . cur_span( ) ,
491- "`alignment_check_failed` called when no alignment check requested"
492- ) ,
493- CheckAlignment :: FutureIncompat => self . tcx . struct_span_lint_hir (
494- INVALID_ALIGNMENT ,
495- self . stack ( ) . iter ( ) . find_map ( |frame| frame. lint_root ( ) ) . unwrap_or ( CRATE_HIR_ID ) ,
496- self . cur_span ( ) ,
497- UndefinedBehaviorInfo :: AlignmentCheckFailed { has, required } . to_string ( ) ,
498- |db| {
499- let mut stacktrace = self . generate_stacktrace ( ) ;
500- // Filter out `requires_caller_location` frames.
501- stacktrace
502- . retain ( |frame| !frame. instance . def . requires_caller_location ( * self . tcx ) ) ;
503- for frame in stacktrace {
504- db. span_label ( frame. span , format ! ( "inside `{}`" , frame. instance) ) ;
505- }
506- db
507- } ,
508- ) ,
509- }
510- Ok ( ( ) )
511- }
512475}
513476
514477/// Allocation accessors
0 commit comments