Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/hir-ty/src/infer/coerce.rs')
| -rw-r--r-- | crates/hir-ty/src/infer/coerce.rs | 49 |
1 files changed, 22 insertions, 27 deletions
diff --git a/crates/hir-ty/src/infer/coerce.rs b/crates/hir-ty/src/infer/coerce.rs index df24148920..77c7155550 100644 --- a/crates/hir-ty/src/infer/coerce.rs +++ b/crates/hir-ty/src/infer/coerce.rs @@ -50,10 +50,9 @@ use rustc_type_ir::{ }; use smallvec::{SmallVec, smallvec}; use tracing::{debug, instrument}; -use triomphe::Arc; use crate::{ - Adjust, Adjustment, AutoBorrow, PointerCast, TargetFeatures, TraitEnvironment, + Adjust, Adjustment, AutoBorrow, ParamEnvAndCrate, PointerCast, TargetFeatures, autoderef::Autoderef, db::{HirDatabase, InternedClosureId}, infer::{ @@ -62,7 +61,7 @@ use crate::{ next_solver::{ Binder, BoundConst, BoundRegion, BoundRegionKind, BoundTy, BoundTyKind, CallableIdWrapper, Canonical, ClauseKind, CoercePredicate, Const, ConstKind, DbInterner, ErrorGuaranteed, - GenericArgs, PolyFnSig, PredicateKind, Region, RegionKind, TraitRef, Ty, TyKind, + GenericArgs, ParamEnv, PolyFnSig, PredicateKind, Region, RegionKind, TraitRef, Ty, TyKind, TypingMode, infer::{ DbInternerInferExt, InferCtxt, InferOk, InferResult, @@ -77,7 +76,7 @@ use crate::{ trait CoerceDelegate<'db> { fn infcx(&self) -> &InferCtxt<'db>; - fn env(&self) -> &TraitEnvironment<'db>; + fn param_env(&self) -> ParamEnv<'db>; fn target_features(&self) -> (&TargetFeatures<'db>, TargetFeatureIsSafeInTarget); fn set_diverging(&mut self, diverging_ty: Ty<'db>); @@ -137,8 +136,8 @@ where } #[inline] - fn env(&self) -> &TraitEnvironment<'db> { - self.delegate.env() + fn param_env(&self) -> ParamEnv<'db> { + self.delegate.param_env() } #[inline] @@ -169,7 +168,7 @@ where fn unify_raw(&self, a: Ty<'db>, b: Ty<'db>) -> InferResult<'db, Ty<'db>> { debug!("unify(a: {:?}, b: {:?}, use_lub: {})", a, b, self.use_lub); self.infcx().commit_if_ok(|_| { - let at = self.infcx().at(&self.cause, self.env().env); + let at = self.infcx().at(&self.cause, self.param_env()); let res = if self.use_lub { at.lub(b, a) @@ -329,7 +328,7 @@ where obligations.push(Obligation::new( self.interner(), self.cause.clone(), - self.env().env, + self.param_env(), Binder::dummy(PredicateKind::Coerce(CoercePredicate { a: source_ty, b: target_ty, @@ -381,7 +380,7 @@ where let mut first_error = None; let mut r_borrow_var = None; - let mut autoderef = Autoderef::new_with_tracking(self.infcx(), self.env(), a); + let mut autoderef = Autoderef::new_with_tracking(self.infcx(), self.param_env(), a); let mut found = None; for (referent_ty, autoderefs) in autoderef.by_ref() { @@ -684,7 +683,7 @@ where let mut queue: SmallVec<[PredicateObligation<'db>; 4]> = smallvec![Obligation::new( self.interner(), cause, - self.env().env, + self.param_env(), TraitRef::new( self.interner(), coerce_unsized_did.into(), @@ -975,8 +974,8 @@ impl<'db> CoerceDelegate<'db> for InferenceCoercionDelegate<'_, '_, 'db> { &self.0.table.infer_ctxt } #[inline] - fn env(&self) -> &TraitEnvironment<'db> { - &self.0.table.trait_env + fn param_env(&self) -> ParamEnv<'db> { + self.0.table.param_env } #[inline] @@ -1104,12 +1103,8 @@ impl<'db> InferenceContext<'_, 'db> { match self.table.commit_if_ok(|table| { // We need to eagerly handle nested obligations due to lazy norm. let mut ocx = ObligationCtxt::new(&table.infer_ctxt); - let value = ocx.lub( - &ObligationCause::new(), - table.trait_env.env, - prev_ty, - new_ty, - )?; + let value = + ocx.lub(&ObligationCause::new(), table.param_env, prev_ty, new_ty)?; if ocx.try_evaluate_obligations().is_empty() { Ok(InferOk { value, obligations: ocx.into_pending_obligations() }) } else { @@ -1152,7 +1147,7 @@ impl<'db> InferenceContext<'_, 'db> { let sig = self .table .infer_ctxt - .at(&ObligationCause::new(), self.table.trait_env.env) + .at(&ObligationCause::new(), self.table.param_env) .lub(a_sig, b_sig) .map(|ok| self.table.register_infer_ok(ok))?; @@ -1231,7 +1226,7 @@ impl<'db> InferenceContext<'_, 'db> { .commit_if_ok(|table| { table .infer_ctxt - .at(&ObligationCause::new(), table.trait_env.env) + .at(&ObligationCause::new(), table.param_env) .lub(prev_ty, new_ty) }) .unwrap_err()) @@ -1483,7 +1478,7 @@ impl<'db, 'exprs> CoerceMany<'db, 'exprs> { // // Another example is `break` with no argument expression. assert!(expression_ty.is_unit(), "if let hack without unit type"); - icx.table.infer_ctxt.at(cause, icx.table.trait_env.env).eq(expected, found).map( + icx.table.infer_ctxt.at(cause, icx.table.param_env).eq(expected, found).map( |infer_ok| { icx.table.register_infer_ok(infer_ok); expression_ty @@ -1540,7 +1535,7 @@ impl<'db, 'exprs> CoerceMany<'db, 'exprs> { pub fn could_coerce<'db>( db: &'db dyn HirDatabase, - env: Arc<TraitEnvironment<'db>>, + env: ParamEnvAndCrate<'db>, tys: &Canonical<'db, (Ty<'db>, Ty<'db>)>, ) -> bool { coerce(db, env, tys).is_ok() @@ -1548,7 +1543,7 @@ pub fn could_coerce<'db>( struct HirCoercionDelegate<'a, 'db> { infcx: &'a InferCtxt<'db>, - env: &'a TraitEnvironment<'db>, + param_env: ParamEnv<'db>, target_features: &'a TargetFeatures<'db>, } @@ -1558,8 +1553,8 @@ impl<'db> CoerceDelegate<'db> for HirCoercionDelegate<'_, 'db> { self.infcx } #[inline] - fn env(&self) -> &TraitEnvironment<'db> { - self.env + fn param_env(&self) -> ParamEnv<'db> { + self.param_env } fn target_features(&self) -> (&TargetFeatures<'db>, TargetFeatureIsSafeInTarget) { (self.target_features, TargetFeatureIsSafeInTarget::No) @@ -1573,7 +1568,7 @@ impl<'db> CoerceDelegate<'db> for HirCoercionDelegate<'_, 'db> { fn coerce<'db>( db: &'db dyn HirDatabase, - env: Arc<TraitEnvironment<'db>>, + env: ParamEnvAndCrate<'db>, tys: &Canonical<'db, (Ty<'db>, Ty<'db>)>, ) -> Result<(Vec<Adjustment<'db>>, Ty<'db>), TypeError<DbInterner<'db>>> { let interner = DbInterner::new_with(db, env.krate); @@ -1586,7 +1581,7 @@ fn coerce<'db>( let mut coerce = Coerce { delegate: HirCoercionDelegate { infcx: &infcx, - env: &env, + param_env: env.param_env, target_features: &target_features, }, cause, |