Skip to content

Commit a0ae32d

Browse files
authored
Rollup merge of #130990 - RalfJung:mir-const-normalize, r=compiler-errors
try to get rid of mir::Const::normalize It was easy to make this compile, let's see if anything breaks... r? `@compiler-errors`
2 parents a061e56 + 7eedb68 commit a0ae32d

File tree

5 files changed

+14
-39
lines changed

5 files changed

+14
-39
lines changed

compiler/rustc_middle/src/mir/consts.rs

+3-13
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,9 @@ pub enum Const<'tcx> {
221221
}
222222

223223
impl<'tcx> Const<'tcx> {
224-
pub fn identity_unevaluated(
224+
/// Creates an unevaluated const from a `DefId` for a const item.
225+
/// The binders of the const item still need to be instantiated.
226+
pub fn from_unevaluated(
225227
tcx: TyCtxt<'tcx>,
226228
def_id: DefId,
227229
) -> ty::EarlyBinder<'tcx, Const<'tcx>> {
@@ -329,18 +331,6 @@ impl<'tcx> Const<'tcx> {
329331
}
330332
}
331333

332-
/// Normalizes the constant to a value or an error if possible.
333-
#[inline]
334-
pub fn normalize(self, tcx: TyCtxt<'tcx>, param_env: ty::ParamEnv<'tcx>) -> Self {
335-
match self.eval(tcx, param_env, DUMMY_SP) {
336-
Ok(val) => Self::Val(val, self.ty()),
337-
Err(ErrorHandled::Reported(guar, _span)) => {
338-
Self::Ty(Ty::new_error(tcx, guar.into()), ty::Const::new_error(tcx, guar.into()))
339-
}
340-
Err(ErrorHandled::TooGeneric(_span)) => self,
341-
}
342-
}
343-
344334
#[inline]
345335
pub fn try_eval_scalar(
346336
self,

compiler/rustc_mir_build/src/thir/cx/expr.rs

+6-12
Original file line numberDiff line numberDiff line change
@@ -699,23 +699,17 @@ impl<'tcx> Cx<'tcx> {
699699
}
700700
}
701701
hir::InlineAsmOperand::Const { ref anon_const } => {
702-
let value = mir::Const::identity_unevaluated(
703-
tcx,
704-
anon_const.def_id.to_def_id(),
705-
)
706-
.instantiate_identity()
707-
.normalize(tcx, self.param_env);
702+
let value =
703+
mir::Const::from_unevaluated(tcx, anon_const.def_id.to_def_id())
704+
.instantiate_identity();
708705
let span = tcx.def_span(anon_const.def_id);
709706

710707
InlineAsmOperand::Const { value, span }
711708
}
712709
hir::InlineAsmOperand::SymFn { ref anon_const } => {
713-
let value = mir::Const::identity_unevaluated(
714-
tcx,
715-
anon_const.def_id.to_def_id(),
716-
)
717-
.instantiate_identity()
718-
.normalize(tcx, self.param_env);
710+
let value =
711+
mir::Const::from_unevaluated(tcx, anon_const.def_id.to_def_id())
712+
.instantiate_identity();
719713
let span = tcx.def_span(anon_const.def_id);
720714

721715
InlineAsmOperand::SymFn { value, span }

compiler/rustc_mir_transform/src/jump_threading.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -516,9 +516,7 @@ impl<'a, 'tcx> TOFinder<'a, 'tcx> {
516516
// Avoid handling them, though this could be extended in the future.
517517
return;
518518
}
519-
let Some(value) =
520-
value.const_.normalize(self.tcx, self.param_env).try_to_scalar_int()
521-
else {
519+
let Some(value) = value.const_.try_eval_scalar_int(self.tcx, self.param_env) else {
522520
return;
523521
};
524522
let conds = conditions.map(self.arena, |c| Condition {

tests/ui/asm/const-error.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
//@ only-x86_64
22
//@ needs-asm-support
3+
//@ check-pass
34

4-
// Test to make sure that we emit const errors eagerly for inline asm
5+
// Test to make sure that we emit const errors late for inline asm,
6+
// which is consistent with inline const blocks.
57

68
use std::arch::asm;
79

810
fn test<T>() {
911
unsafe {
12+
// No error here, as this does not get monomorphized.
1013
asm!("/* {} */", const 1 / 0);
11-
//~^ ERROR evaluation of
1214
}
1315
}
1416

tests/ui/asm/const-error.stderr

-9
This file was deleted.

0 commit comments

Comments
 (0)