Move eval_bits optimization upstream

This commit is contained in:
Nadrieril
2023-09-30 23:54:31 +02:00
parent 0a6d794d0b
commit eac7bcde5f
2 changed files with 16 additions and 36 deletions

View File

@@ -288,7 +288,16 @@ impl<'tcx> Const<'tcx> {
tcx: TyCtxt<'tcx>,
param_env: ty::ParamEnv<'tcx>,
) -> Option<ScalarInt> {
self.try_eval_scalar(tcx, param_env)?.try_to_int().ok()
match self {
// If the constant is already evaluated, we shortcut here.
Const::Ty(c) if let ty::ConstKind::Value(valtree) = c.kind() => {
valtree.try_to_scalar_int()
},
// This is a more general form of the previous case.
_ => {
self.try_eval_scalar(tcx, param_env)?.try_to_int().ok()
},
}
}
#[inline]