From e84e929f718e3dbc6412386ec2d3fa0c12a5c0ee Mon Sep 17 00:00:00 2001 From: Gary Guo Date: Wed, 13 Nov 2024 15:09:52 +0000 Subject: [PATCH] Use evaluate_const --- src/preempt_count/adjustment.rs | 7 ++++--- src/preempt_count/expectation.rs | 11 ++++++----- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/preempt_count/adjustment.rs b/src/preempt_count/adjustment.rs index 71c1c2f..d539871 100644 --- a/src/preempt_count/adjustment.rs +++ b/src/preempt_count/adjustment.rs @@ -6,9 +6,10 @@ use rustc_errors::{Diag, EmissionGuarantee, ErrorGuaranteed, MultiSpan}; use rustc_hir::def_id::{CrateNum, DefId}; use rustc_hir::LangItem; use rustc_middle::mir::{Body, TerminatorKind, UnwindAction}; -use rustc_middle::ty::{self, GenericArgs, Instance, ParamEnv, ParamEnvAnd, Ty}; +use rustc_middle::ty::{self, GenericArgs, Instance, ParamEnv, ParamEnvAnd, Ty, TypingMode}; use rustc_mir_dataflow::Analysis; use rustc_mir_dataflow::JoinSemiLattice; +use rustc_trait_selection::infer::TyCtxtInferExt; use super::dataflow::{AdjustmentBoundsOrError, AdjustmentComputation}; use super::{Error, PolyDisplay, UseSiteKind}; @@ -423,8 +424,8 @@ memoize!( } ty::Array(elem_ty, size) => { - let size = size - .normalize_internal(cx.tcx, param_env) + let infcx = cx.tcx.infer_ctxt().build(TypingMode::PostAnalysis); + let size = rustc_trait_selection::traits::evaluate_const(&infcx, *size, param_env) .try_to_target_usize(cx.tcx) .ok_or(Error::TooGeneric); if size == Ok(0) { diff --git a/src/preempt_count/expectation.rs b/src/preempt_count/expectation.rs index 8bbb2dc..d238055 100644 --- a/src/preempt_count/expectation.rs +++ b/src/preempt_count/expectation.rs @@ -6,10 +6,11 @@ use rustc_errors::{EmissionGuarantee, MultiSpan}; use rustc_hir::def_id::CrateNum; use rustc_hir::LangItem; use rustc_middle::mir::{self, Body, TerminatorKind}; -use rustc_middle::ty::{self, GenericArgs, Instance, ParamEnv, ParamEnvAnd, Ty}; +use rustc_middle::ty::{self, GenericArgs, Instance, ParamEnv, ParamEnvAnd, Ty, TypingMode}; use rustc_mir_dataflow::lattice::MeetSemiLattice; use rustc_mir_dataflow::Analysis; use rustc_span::DUMMY_SP; +use rustc_trait_selection::infer::TyCtxtInferExt; use super::dataflow::AdjustmentComputation; use super::{AdjustmentBounds, Error, ExpectationRange, PolyDisplay, UseSite, UseSiteKind}; @@ -423,8 +424,8 @@ impl<'tcx> AnalysisCtxt<'tcx> { } let elem_adj = self.drop_adjustment(param_and_elem_ty)?; - let size = size - .normalize_internal(self.tcx, param_env) + let infcx = self.tcx.infer_ctxt().build(TypingMode::PostAnalysis); + let size = rustc_trait_selection::traits::evaluate_const(&infcx, *size, param_env) .try_to_target_usize(self.tcx) .ok_or(Error::TooGeneric)?; let Ok(size) = i32::try_from(size) else { @@ -741,8 +742,8 @@ memoize!( } ty::Array(elem_ty, size) => { - let size = size - .normalize_internal(cx.tcx, param_env) + let infcx = cx.tcx.infer_ctxt().build(TypingMode::PostAnalysis); + let size = rustc_trait_selection::traits::evaluate_const(&infcx, *size, param_env) .try_to_target_usize(cx.tcx) .ok_or(Error::TooGeneric); if size == Ok(0) {