Skip to content

Commit 5a06b1e

Browse files
RalfJungoli-obk
authored andcommitted
simplify alignment_check_failed a bit
1 parent 2b21703 commit 5a06b1e

File tree

1 file changed

+5
-14
lines changed
  • compiler/rustc_const_eval/src/const_eval

1 file changed

+5
-14
lines changed

compiler/rustc_const_eval/src/const_eval/machine.rs

+5-14
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use rustc_hir::def::DefKind;
22
use rustc_hir::{LangItem, CRATE_HIR_ID};
33
use rustc_middle::mir;
4-
use rustc_middle::mir::interpret::{InterpError, PointerArithmetic, UndefinedBehaviorInfo};
4+
use rustc_middle::mir::interpret::PointerArithmetic;
55
use rustc_middle::ty::layout::FnAbiOf;
66
use rustc_middle::ty::{self, Ty, TyCtxt};
77
use rustc_session::lint::builtin::INVALID_ALIGNMENT;
@@ -345,24 +345,15 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir,
345345
required: Align,
346346
check: CheckAlignment,
347347
) -> InterpResult<'tcx, ()> {
348+
let err = err_ub!(AlignmentCheckFailed { has, required }).into();
348349
match check {
349-
CheckAlignment::Error => {
350-
throw_ub!(AlignmentCheckFailed { has, required })
351-
}
350+
CheckAlignment::Error => Err(err),
352351
CheckAlignment::No => span_bug!(
353352
ecx.cur_span(),
354353
"`alignment_check_failed` called when no alignment check requested"
355354
),
356355
CheckAlignment::FutureIncompat => {
357-
let err = ConstEvalErr::new(
358-
ecx,
359-
InterpError::UndefinedBehavior(UndefinedBehaviorInfo::AlignmentCheckFailed {
360-
has,
361-
required,
362-
})
363-
.into(),
364-
None,
365-
);
356+
let err = ConstEvalErr::new(ecx, err, None);
366357
ecx.tcx.struct_span_lint_hir(
367358
INVALID_ALIGNMENT,
368359
ecx.stack().iter().find_map(|frame| frame.lint_root()).unwrap_or(CRATE_HIR_ID),
@@ -373,9 +364,9 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir,
373364
db
374365
},
375366
);
367+
Ok(())
376368
}
377369
}
378-
Ok(())
379370
}
380371

381372
fn load_mir(

0 commit comments

Comments
 (0)