diff options
| author | Oli Scherer <git-spam-no-reply9815368754983@oli-obk.de> | 2022-11-09 10:49:28 +0000 | 
|---|---|---|
| committer | Oli Scherer <git-spam-no-reply9815368754983@oli-obk.de> | 2022-11-16 09:25:19 +0000 | 
| commit | 4f11f3b2571c895c08757aa91af57fc1091e45ef (patch) | |
| tree | fa952f5375f2f1270bd3e4a794434e4836a383bf /compiler/rustc_infer/src | |
| parent | 634df06fae22066e2a9f2d3ce68c0fc7203bfa92 (diff) | |
| download | rust-4f11f3b2571c895c08757aa91af57fc1091e45ef.tar.gz rust-4f11f3b2571c895c08757aa91af57fc1091e45ef.zip | |
Convert predicates into Predicate in the Obligation constructor
Diffstat (limited to 'compiler/rustc_infer/src')
| -rw-r--r-- | compiler/rustc_infer/src/infer/canonical/query_response.rs | 4 | ||||
| -rw-r--r-- | compiler/rustc_infer/src/infer/combine.rs | 9 | ||||
| -rw-r--r-- | compiler/rustc_infer/src/infer/opaque_types.rs | 7 | ||||
| -rw-r--r-- | compiler/rustc_infer/src/infer/projection.rs | 10 | ||||
| -rw-r--r-- | compiler/rustc_infer/src/infer/sub.rs | 6 | ||||
| -rw-r--r-- | compiler/rustc_infer/src/traits/mod.rs | 29 | 
6 files changed, 35 insertions, 30 deletions
| diff --git a/compiler/rustc_infer/src/infer/canonical/query_response.rs b/compiler/rustc_infer/src/infer/canonical/query_response.rs index a299a3e578d..34f54328230 100644 --- a/compiler/rustc_infer/src/infer/canonical/query_response.rs +++ b/compiler/rustc_infer/src/infer/canonical/query_response.rs @@ -581,9 +581,9 @@ impl<'tcx> InferCtxt<'tcx> { span_bug!(cause.span, "unexpected const outlives {:?}", predicate); } }; - let predicate = predicate.0.rebind(atom).to_predicate(self.tcx); + let predicate = predicate.0.rebind(atom); - Obligation::new(cause, param_env, predicate) + Obligation::new(self.tcx, cause, param_env, predicate) } /// Given two sets of values for the same set of canonical variables, unify them. diff --git a/compiler/rustc_infer/src/infer/combine.rs b/compiler/rustc_infer/src/infer/combine.rs index a973bf54b05..37f071a19ac 100644 --- a/compiler/rustc_infer/src/infer/combine.rs +++ b/compiler/rustc_infer/src/infer/combine.rs @@ -37,7 +37,7 @@ use rustc_middle::traits::ObligationCause; use rustc_middle::ty::error::{ExpectedFound, TypeError}; use rustc_middle::ty::relate::{self, Relate, RelateResult, TypeRelation}; use rustc_middle::ty::subst::SubstsRef; -use rustc_middle::ty::{self, InferConst, ToPredicate, Ty, TyCtxt, TypeVisitable}; +use rustc_middle::ty::{self, InferConst, Ty, TyCtxt, TypeVisitable}; use rustc_middle::ty::{IntType, UintType}; use rustc_span::{Span, DUMMY_SP}; @@ -347,10 +347,10 @@ impl<'infcx, 'tcx> CombineFields<'infcx, 'tcx> { if needs_wf { self.obligations.push(Obligation::new( + self.tcx(), self.trace.cause.clone(), self.param_env, - ty::Binder::dummy(ty::PredicateKind::WellFormed(b_ty.into())) - .to_predicate(self.infcx.tcx), + ty::Binder::dummy(ty::PredicateKind::WellFormed(b_ty.into())), )); } @@ -444,9 +444,10 @@ impl<'infcx, 'tcx> CombineFields<'infcx, 'tcx> { ty::PredicateKind::ConstEquate(b, a) }; self.obligations.push(Obligation::new( + self.tcx(), self.trace.cause.clone(), self.param_env, - ty::Binder::dummy(predicate).to_predicate(self.tcx()), + ty::Binder::dummy(predicate), )); } } diff --git a/compiler/rustc_infer/src/infer/opaque_types.rs b/compiler/rustc_infer/src/infer/opaque_types.rs index a982f11f718..1fa95f8d62a 100644 --- a/compiler/rustc_infer/src/infer/opaque_types.rs +++ b/compiler/rustc_infer/src/infer/opaque_types.rs @@ -595,7 +595,12 @@ impl<'tcx> InferCtxt<'tcx> { } // Require that the predicate holds for the concrete type. debug!(?predicate); - obligations.push(traits::Obligation::new(cause.clone(), param_env, predicate)); + obligations.push(traits::Obligation::new( + self.tcx, + cause.clone(), + param_env, + predicate, + )); } Ok(InferOk { value: (), obligations }) } diff --git a/compiler/rustc_infer/src/infer/projection.rs b/compiler/rustc_infer/src/infer/projection.rs index 9f12bc972a8..eb6deee291c 100644 --- a/compiler/rustc_infer/src/infer/projection.rs +++ b/compiler/rustc_infer/src/infer/projection.rs @@ -1,5 +1,5 @@ use rustc_middle::traits::ObligationCause; -use rustc_middle::ty::{self, ToPredicate, Ty}; +use rustc_middle::ty::{self, Ty}; use crate::traits::{Obligation, PredicateObligation}; @@ -28,12 +28,8 @@ impl<'tcx> InferCtxt<'tcx> { }); let projection = ty::Binder::dummy(ty::ProjectionPredicate { projection_ty, term: ty_var.into() }); - let obligation = Obligation::with_depth( - cause, - recursion_depth, - param_env, - projection.to_predicate(self.tcx), - ); + let obligation = + Obligation::with_depth(self.tcx, cause, recursion_depth, param_env, projection); obligations.push(obligation); ty_var } diff --git a/compiler/rustc_infer/src/infer/sub.rs b/compiler/rustc_infer/src/infer/sub.rs index 97354ba5d1b..8c8445a4d9e 100644 --- a/compiler/rustc_infer/src/infer/sub.rs +++ b/compiler/rustc_infer/src/infer/sub.rs @@ -6,7 +6,7 @@ use crate::traits::Obligation; use rustc_middle::ty::relate::{Cause, Relate, RelateResult, TypeRelation}; use rustc_middle::ty::visit::TypeVisitable; use rustc_middle::ty::TyVar; -use rustc_middle::ty::{self, ToPredicate, Ty, TyCtxt}; +use rustc_middle::ty::{self, Ty, TyCtxt}; use std::mem; /// Ensures `a` is made a subtype of `b`. Returns `a` on success. @@ -95,14 +95,14 @@ impl<'tcx> TypeRelation<'tcx> for Sub<'_, '_, 'tcx> { // can't make progress on `A <: B` if both A and B are // type variables, so record an obligation. self.fields.obligations.push(Obligation::new( + self.tcx(), self.fields.trace.cause.clone(), self.fields.param_env, ty::Binder::dummy(ty::PredicateKind::Subtype(ty::SubtypePredicate { a_is_expected: self.a_is_expected, a, b, - })) - .to_predicate(self.tcx()), + })), )); Ok(a) diff --git a/compiler/rustc_infer/src/traits/mod.rs b/compiler/rustc_infer/src/traits/mod.rs index c8600ded987..a9e6241bf6b 100644 --- a/compiler/rustc_infer/src/traits/mod.rs +++ b/compiler/rustc_infer/src/traits/mod.rs @@ -10,7 +10,7 @@ pub mod util; use rustc_hir as hir; use rustc_middle::ty::error::{ExpectedFound, TypeError}; -use rustc_middle::ty::{self, Const, Ty, TyCtxt}; +use rustc_middle::ty::{self, Const, ToPredicate, Ty, TyCtxt}; use rustc_span::Span; pub use self::FulfillmentErrorCode::*; @@ -124,38 +124,41 @@ pub enum FulfillmentErrorCode<'tcx> { impl<'tcx, O> Obligation<'tcx, O> { pub fn new( + tcx: TyCtxt<'tcx>, cause: ObligationCause<'tcx>, param_env: ty::ParamEnv<'tcx>, - predicate: O, + predicate: impl ToPredicate<'tcx, O>, ) -> Obligation<'tcx, O> { - Obligation { cause, param_env, recursion_depth: 0, predicate } + Self::with_depth(tcx, cause, 0, param_env, predicate) } pub fn with_depth( + tcx: TyCtxt<'tcx>, cause: ObligationCause<'tcx>, recursion_depth: usize, param_env: ty::ParamEnv<'tcx>, - predicate: O, + predicate: impl ToPredicate<'tcx, O>, ) -> Obligation<'tcx, O> { + let predicate = predicate.to_predicate(tcx); Obligation { cause, param_env, recursion_depth, predicate } } pub fn misc( + tcx: TyCtxt<'tcx>, span: Span, body_id: hir::HirId, param_env: ty::ParamEnv<'tcx>, - trait_ref: O, + trait_ref: impl ToPredicate<'tcx, O>, ) -> Obligation<'tcx, O> { - Obligation::new(ObligationCause::misc(span, body_id), param_env, trait_ref) + Obligation::new(tcx, ObligationCause::misc(span, body_id), param_env, trait_ref) } - pub fn with<P>(&self, value: P) -> Obligation<'tcx, P> { - Obligation { - cause: self.cause.clone(), - param_env: self.param_env, - recursion_depth: self.recursion_depth, - predicate: value, - } + pub fn with<P>( + &self, + tcx: TyCtxt<'tcx>, + value: impl ToPredicate<'tcx, P>, + ) -> Obligation<'tcx, P> { + Obligation::with_depth(tcx, self.cause.clone(), self.recursion_depth, self.param_env, value) } } | 
