From b96e459e7157d2466ed3ea8373ee9fa90a5f2ecb Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Wed, 18 Sep 2024 11:41:29 +0200 Subject: [PATCH] Don't eval constants eagerly --- frontend/exporter/src/types/copied.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/frontend/exporter/src/types/copied.rs b/frontend/exporter/src/types/copied.rs index 2fcb8f874..69944cd61 100644 --- a/frontend/exporter/src/types/copied.rs +++ b/frontend/exporter/src/types/copied.rs @@ -225,7 +225,7 @@ impl<'tcx, S: UnderOwnerState<'tcx>> SInto for rustc_middle::mi fn sinto(&self, s: &S) -> ConstantExpr { use rustc_middle::mir::Const; let tcx = s.base().tcx; - match self.eval_constant(s).as_ref().unwrap_or(self) { + match self { Const::Val(const_value, ty) => const_value_to_constant_expr( s, ty.clone(), @@ -239,7 +239,11 @@ impl<'tcx, S: UnderOwnerState<'tcx>> SInto for rustc_middle::mi .def_ident_span(ucv.def) .unwrap_or_else(|| ucv.def.default_span(tcx)); if let Some(_) = ucv.promoted { - supposely_unreachable_fatal!(s[span], "PromotedConstant"; {ucv.def}) + self.eval_constant(s) + .unwrap_or_else(|| { + supposely_unreachable_fatal!(s, "UnevalPromotedConstant"; {self, ucv}); + }) + .sinto(s) } else { match self.translate_uneval(s, ucv.shrink(), span) { TranslateUnevalRes::EvaluatedConstant(c) => c.sinto(s),