Skip to content

Commit

Permalink
Use evaluate_const
Browse files Browse the repository at this point in the history
  • Loading branch information
nbdd0121 committed Nov 13, 2024
1 parent f1782ca commit e84e929
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
7 changes: 4 additions & 3 deletions src/preempt_count/adjustment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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) {
Expand Down
11 changes: 6 additions & 5 deletions src/preempt_count/expectation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit e84e929

Please sign in to comment.