diff --git a/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs b/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs index ccc45e2829a..15050c87b39 100644 --- a/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs +++ b/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs @@ -24,8 +24,8 @@ use rustc_middle::mir::{ }; use rustc_middle::ty::print::PrintTraitRefExt as _; use rustc_middle::ty::{ - self, suggest_constraining_type_params, PredicateKind, ToPredicate, Ty, TyCtxt, - TypeSuperVisitable, TypeVisitor, + self, suggest_constraining_type_params, PredicateKind, Ty, TyCtxt, TypeSuperVisitable, + TypeVisitor, Upcast, }; use rustc_middle::util::CallKind; use rustc_mir_dataflow::move_paths::{InitKind, MoveOutIndex, MovePathIndex}; @@ -1915,7 +1915,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { self.infcx.err_ctxt().suggest_derive( &obligation, err, - trait_ref.to_predicate(self.infcx.tcx), + trait_ref.upcast(self.infcx.tcx), ); } } diff --git a/compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs b/compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs index c9a09c19ce6..35017b9e6b5 100644 --- a/compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs +++ b/compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs @@ -9,7 +9,7 @@ use rustc_hir::{self as hir, BindingMode, ByRef, Node}; use rustc_infer::traits; use rustc_middle::bug; use rustc_middle::mir::{Mutability, Place, PlaceRef, ProjectionElem}; -use rustc_middle::ty::{self, InstanceDef, ToPredicate, Ty, TyCtxt}; +use rustc_middle::ty::{self, InstanceDef, Ty, TyCtxt, Upcast}; use rustc_middle::{ hir::place::PlaceBase, mir::{self, BindingForm, Local, LocalDecl, LocalInfo, LocalKind, Location}, @@ -1255,7 +1255,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> { self.infcx.err_ctxt().suggest_derive( &obligation, err, - trait_ref.to_predicate(self.infcx.tcx), + trait_ref.upcast(self.infcx.tcx), ); } Some(errors) => { diff --git a/compiler/rustc_borrowck/src/type_check/canonical.rs b/compiler/rustc_borrowck/src/type_check/canonical.rs index 49d3f7381d9..2b89fa9b770 100644 --- a/compiler/rustc_borrowck/src/type_check/canonical.rs +++ b/compiler/rustc_borrowck/src/type_check/canonical.rs @@ -4,7 +4,7 @@ use rustc_errors::ErrorGuaranteed; use rustc_infer::infer::canonical::Canonical; use rustc_middle::bug; use rustc_middle::mir::ConstraintCategory; -use rustc_middle::ty::{self, ToPredicate, Ty, TyCtxt, TypeFoldable}; +use rustc_middle::ty::{self, Ty, TyCtxt, TypeFoldable, Upcast}; use rustc_span::def_id::DefId; use rustc_span::Span; use rustc_trait_selection::traits::query::type_op::{self, TypeOpOutput}; @@ -115,7 +115,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { pub(super) fn prove_predicates( &mut self, - predicates: impl IntoIterator + std::fmt::Debug>, + predicates: impl IntoIterator + std::fmt::Debug>, locations: Locations, category: ConstraintCategory<'tcx>, ) { @@ -127,12 +127,12 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { #[instrument(skip(self), level = "debug")] pub(super) fn prove_predicate( &mut self, - predicate: impl ToPredicate<'tcx> + std::fmt::Debug, + predicate: impl Upcast<'tcx> + std::fmt::Debug, locations: Locations, category: ConstraintCategory<'tcx>, ) { let param_env = self.param_env; - let predicate = predicate.to_predicate(self.tcx()); + let predicate = predicate.upcast(self.tcx()); let _: Result<_, ErrorGuaranteed> = self.fully_perform_op( locations, category, diff --git a/compiler/rustc_borrowck/src/type_check/relate_tys.rs b/compiler/rustc_borrowck/src/type_check/relate_tys.rs index 493c41e59e3..2b01b8dbbf4 100644 --- a/compiler/rustc_borrowck/src/type_check/relate_tys.rs +++ b/compiler/rustc_borrowck/src/type_check/relate_tys.rs @@ -546,7 +546,7 @@ impl<'bccx, 'tcx> ObligationEmittingRelation<'tcx> for NllTypeRelating<'_, 'bccx self.type_checker.param_env } - fn register_predicates(&mut self, obligations: impl IntoIterator>) { + fn register_predicates(&mut self, obligations: impl IntoIterator>) { self.register_obligations( obligations .into_iter() diff --git a/compiler/rustc_hir_analysis/src/bounds.rs b/compiler/rustc_hir_analysis/src/bounds.rs index 5562b81871f..38ecd7dd082 100644 --- a/compiler/rustc_hir_analysis/src/bounds.rs +++ b/compiler/rustc_hir_analysis/src/bounds.rs @@ -2,7 +2,7 @@ //! [`rustc_middle::ty`] form. use rustc_hir::LangItem; -use rustc_middle::ty::{self, ToPredicate, Ty, TyCtxt}; +use rustc_middle::ty::{self, Ty, TyCtxt, Upcast}; use rustc_span::Span; /// Collects together a list of type bounds. These lists of bounds occur in many places @@ -34,7 +34,7 @@ impl<'tcx> Bounds<'tcx> { span: Span, ) { self.clauses - .push((region.map_bound(|p| ty::ClauseKind::TypeOutlives(p)).to_predicate(tcx), span)); + .push((region.map_bound(|p| ty::ClauseKind::TypeOutlives(p)).upcast(tcx), span)); } pub fn push_trait_bound( @@ -49,7 +49,7 @@ impl<'tcx> Bounds<'tcx> { .map_bound(|trait_ref| { ty::ClauseKind::Trait(ty::TraitPredicate { trait_ref, polarity }) }) - .to_predicate(tcx), + .upcast(tcx), span, ); // FIXME(-Znext-solver): We can likely remove this hack once the new trait solver lands. @@ -67,7 +67,7 @@ impl<'tcx> Bounds<'tcx> { span: Span, ) { self.clauses.push(( - projection.map_bound(|proj| ty::ClauseKind::Projection(proj)).to_predicate(tcx), + projection.map_bound(|proj| ty::ClauseKind::Projection(proj)).upcast(tcx), span, )); } @@ -76,7 +76,7 @@ impl<'tcx> Bounds<'tcx> { let sized_def_id = tcx.require_lang_item(LangItem::Sized, Some(span)); let trait_ref = ty::TraitRef::new(tcx, sized_def_id, [ty]); // Preferable to put this obligation first, since we report better errors for sized ambiguity. - self.clauses.insert(0, (trait_ref.to_predicate(tcx), span)); + self.clauses.insert(0, (trait_ref.upcast(tcx), span)); } pub fn clauses(&self) -> impl Iterator, Span)> + '_ { diff --git a/compiler/rustc_hir_analysis/src/check/compare_impl_item.rs b/compiler/rustc_hir_analysis/src/check/compare_impl_item.rs index 39940c8f0f3..19645049d0c 100644 --- a/compiler/rustc_hir_analysis/src/check/compare_impl_item.rs +++ b/compiler/rustc_hir_analysis/src/check/compare_impl_item.rs @@ -14,7 +14,7 @@ use rustc_infer::traits::{util, FulfillmentError}; use rustc_middle::ty::error::{ExpectedFound, TypeError}; use rustc_middle::ty::fold::BottomUpFolder; use rustc_middle::ty::util::ExplicitSelf; -use rustc_middle::ty::ToPredicate; +use rustc_middle::ty::Upcast; use rustc_middle::ty::{ self, GenericArgs, Ty, TypeFoldable, TypeFolder, TypeSuperFoldable, TypeVisitableExt, }; @@ -2211,7 +2211,7 @@ fn param_env_with_gat_bounds<'tcx>( }, bound_vars, ) - .to_predicate(tcx), + .upcast(tcx), ), }; } diff --git a/compiler/rustc_hir_analysis/src/check/wfcheck.rs b/compiler/rustc_hir_analysis/src/check/wfcheck.rs index b918a8c32d8..059e4141e15 100644 --- a/compiler/rustc_hir_analysis/src/check/wfcheck.rs +++ b/compiler/rustc_hir_analysis/src/check/wfcheck.rs @@ -20,8 +20,8 @@ use rustc_middle::query::Providers; use rustc_middle::ty::print::with_no_trimmed_paths; use rustc_middle::ty::trait_def::TraitSpecializationKind; use rustc_middle::ty::{ - self, AdtKind, GenericParamDefKind, ToPredicate, Ty, TyCtxt, TypeFoldable, TypeSuperVisitable, - TypeVisitable, TypeVisitableExt, TypeVisitor, + self, AdtKind, GenericParamDefKind, Ty, TyCtxt, TypeFoldable, TypeSuperVisitable, + TypeVisitable, TypeVisitableExt, TypeVisitor, Upcast, }; use rustc_middle::ty::{GenericArgKind, GenericArgs}; use rustc_middle::{bug, span_bug}; @@ -685,7 +685,7 @@ fn gather_gat_bounds<'tcx, T: TypeFoldable>>( // `Self: 'me`.) bounds.insert( ty::ClauseKind::TypeOutlives(ty::OutlivesPredicate(ty_param, region_param)) - .to_predicate(tcx), + .upcast(tcx), ); } } @@ -730,7 +730,7 @@ fn gather_gat_bounds<'tcx, T: TypeFoldable>>( region_a_param, region_b_param, )) - .to_predicate(tcx), + .upcast(tcx), ); } } diff --git a/compiler/rustc_hir_analysis/src/collect.rs b/compiler/rustc_hir_analysis/src/collect.rs index 0b9f7fd41fb..a1f44f82279 100644 --- a/compiler/rustc_hir_analysis/src/collect.rs +++ b/compiler/rustc_hir_analysis/src/collect.rs @@ -29,7 +29,7 @@ use rustc_infer::traits::ObligationCause; use rustc_middle::hir::nested_filter; use rustc_middle::query::Providers; use rustc_middle::ty::util::{Discr, IntTypeExt}; -use rustc_middle::ty::{self, AdtKind, Const, IsSuggestable, ToPredicate, Ty, TyCtxt}; +use rustc_middle::ty::{self, AdtKind, Const, IsSuggestable, Ty, TyCtxt, Upcast}; use rustc_middle::{bug, span_bug}; use rustc_span::symbol::{kw, sym, Ident, Symbol}; use rustc_span::{Span, DUMMY_SP}; @@ -1665,7 +1665,7 @@ fn predicates_defined_on(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericPredicate def_id, inferred_outlives, ); let inferred_outlives_iter = - inferred_outlives.iter().map(|(clause, span)| ((*clause).to_predicate(tcx), *span)); + inferred_outlives.iter().map(|(clause, span)| ((*clause).upcast(tcx), *span)); if result.predicates.is_empty() { result.predicates = tcx.arena.alloc_from_iter(inferred_outlives_iter); } else { diff --git a/compiler/rustc_hir_analysis/src/collect/predicates_of.rs b/compiler/rustc_hir_analysis/src/collect/predicates_of.rs index d348d6f789f..eeca67cb56e 100644 --- a/compiler/rustc_hir_analysis/src/collect/predicates_of.rs +++ b/compiler/rustc_hir_analysis/src/collect/predicates_of.rs @@ -9,7 +9,7 @@ use rustc_hir::def::DefKind; use rustc_hir::def_id::{DefId, LocalDefId}; use rustc_hir::intravisit::{self, Visitor}; use rustc_middle::ty::{self, Ty, TyCtxt}; -use rustc_middle::ty::{GenericPredicates, ImplTraitInTraitData, ToPredicate}; +use rustc_middle::ty::{GenericPredicates, ImplTraitInTraitData, Upcast}; use rustc_middle::{bug, span_bug}; use rustc_span::symbol::Ident; use rustc_span::{Span, DUMMY_SP}; @@ -42,7 +42,7 @@ pub(super) fn predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericPredic result.predicates = tcx.arena.alloc_from_iter(result.predicates.iter().copied().chain(std::iter::once(( - ty::TraitRef::identity(tcx, def_id).to_predicate(tcx), + ty::TraitRef::identity(tcx, def_id).upcast(tcx), span, )))); } @@ -165,7 +165,7 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Gen // (see below). Recall that a default impl is not itself an impl, but rather a // set of defaults that can be incorporated into another impl. if let Some(trait_ref) = is_default_impl_trait { - predicates.insert((trait_ref.to_predicate(tcx), tcx.def_span(def_id))); + predicates.insert((trait_ref.upcast(tcx), tcx.def_span(def_id))); } // Collect the predicates that were written inline by the user on each @@ -197,7 +197,7 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Gen .expect("const parameters cannot be generic"); let ct = icx.lowerer().lower_const_param(param.hir_id, ct_ty); predicates.insert(( - ty::ClauseKind::ConstArgHasType(ct, ct_ty).to_predicate(tcx), + ty::ClauseKind::ConstArgHasType(ct, ct_ty).upcast(tcx), param.span, )); } @@ -228,7 +228,7 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Gen ty::ClauseKind::WellFormed(ty.into()), bound_vars, ); - predicates.insert((predicate.to_predicate(tcx), span)); + predicates.insert((predicate.upcast(tcx), span)); } } @@ -258,7 +258,7 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Gen } }; let pred = ty::ClauseKind::RegionOutlives(ty::OutlivesPredicate(r1, r2)) - .to_predicate(tcx); + .upcast(tcx); (pred, span) })) } @@ -328,12 +328,12 @@ fn compute_bidirectional_outlives_predicates<'tcx>( let span = tcx.def_span(param.def_id); predicates.push(( ty::ClauseKind::RegionOutlives(ty::OutlivesPredicate(orig_lifetime, dup_lifetime)) - .to_predicate(tcx), + .upcast(tcx), span, )); predicates.push(( ty::ClauseKind::RegionOutlives(ty::OutlivesPredicate(dup_lifetime, orig_lifetime)) - .to_predicate(tcx), + .upcast(tcx), span, )); } @@ -355,7 +355,7 @@ fn const_evaluatable_predicates_of( if let ty::ConstKind::Unevaluated(_) = ct.kind() { let span = self.tcx.def_span(c.def_id); self.preds - .insert((ty::ClauseKind::ConstEvaluatable(ct).to_predicate(self.tcx), span)); + .insert((ty::ClauseKind::ConstEvaluatable(ct).upcast(self.tcx), span)); } } @@ -694,7 +694,7 @@ pub(super) fn type_param_predicates( && param_id == item_hir_id { let identity_trait_ref = ty::TraitRef::identity(tcx, item_def_id.to_def_id()); - extend = Some((identity_trait_ref.to_predicate(tcx), item.span)); + extend = Some((identity_trait_ref.upcast(tcx), item.span)); } let icx = ItemCtxt::new(tcx, item_def_id); diff --git a/compiler/rustc_hir_analysis/src/hir_ty_lowering/object_safety.rs b/compiler/rustc_hir_analysis/src/hir_ty_lowering/object_safety.rs index 30b99a095f3..4f7a39d0250 100644 --- a/compiler/rustc_hir_analysis/src/hir_ty_lowering/object_safety.rs +++ b/compiler/rustc_hir_analysis/src/hir_ty_lowering/object_safety.rs @@ -9,7 +9,7 @@ use rustc_lint_defs::builtin::UNUSED_ASSOCIATED_TYPE_BOUNDS; use rustc_middle::span_bug; use rustc_middle::ty::fold::BottomUpFolder; use rustc_middle::ty::{self, ExistentialPredicateStableCmpExt as _, Ty, TyCtxt, TypeFoldable}; -use rustc_middle::ty::{DynKind, ToPredicate}; +use rustc_middle::ty::{DynKind, Upcast}; use rustc_span::{ErrorGuaranteed, Span}; use rustc_trait_selection::traits::error_reporting::report_object_safety_error; use rustc_trait_selection::traits::{self, hir_ty_lowering_object_safety_violations}; @@ -119,7 +119,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { .filter(|(trait_ref, _)| !tcx.trait_is_auto(trait_ref.def_id())); for (base_trait_ref, span) in regular_traits_refs_spans { - let base_pred: ty::Predicate<'tcx> = base_trait_ref.to_predicate(tcx); + let base_pred: ty::Predicate<'tcx> = base_trait_ref.upcast(tcx); for pred in traits::elaborate(tcx, [base_pred]).filter_only_self() { debug!("observing object predicate `{pred:?}`"); diff --git a/compiler/rustc_hir_analysis/src/outlives/mod.rs b/compiler/rustc_hir_analysis/src/outlives/mod.rs index a87112dcc12..97fd7731b1e 100644 --- a/compiler/rustc_hir_analysis/src/outlives/mod.rs +++ b/compiler/rustc_hir_analysis/src/outlives/mod.rs @@ -2,7 +2,7 @@ use rustc_hir::def::DefKind; use rustc_hir::def_id::LocalDefId; use rustc_middle::query::Providers; use rustc_middle::ty::GenericArgKind; -use rustc_middle::ty::{self, CratePredicatesMap, ToPredicate, TyCtxt}; +use rustc_middle::ty::{self, CratePredicatesMap, TyCtxt, Upcast}; use rustc_span::Span; mod explicit; @@ -75,14 +75,14 @@ fn inferred_outlives_crate(tcx: TyCtxt<'_>, (): ()) -> CratePredicatesMap<'_> { match kind1.unpack() { GenericArgKind::Type(ty1) => Some(( ty::ClauseKind::TypeOutlives(ty::OutlivesPredicate(ty1, *region2)) - .to_predicate(tcx), + .upcast(tcx), span, )), GenericArgKind::Lifetime(region1) => Some(( ty::ClauseKind::RegionOutlives(ty::OutlivesPredicate( region1, *region2, )) - .to_predicate(tcx), + .upcast(tcx), span, )), GenericArgKind::Const(_) => { diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs index fe0dd4e393f..56e13cd679d 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs @@ -28,8 +28,8 @@ use rustc_middle::middle::stability::EvalResult; use rustc_middle::span_bug; use rustc_middle::ty::print::with_no_trimmed_paths; use rustc_middle::ty::{ - self, suggest_constraining_type_params, Article, Binder, IsSuggestable, ToPredicate, Ty, - TypeVisitableExt, + self, suggest_constraining_type_params, Article, Binder, IsSuggestable, Ty, TypeVisitableExt, + Upcast, }; use rustc_session::errors::ExprParenthesesNeeded; use rustc_span::source_map::Spanned; @@ -1716,7 +1716,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } } } - self.suggest_derive(diag, &[(trait_ref.to_predicate(self.tcx), None, None)]); + self.suggest_derive(diag, &[(trait_ref.upcast(self.tcx), None, None)]); } } } diff --git a/compiler/rustc_hir_typeck/src/method/probe.rs b/compiler/rustc_hir_typeck/src/method/probe.rs index 6cfdacf6a24..7ec0bdbef99 100644 --- a/compiler/rustc_hir_typeck/src/method/probe.rs +++ b/compiler/rustc_hir_typeck/src/method/probe.rs @@ -21,7 +21,7 @@ use rustc_middle::query::Providers; use rustc_middle::ty::fast_reject::{simplify_type, TreatParams}; use rustc_middle::ty::AssocItem; use rustc_middle::ty::GenericParamDefKind; -use rustc_middle::ty::ToPredicate; +use rustc_middle::ty::Upcast; use rustc_middle::ty::{self, ParamEnvAnd, Ty, TyCtxt, TypeVisitableExt}; use rustc_middle::ty::{GenericArgs, GenericArgsRef}; use rustc_middle::{bug, span_bug}; @@ -1496,7 +1496,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> { } } - trait_predicate = Some(ty::Binder::dummy(trait_ref).to_predicate(self.tcx)); + trait_predicate = Some(ty::Binder::dummy(trait_ref).upcast(self.tcx)); } ObjectCandidate(poly_trait_ref) | WhereClauseCandidate(poly_trait_ref) => { let trait_ref = self.instantiate_binder_with_fresh_vars( diff --git a/compiler/rustc_infer/src/infer/error_reporting/mod.rs b/compiler/rustc_infer/src/infer/error_reporting/mod.rs index d0687dfc6fd..f4618fb8243 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/mod.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/mod.rs @@ -73,7 +73,7 @@ use rustc_middle::bug; use rustc_middle::dep_graph::DepContext; use rustc_middle::ty::print::{with_forced_trimmed_paths, PrintError, PrintTraitRefExt as _}; use rustc_middle::ty::relate::{self, RelateResult, TypeRelation}; -use rustc_middle::ty::ToPredicate; +use rustc_middle::ty::Upcast; use rustc_middle::ty::{ self, error::TypeError, IsSuggestable, List, Region, Ty, TyCtxt, TypeFoldable, TypeSuperVisitable, TypeVisitable, TypeVisitableExt, @@ -516,7 +516,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { RegionResolutionError::CannotNormalize(clause, origin) => { let clause: ty::Clause<'tcx> = - clause.map_bound(ty::ClauseKind::TypeOutlives).to_predicate(self.tcx); + clause.map_bound(ty::ClauseKind::TypeOutlives).upcast(self.tcx); self.tcx .dcx() .struct_span_err(origin.span(), format!("cannot normalize `{clause}`")) diff --git a/compiler/rustc_infer/src/infer/relate/combine.rs b/compiler/rustc_infer/src/infer/relate/combine.rs index c1baadfa8df..18727335006 100644 --- a/compiler/rustc_infer/src/infer/relate/combine.rs +++ b/compiler/rustc_infer/src/infer/relate/combine.rs @@ -29,7 +29,7 @@ use rustc_middle::infer::canonical::OriginalQueryValues; use rustc_middle::infer::unify_key::EffectVarValue; use rustc_middle::ty::error::{ExpectedFound, TypeError}; use rustc_middle::ty::relate::{RelateResult, TypeRelation}; -use rustc_middle::ty::{self, InferConst, ToPredicate, Ty, TyCtxt, TypeVisitableExt}; +use rustc_middle::ty::{self, InferConst, Ty, TyCtxt, TypeVisitableExt, Upcast}; use rustc_middle::ty::{IntType, UintType}; use rustc_span::Span; @@ -337,7 +337,7 @@ impl<'infcx, 'tcx> CombineFields<'infcx, 'tcx> { self.obligations.extend(obligations); } - pub fn register_predicates(&mut self, obligations: impl IntoIterator>) { + pub fn register_predicates(&mut self, obligations: impl IntoIterator>) { self.obligations.extend(obligations.into_iter().map(|to_pred| { Obligation::new(self.infcx.tcx, self.trace.cause.clone(), self.param_env, to_pred) })) @@ -360,7 +360,7 @@ pub trait ObligationEmittingRelation<'tcx>: TypeRelation<'tcx> { /// Register predicates that must hold in order for this relation to hold. Uses /// a default obligation cause, [`ObligationEmittingRelation::register_obligations`] should /// be used if control over the obligation causes is required. - fn register_predicates(&mut self, obligations: impl IntoIterator>); + fn register_predicates(&mut self, obligations: impl IntoIterator>); /// Register `AliasRelate` obligation(s) that both types must be related to each other. fn register_type_relate_obligation(&mut self, a: Ty<'tcx>, b: Ty<'tcx>); diff --git a/compiler/rustc_infer/src/infer/relate/glb.rs b/compiler/rustc_infer/src/infer/relate/glb.rs index b86d1b2671d..1a8f02fc5ca 100644 --- a/compiler/rustc_infer/src/infer/relate/glb.rs +++ b/compiler/rustc_infer/src/infer/relate/glb.rs @@ -140,7 +140,7 @@ impl<'tcx> ObligationEmittingRelation<'tcx> for Glb<'_, '_, 'tcx> { self.fields.param_env } - fn register_predicates(&mut self, obligations: impl IntoIterator>) { + fn register_predicates(&mut self, obligations: impl IntoIterator>) { self.fields.register_predicates(obligations); } diff --git a/compiler/rustc_infer/src/infer/relate/lub.rs b/compiler/rustc_infer/src/infer/relate/lub.rs index 20f5f65c984..18f92ca5236 100644 --- a/compiler/rustc_infer/src/infer/relate/lub.rs +++ b/compiler/rustc_infer/src/infer/relate/lub.rs @@ -140,7 +140,7 @@ impl<'tcx> ObligationEmittingRelation<'tcx> for Lub<'_, '_, 'tcx> { self.fields.param_env } - fn register_predicates(&mut self, obligations: impl IntoIterator>) { + fn register_predicates(&mut self, obligations: impl IntoIterator>) { self.fields.register_predicates(obligations); } diff --git a/compiler/rustc_infer/src/infer/relate/type_relating.rs b/compiler/rustc_infer/src/infer/relate/type_relating.rs index 86a24eef7f5..2dd37022319 100644 --- a/compiler/rustc_infer/src/infer/relate/type_relating.rs +++ b/compiler/rustc_infer/src/infer/relate/type_relating.rs @@ -312,7 +312,7 @@ impl<'tcx> ObligationEmittingRelation<'tcx> for TypeRelating<'_, '_, 'tcx> { self.structurally_relate_aliases } - fn register_predicates(&mut self, obligations: impl IntoIterator>) { + fn register_predicates(&mut self, obligations: impl IntoIterator>) { self.fields.register_predicates(obligations); } diff --git a/compiler/rustc_infer/src/traits/engine.rs b/compiler/rustc_infer/src/traits/engine.rs index cb067c7a660..cf523f056a3 100644 --- a/compiler/rustc_infer/src/traits/engine.rs +++ b/compiler/rustc_infer/src/traits/engine.rs @@ -2,7 +2,7 @@ use crate::infer::InferCtxt; use crate::traits::Obligation; use rustc_hir::def_id::DefId; use rustc_macros::extension; -use rustc_middle::ty::{self, ToPredicate, Ty}; +use rustc_middle::ty::{self, Ty, Upcast}; use super::FulfillmentError; use super::{ObligationCause, PredicateObligation}; @@ -26,7 +26,7 @@ pub trait TraitEngine<'tcx>: 'tcx { cause, recursion_depth: 0, param_env, - predicate: ty::Binder::dummy(trait_ref).to_predicate(infcx.tcx), + predicate: ty::Binder::dummy(trait_ref).upcast(infcx.tcx), }, ); } diff --git a/compiler/rustc_infer/src/traits/mod.rs b/compiler/rustc_infer/src/traits/mod.rs index f77a92bf9bc..f8999689241 100644 --- a/compiler/rustc_infer/src/traits/mod.rs +++ b/compiler/rustc_infer/src/traits/mod.rs @@ -16,7 +16,7 @@ use rustc_hir as hir; use rustc_middle::traits::query::NoSolution; use rustc_middle::traits::solve::Certainty; use rustc_middle::ty::error::{ExpectedFound, TypeError}; -use rustc_middle::ty::{self, Const, ToPredicate, Ty, TyCtxt}; +use rustc_middle::ty::{self, Const, Ty, TyCtxt, Upcast}; use rustc_span::Span; pub use self::ImplSource::*; @@ -155,7 +155,7 @@ impl<'tcx, O> Obligation<'tcx, O> { tcx: TyCtxt<'tcx>, cause: ObligationCause<'tcx>, param_env: ty::ParamEnv<'tcx>, - predicate: impl ToPredicate<'tcx, O>, + predicate: impl Upcast<'tcx, O>, ) -> Obligation<'tcx, O> { Self::with_depth(tcx, cause, 0, param_env, predicate) } @@ -173,9 +173,9 @@ impl<'tcx, O> Obligation<'tcx, O> { cause: ObligationCause<'tcx>, recursion_depth: usize, param_env: ty::ParamEnv<'tcx>, - predicate: impl ToPredicate<'tcx, O>, + predicate: impl Upcast<'tcx, O>, ) -> Obligation<'tcx, O> { - let predicate = predicate.to_predicate(tcx); + let predicate = predicate.upcast(tcx); Obligation { cause, param_env, recursion_depth, predicate } } @@ -184,16 +184,12 @@ impl<'tcx, O> Obligation<'tcx, O> { span: Span, body_id: LocalDefId, param_env: ty::ParamEnv<'tcx>, - trait_ref: impl ToPredicate<'tcx, O>, + trait_ref: impl Upcast<'tcx, O>, ) -> Obligation<'tcx, O> { Obligation::new(tcx, ObligationCause::misc(span, body_id), param_env, trait_ref) } - pub fn with

( - &self, - tcx: TyCtxt<'tcx>, - value: impl ToPredicate<'tcx, P>, - ) -> Obligation<'tcx, P> { + pub fn with

(&self, tcx: TyCtxt<'tcx>, value: impl Upcast<'tcx, P>) -> Obligation<'tcx, P> { Obligation::with_depth(tcx, self.cause.clone(), self.recursion_depth, self.param_env, value) } } diff --git a/compiler/rustc_infer/src/traits/util.rs b/compiler/rustc_infer/src/traits/util.rs index d8d84b777e0..6de32dd0774 100644 --- a/compiler/rustc_infer/src/traits/util.rs +++ b/compiler/rustc_infer/src/traits/util.rs @@ -3,7 +3,7 @@ use smallvec::smallvec; use crate::infer::outlives::components::{push_outlives_components, Component}; use crate::traits::{self, Obligation, ObligationCauseCode, PredicateObligation}; use rustc_data_structures::fx::FxHashSet; -use rustc_middle::ty::{self, ToPredicate, Ty, TyCtxt}; +use rustc_middle::ty::{self, Ty, TyCtxt, Upcast}; use rustc_span::symbol::Ident; use rustc_span::Span; @@ -358,7 +358,7 @@ impl<'tcx, O: Elaboratable<'tcx>> Elaborator<'tcx, O> { } }) .map(|clause| { - elaboratable.child(bound_clause.rebind(clause).to_predicate(tcx)) + elaboratable.child(bound_clause.rebind(clause).upcast(tcx)) }), ); } @@ -409,14 +409,14 @@ pub fn supertraits<'tcx>( tcx: TyCtxt<'tcx>, trait_ref: ty::PolyTraitRef<'tcx>, ) -> FilterToTraits>> { - elaborate(tcx, [trait_ref.to_predicate(tcx)]).filter_only_self().filter_to_traits() + elaborate(tcx, [trait_ref.upcast(tcx)]).filter_only_self().filter_to_traits() } pub fn transitive_bounds<'tcx>( tcx: TyCtxt<'tcx>, trait_refs: impl Iterator>, ) -> FilterToTraits>> { - elaborate(tcx, trait_refs.map(|trait_ref| trait_ref.to_predicate(tcx))) + elaborate(tcx, trait_refs.map(|trait_ref| trait_ref.upcast(tcx))) .filter_only_self() .filter_to_traits() } @@ -431,7 +431,7 @@ pub fn transitive_bounds_that_define_assoc_item<'tcx>( trait_refs: impl Iterator>, assoc_name: Ident, ) -> FilterToTraits>> { - elaborate(tcx, trait_refs.map(|trait_ref| trait_ref.to_predicate(tcx))) + elaborate(tcx, trait_refs.map(|trait_ref| trait_ref.upcast(tcx))) .filter_only_self_that_defines(assoc_name) .filter_to_traits() } diff --git a/compiler/rustc_lint/src/builtin.rs b/compiler/rustc_lint/src/builtin.rs index b9be92b89af..9c36e22aa29 100644 --- a/compiler/rustc_lint/src/builtin.rs +++ b/compiler/rustc_lint/src/builtin.rs @@ -57,8 +57,8 @@ use rustc_middle::lint::in_external_macro; use rustc_middle::ty::layout::LayoutOf; use rustc_middle::ty::print::with_no_trimmed_paths; use rustc_middle::ty::GenericArgKind; -use rustc_middle::ty::ToPredicate; use rustc_middle::ty::TypeVisitableExt; +use rustc_middle::ty::Upcast; use rustc_middle::ty::{self, Ty, TyCtxt, VariantDef}; use rustc_session::lint::{BuiltinLintDiag, FutureIncompatibilityReason}; use rustc_session::{declare_lint, declare_lint_pass, impl_lint_pass}; @@ -734,7 +734,7 @@ fn type_implements_negative_copy_modulo_regions<'tcx>( cause: traits::ObligationCause::dummy(), param_env, recursion_depth: 0, - predicate: ty::Binder::dummy(pred).to_predicate(tcx), + predicate: ty::Binder::dummy(pred).upcast(tcx), }; tcx.infer_ctxt().build().predicate_must_hold_modulo_regions(&obligation) diff --git a/compiler/rustc_middle/src/traits/solve.rs b/compiler/rustc_middle/src/traits/solve.rs index 3ad6b68d129..fe9a4c0f677 100644 --- a/compiler/rustc_middle/src/traits/solve.rs +++ b/compiler/rustc_middle/src/traits/solve.rs @@ -7,8 +7,8 @@ use crate::infer::canonical::{CanonicalVarValues, QueryRegionConstraints}; use crate::traits::query::NoSolution; use crate::traits::Canonical; use crate::ty::{ - self, FallibleTypeFolder, ToPredicate, Ty, TyCtxt, TypeFoldable, TypeFolder, TypeVisitable, - TypeVisitor, + self, FallibleTypeFolder, Ty, TyCtxt, TypeFoldable, TypeFolder, TypeVisitable, TypeVisitor, + Upcast, }; use super::BuiltinImplSource; @@ -33,14 +33,14 @@ impl<'tcx, P> Goal<'tcx, P> { pub fn new( tcx: TyCtxt<'tcx>, param_env: ty::ParamEnv<'tcx>, - predicate: impl ToPredicate<'tcx, P>, + predicate: impl Upcast<'tcx, P>, ) -> Goal<'tcx, P> { - Goal { param_env, predicate: predicate.to_predicate(tcx) } + Goal { param_env, predicate: predicate.upcast(tcx) } } /// Updates the goal to one with a different `predicate` but the same `param_env`. - pub fn with(self, tcx: TyCtxt<'tcx>, predicate: impl ToPredicate<'tcx, Q>) -> Goal<'tcx, Q> { - Goal { param_env: self.param_env, predicate: predicate.to_predicate(tcx) } + pub fn with(self, tcx: TyCtxt<'tcx>, predicate: impl Upcast<'tcx, Q>) -> Goal<'tcx, Q> { + Goal { param_env: self.param_env, predicate: predicate.upcast(tcx) } } } diff --git a/compiler/rustc_middle/src/traits/util.rs b/compiler/rustc_middle/src/traits/util.rs index 3419827a742..707e076921b 100644 --- a/compiler/rustc_middle/src/traits/util.rs +++ b/compiler/rustc_middle/src/traits/util.rs @@ -1,6 +1,6 @@ use rustc_data_structures::fx::FxHashSet; -use crate::ty::{Clause, PolyTraitRef, ToPolyTraitRef, ToPredicate, TyCtxt}; +use crate::ty::{Clause, PolyTraitRef, ToPolyTraitRef, TyCtxt, Upcast}; /// Given a [`PolyTraitRef`], get the [`Clause`]s implied by the trait's definition. /// @@ -11,7 +11,7 @@ pub fn super_predicates_for_pretty_printing<'tcx>( tcx: TyCtxt<'tcx>, trait_ref: PolyTraitRef<'tcx>, ) -> impl Iterator> { - let clause = trait_ref.to_predicate(tcx); + let clause = trait_ref.upcast(tcx); Elaborator { tcx, visited: FxHashSet::from_iter([clause]), stack: vec![clause] } } diff --git a/compiler/rustc_middle/src/ty/mod.rs b/compiler/rustc_middle/src/ty/mod.rs index 93ccc0a7de4..7d2c3ee2df8 100644 --- a/compiler/rustc_middle/src/ty/mod.rs +++ b/compiler/rustc_middle/src/ty/mod.rs @@ -102,7 +102,7 @@ pub use self::predicate::{ PolyExistentialTraitRef, PolyProjectionPredicate, PolyRegionOutlivesPredicate, PolySubtypePredicate, PolyTraitPredicate, PolyTraitRef, PolyTypeOutlivesPredicate, Predicate, PredicateKind, ProjectionPredicate, RegionOutlivesPredicate, SubtypePredicate, ToPolyTraitRef, - ToPredicate, TraitPredicate, TraitRef, TypeOutlivesPredicate, + TraitPredicate, TraitRef, TypeOutlivesPredicate, Upcast, }; pub use self::region::{ BoundRegion, BoundRegionKind, BoundRegionKind::*, EarlyParamRegion, LateParamRegion, Region, diff --git a/compiler/rustc_middle/src/ty/predicate.rs b/compiler/rustc_middle/src/ty/predicate.rs index 16ca098853e..41b016830d0 100644 --- a/compiler/rustc_middle/src/ty/predicate.rs +++ b/compiler/rustc_middle/src/ty/predicate.rs @@ -234,10 +234,10 @@ impl<'tcx> PolyExistentialPredicate<'tcx> { pub fn with_self_ty(&self, tcx: TyCtxt<'tcx>, self_ty: Ty<'tcx>) -> ty::Clause<'tcx> { match self.skip_binder() { ExistentialPredicate::Trait(tr) => { - self.rebind(tr).with_self_ty(tcx, self_ty).to_predicate(tcx) + self.rebind(tr).with_self_ty(tcx, self_ty).upcast(tcx) } ExistentialPredicate::Projection(p) => { - self.rebind(p.with_self_ty(tcx, self_ty)).to_predicate(tcx) + self.rebind(p.with_self_ty(tcx, self_ty)).upcast(tcx) } ExistentialPredicate::AutoTrait(did) => { let generics = tcx.generics_of(did); @@ -249,7 +249,7 @@ impl<'tcx> PolyExistentialPredicate<'tcx> { let err_args = ty::GenericArgs::extend_with_error(tcx, did, &[self_ty.into()]); ty::TraitRef::new(tcx, did, err_args) }; - self.rebind(trait_ref).to_predicate(tcx) + self.rebind(trait_ref).upcast(tcx) } } } @@ -544,106 +544,106 @@ impl<'tcx> ToPolyTraitRef<'tcx> for PolyTraitPredicate<'tcx> { } } -pub trait ToPredicate<'tcx, P = Predicate<'tcx>> { - fn to_predicate(self, tcx: TyCtxt<'tcx>) -> P; +pub trait Upcast<'tcx, P = Predicate<'tcx>> { + fn upcast(self, tcx: TyCtxt<'tcx>) -> P; } -impl<'tcx, T> ToPredicate<'tcx, T> for T { - fn to_predicate(self, _tcx: TyCtxt<'tcx>) -> T { +impl<'tcx, T> Upcast<'tcx, T> for T { + fn upcast(self, _tcx: TyCtxt<'tcx>) -> T { self } } -impl<'tcx> ToPredicate<'tcx> for PredicateKind<'tcx> { +impl<'tcx> Upcast<'tcx> for PredicateKind<'tcx> { #[inline(always)] - fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> { - ty::Binder::dummy(self).to_predicate(tcx) + fn upcast(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> { + ty::Binder::dummy(self).upcast(tcx) } } -impl<'tcx> ToPredicate<'tcx> for Binder<'tcx, PredicateKind<'tcx>> { +impl<'tcx> Upcast<'tcx> for Binder<'tcx, PredicateKind<'tcx>> { #[inline(always)] - fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> { + fn upcast(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> { tcx.mk_predicate(self) } } -impl<'tcx> ToPredicate<'tcx> for ClauseKind<'tcx> { +impl<'tcx> Upcast<'tcx> for ClauseKind<'tcx> { #[inline(always)] - fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> { + fn upcast(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> { tcx.mk_predicate(ty::Binder::dummy(ty::PredicateKind::Clause(self))) } } -impl<'tcx> ToPredicate<'tcx> for Binder<'tcx, ClauseKind<'tcx>> { +impl<'tcx> Upcast<'tcx> for Binder<'tcx, ClauseKind<'tcx>> { #[inline(always)] - fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> { + fn upcast(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> { tcx.mk_predicate(self.map_bound(ty::PredicateKind::Clause)) } } -impl<'tcx> ToPredicate<'tcx> for Clause<'tcx> { +impl<'tcx> Upcast<'tcx> for Clause<'tcx> { #[inline(always)] - fn to_predicate(self, _tcx: TyCtxt<'tcx>) -> Predicate<'tcx> { + fn upcast(self, _tcx: TyCtxt<'tcx>) -> Predicate<'tcx> { self.as_predicate() } } -impl<'tcx> ToPredicate<'tcx, Clause<'tcx>> for ClauseKind<'tcx> { +impl<'tcx> Upcast<'tcx, Clause<'tcx>> for ClauseKind<'tcx> { #[inline(always)] - fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Clause<'tcx> { + fn upcast(self, tcx: TyCtxt<'tcx>) -> Clause<'tcx> { tcx.mk_predicate(Binder::dummy(ty::PredicateKind::Clause(self))).expect_clause() } } -impl<'tcx> ToPredicate<'tcx, Clause<'tcx>> for Binder<'tcx, ClauseKind<'tcx>> { +impl<'tcx> Upcast<'tcx, Clause<'tcx>> for Binder<'tcx, ClauseKind<'tcx>> { #[inline(always)] - fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Clause<'tcx> { + fn upcast(self, tcx: TyCtxt<'tcx>) -> Clause<'tcx> { tcx.mk_predicate(self.map_bound(|clause| ty::PredicateKind::Clause(clause))).expect_clause() } } -impl<'tcx> ToPredicate<'tcx> for TraitRef<'tcx> { +impl<'tcx> Upcast<'tcx> for TraitRef<'tcx> { #[inline(always)] - fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> { - ty::Binder::dummy(self).to_predicate(tcx) + fn upcast(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> { + ty::Binder::dummy(self).upcast(tcx) } } -impl<'tcx> ToPredicate<'tcx, TraitPredicate<'tcx>> for TraitRef<'tcx> { +impl<'tcx> Upcast<'tcx, TraitPredicate<'tcx>> for TraitRef<'tcx> { #[inline(always)] - fn to_predicate(self, _tcx: TyCtxt<'tcx>) -> TraitPredicate<'tcx> { + fn upcast(self, _tcx: TyCtxt<'tcx>) -> TraitPredicate<'tcx> { TraitPredicate { trait_ref: self, polarity: PredicatePolarity::Positive } } } -impl<'tcx> ToPredicate<'tcx, Clause<'tcx>> for TraitRef<'tcx> { +impl<'tcx> Upcast<'tcx, Clause<'tcx>> for TraitRef<'tcx> { #[inline(always)] - fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Clause<'tcx> { - let p: Predicate<'tcx> = self.to_predicate(tcx); + fn upcast(self, tcx: TyCtxt<'tcx>) -> Clause<'tcx> { + let p: Predicate<'tcx> = self.upcast(tcx); p.expect_clause() } } -impl<'tcx> ToPredicate<'tcx> for Binder<'tcx, TraitRef<'tcx>> { +impl<'tcx> Upcast<'tcx> for Binder<'tcx, TraitRef<'tcx>> { #[inline(always)] - fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> { - let pred: PolyTraitPredicate<'tcx> = self.to_predicate(tcx); - pred.to_predicate(tcx) + fn upcast(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> { + let pred: PolyTraitPredicate<'tcx> = self.upcast(tcx); + pred.upcast(tcx) } } -impl<'tcx> ToPredicate<'tcx, Clause<'tcx>> for Binder<'tcx, TraitRef<'tcx>> { +impl<'tcx> Upcast<'tcx, Clause<'tcx>> for Binder<'tcx, TraitRef<'tcx>> { #[inline(always)] - fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Clause<'tcx> { - let pred: PolyTraitPredicate<'tcx> = self.to_predicate(tcx); - pred.to_predicate(tcx) + fn upcast(self, tcx: TyCtxt<'tcx>) -> Clause<'tcx> { + let pred: PolyTraitPredicate<'tcx> = self.upcast(tcx); + pred.upcast(tcx) } } -impl<'tcx> ToPredicate<'tcx, PolyTraitPredicate<'tcx>> for Binder<'tcx, TraitRef<'tcx>> { +impl<'tcx> Upcast<'tcx, PolyTraitPredicate<'tcx>> for Binder<'tcx, TraitRef<'tcx>> { #[inline(always)] - fn to_predicate(self, _: TyCtxt<'tcx>) -> PolyTraitPredicate<'tcx> { + fn upcast(self, _: TyCtxt<'tcx>) -> PolyTraitPredicate<'tcx> { self.map_bound(|trait_ref| TraitPredicate { trait_ref, polarity: ty::PredicatePolarity::Positive, @@ -651,73 +651,73 @@ impl<'tcx> ToPredicate<'tcx, PolyTraitPredicate<'tcx>> for Binder<'tcx, TraitRef } } -impl<'tcx> ToPredicate<'tcx> for TraitPredicate<'tcx> { - fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> { - PredicateKind::Clause(ClauseKind::Trait(self)).to_predicate(tcx) +impl<'tcx> Upcast<'tcx> for TraitPredicate<'tcx> { + fn upcast(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> { + PredicateKind::Clause(ClauseKind::Trait(self)).upcast(tcx) } } -impl<'tcx> ToPredicate<'tcx> for PolyTraitPredicate<'tcx> { - fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> { - self.map_bound(|p| PredicateKind::Clause(ClauseKind::Trait(p))).to_predicate(tcx) +impl<'tcx> Upcast<'tcx> for PolyTraitPredicate<'tcx> { + fn upcast(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> { + self.map_bound(|p| PredicateKind::Clause(ClauseKind::Trait(p))).upcast(tcx) } } -impl<'tcx> ToPredicate<'tcx, Clause<'tcx>> for TraitPredicate<'tcx> { - fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Clause<'tcx> { - let p: Predicate<'tcx> = self.to_predicate(tcx); +impl<'tcx> Upcast<'tcx, Clause<'tcx>> for TraitPredicate<'tcx> { + fn upcast(self, tcx: TyCtxt<'tcx>) -> Clause<'tcx> { + let p: Predicate<'tcx> = self.upcast(tcx); p.expect_clause() } } -impl<'tcx> ToPredicate<'tcx, Clause<'tcx>> for PolyTraitPredicate<'tcx> { - fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Clause<'tcx> { - let p: Predicate<'tcx> = self.to_predicate(tcx); +impl<'tcx> Upcast<'tcx, Clause<'tcx>> for PolyTraitPredicate<'tcx> { + fn upcast(self, tcx: TyCtxt<'tcx>) -> Clause<'tcx> { + let p: Predicate<'tcx> = self.upcast(tcx); p.expect_clause() } } -impl<'tcx> ToPredicate<'tcx> for PolyRegionOutlivesPredicate<'tcx> { - fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> { - self.map_bound(|p| PredicateKind::Clause(ClauseKind::RegionOutlives(p))).to_predicate(tcx) +impl<'tcx> Upcast<'tcx> for PolyRegionOutlivesPredicate<'tcx> { + fn upcast(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> { + self.map_bound(|p| PredicateKind::Clause(ClauseKind::RegionOutlives(p))).upcast(tcx) } } -impl<'tcx> ToPredicate<'tcx> for OutlivesPredicate, ty::Region<'tcx>> { - fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> { - ty::Binder::dummy(PredicateKind::Clause(ClauseKind::TypeOutlives(self))).to_predicate(tcx) +impl<'tcx> Upcast<'tcx> for OutlivesPredicate, ty::Region<'tcx>> { + fn upcast(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> { + ty::Binder::dummy(PredicateKind::Clause(ClauseKind::TypeOutlives(self))).upcast(tcx) } } -impl<'tcx> ToPredicate<'tcx> for ProjectionPredicate<'tcx> { - fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> { - ty::Binder::dummy(PredicateKind::Clause(ClauseKind::Projection(self))).to_predicate(tcx) +impl<'tcx> Upcast<'tcx> for ProjectionPredicate<'tcx> { + fn upcast(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> { + ty::Binder::dummy(PredicateKind::Clause(ClauseKind::Projection(self))).upcast(tcx) } } -impl<'tcx> ToPredicate<'tcx> for PolyProjectionPredicate<'tcx> { - fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> { - self.map_bound(|p| PredicateKind::Clause(ClauseKind::Projection(p))).to_predicate(tcx) +impl<'tcx> Upcast<'tcx> for PolyProjectionPredicate<'tcx> { + fn upcast(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> { + self.map_bound(|p| PredicateKind::Clause(ClauseKind::Projection(p))).upcast(tcx) } } -impl<'tcx> ToPredicate<'tcx, Clause<'tcx>> for ProjectionPredicate<'tcx> { - fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Clause<'tcx> { - let p: Predicate<'tcx> = self.to_predicate(tcx); +impl<'tcx> Upcast<'tcx, Clause<'tcx>> for ProjectionPredicate<'tcx> { + fn upcast(self, tcx: TyCtxt<'tcx>) -> Clause<'tcx> { + let p: Predicate<'tcx> = self.upcast(tcx); p.expect_clause() } } -impl<'tcx> ToPredicate<'tcx, Clause<'tcx>> for PolyProjectionPredicate<'tcx> { - fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Clause<'tcx> { - let p: Predicate<'tcx> = self.to_predicate(tcx); +impl<'tcx> Upcast<'tcx, Clause<'tcx>> for PolyProjectionPredicate<'tcx> { + fn upcast(self, tcx: TyCtxt<'tcx>) -> Clause<'tcx> { + let p: Predicate<'tcx> = self.upcast(tcx); p.expect_clause() } } -impl<'tcx> ToPredicate<'tcx> for NormalizesTo<'tcx> { - fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> { - PredicateKind::NormalizesTo(self).to_predicate(tcx) +impl<'tcx> Upcast<'tcx> for NormalizesTo<'tcx> { + fn upcast(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> { + PredicateKind::NormalizesTo(self).upcast(tcx) } } diff --git a/compiler/rustc_middle/src/ty/util.rs b/compiler/rustc_middle/src/ty/util.rs index 7f3d6a713d9..8c14f1e080a 100644 --- a/compiler/rustc_middle/src/ty/util.rs +++ b/compiler/rustc_middle/src/ty/util.rs @@ -4,8 +4,8 @@ use crate::middle::codegen_fn_attrs::CodegenFnAttrFlags; use crate::query::{IntoQueryParam, Providers}; use crate::ty::layout::{FloatExt, IntegerExt}; use crate::ty::{ - self, FallibleTypeFolder, ToPredicate, Ty, TyCtxt, TypeFoldable, TypeFolder, TypeSuperFoldable, - TypeVisitableExt, + self, FallibleTypeFolder, Ty, TyCtxt, TypeFoldable, TypeFolder, TypeSuperFoldable, + TypeVisitableExt, Upcast, }; use crate::ty::{GenericArgKind, GenericArgsRef}; use rustc_apfloat::Float as _; @@ -1094,7 +1094,7 @@ impl<'tcx> TypeFolder> for OpaqueTypeExpander<'tcx> { // anything that requires `ParamEnv::with_reveal_all_normalized`. term: projection_pred.term, }) - .to_predicate(self.tcx) + .upcast(self.tcx) } else { p.super_fold_with(self) } diff --git a/compiler/rustc_trait_selection/src/infer.rs b/compiler/rustc_trait_selection/src/infer.rs index 3dc55509dad..6797be5cdd0 100644 --- a/compiler/rustc_trait_selection/src/infer.rs +++ b/compiler/rustc_trait_selection/src/infer.rs @@ -10,7 +10,7 @@ use rustc_middle::infer::canonical::{Canonical, CanonicalQueryResponse, QueryRes use rustc_middle::traits::query::NoSolution; use rustc_middle::traits::ObligationCause; use rustc_middle::ty::{self, Ty, TyCtxt, TypeFoldable, TypeVisitableExt}; -use rustc_middle::ty::{GenericArg, ToPredicate}; +use rustc_middle::ty::{GenericArg, Upcast}; use rustc_span::DUMMY_SP; use std::fmt::Debug; @@ -63,7 +63,7 @@ impl<'tcx> InferCtxt<'tcx> { cause: traits::ObligationCause::dummy(), param_env, recursion_depth: 0, - predicate: ty::Binder::dummy(trait_ref).to_predicate(self.tcx), + predicate: ty::Binder::dummy(trait_ref).upcast(self.tcx), }; self.evaluate_obligation(&obligation).unwrap_or(traits::EvaluationResult::EvaluatedToErr) } diff --git a/compiler/rustc_trait_selection/src/solve/assembly/mod.rs b/compiler/rustc_trait_selection/src/solve/assembly/mod.rs index 97bea28f06a..e09ddc7fb5e 100644 --- a/compiler/rustc_trait_selection/src/solve/assembly/mod.rs +++ b/compiler/rustc_trait_selection/src/solve/assembly/mod.rs @@ -13,7 +13,7 @@ use rustc_middle::traits::BuiltinImplSource; use rustc_middle::ty::fast_reject::{SimplifiedType, TreatParams}; use rustc_middle::ty::{self, Ty, TyCtxt}; use rustc_middle::ty::{fast_reject, TypeFoldable}; -use rustc_middle::ty::{ToPredicate, TypeVisitableExt}; +use rustc_middle::ty::{TypeVisitableExt, Upcast}; use rustc_span::{ErrorGuaranteed, DUMMY_SP}; use std::fmt::Debug; @@ -744,7 +744,7 @@ impl<'tcx> EvalCtxt<'_, 'tcx> { ecx, CandidateSource::BuiltinImpl(BuiltinImplSource::Object { vtable_base }), goal, - assumption.to_predicate(tcx), + assumption.upcast(tcx), )); }); } diff --git a/compiler/rustc_trait_selection/src/solve/assembly/structural_traits.rs b/compiler/rustc_trait_selection/src/solve/assembly/structural_traits.rs index 9e844d78702..cf826596392 100644 --- a/compiler/rustc_trait_selection/src/solve/assembly/structural_traits.rs +++ b/compiler/rustc_trait_selection/src/solve/assembly/structural_traits.rs @@ -7,9 +7,7 @@ use rustc_infer::traits::query::NoSolution; use rustc_macros::{TypeFoldable, TypeVisitable}; use rustc_middle::bug; use rustc_middle::traits::solve::Goal; -use rustc_middle::ty::{ - self, ToPredicate, Ty, TyCtxt, TypeFoldable, TypeFolder, TypeSuperFoldable, -}; +use rustc_middle::ty::{self, Ty, TyCtxt, TypeFoldable, TypeFolder, TypeSuperFoldable, Upcast}; use rustc_span::sym; use crate::solve::EvalCtxt; @@ -429,7 +427,7 @@ pub(in crate::solve) fn extract_tupled_inputs_and_output_from_async_callable<'tc tcx.require_lang_item(LangItem::AsyncFnKindHelper, None), [kind_ty, Ty::from_closure_kind(tcx, goal_kind)], ) - .to_predicate(tcx), + .upcast(tcx), ); coroutine_closure_to_ambiguous_coroutine( @@ -456,7 +454,7 @@ pub(in crate::solve) fn extract_tupled_inputs_and_output_from_async_callable<'tc let nested = vec![ bound_sig .rebind(ty::TraitRef::new(tcx, future_trait_def_id, [sig.output()])) - .to_predicate(tcx), + .upcast(tcx), ]; let future_output_def_id = tcx .associated_items(future_trait_def_id) @@ -484,7 +482,7 @@ pub(in crate::solve) fn extract_tupled_inputs_and_output_from_async_callable<'tc let mut nested = vec![ bound_sig .rebind(ty::TraitRef::new(tcx, future_trait_def_id, [sig.output()])) - .to_predicate(tcx), + .upcast(tcx), ]; // Additionally, we need to check that the closure kind @@ -510,7 +508,7 @@ pub(in crate::solve) fn extract_tupled_inputs_and_output_from_async_callable<'tc async_fn_kind_trait_def_id, [kind_ty, Ty::from_closure_kind(tcx, goal_kind)], ) - .to_predicate(tcx), + .upcast(tcx), ); } diff --git a/compiler/rustc_trait_selection/src/solve/normalizes_to/mod.rs b/compiler/rustc_trait_selection/src/solve/normalizes_to/mod.rs index 6ec0ad9d29a..7ab27374e7a 100644 --- a/compiler/rustc_trait_selection/src/solve/normalizes_to/mod.rs +++ b/compiler/rustc_trait_selection/src/solve/normalizes_to/mod.rs @@ -16,7 +16,7 @@ use rustc_middle::traits::BuiltinImplSource; use rustc_middle::ty::fast_reject::{DeepRejectCtxt, TreatParams}; use rustc_middle::ty::NormalizesTo; use rustc_middle::ty::{self, Ty, TyCtxt}; -use rustc_middle::ty::{ToPredicate, TypeVisitableExt}; +use rustc_middle::ty::{TypeVisitableExt, Upcast}; use rustc_middle::{bug, span_bug}; use rustc_span::{sym, ErrorGuaranteed, DUMMY_SP}; @@ -370,7 +370,7 @@ impl<'tcx> assembly::GoalKind<'tcx> for NormalizesTo<'tcx> { ), term: output.into(), }) - .to_predicate(tcx); + .upcast(tcx); // A built-in `Fn` impl only holds if the output is sized. // (FIXME: technically we only need to check this if the type is a fn ptr...) @@ -452,7 +452,7 @@ impl<'tcx> assembly::GoalKind<'tcx> for NormalizesTo<'tcx> { ty::ProjectionPredicate { projection_term, term } }, ) - .to_predicate(tcx); + .upcast(tcx); // A built-in `AsyncFn` impl only holds if the output is sized. // (FIXME: technically we only need to check this if the type is a fn ptr...) @@ -629,7 +629,7 @@ impl<'tcx> assembly::GoalKind<'tcx> for NormalizesTo<'tcx> { projection_term: ty::AliasTerm::new(ecx.tcx(), goal.predicate.def_id(), [self_ty]), term, } - .to_predicate(tcx), + .upcast(tcx), // Technically, we need to check that the future type is Sized, // but that's already proven by the coroutine being WF. [], @@ -661,7 +661,7 @@ impl<'tcx> assembly::GoalKind<'tcx> for NormalizesTo<'tcx> { projection_term: ty::AliasTerm::new(ecx.tcx(), goal.predicate.def_id(), [self_ty]), term, } - .to_predicate(tcx), + .upcast(tcx), // Technically, we need to check that the iterator type is Sized, // but that's already proven by the generator being WF. [], @@ -749,7 +749,7 @@ impl<'tcx> assembly::GoalKind<'tcx> for NormalizesTo<'tcx> { ), term, } - .to_predicate(tcx), + .upcast(tcx), // Technically, we need to check that the coroutine type is Sized, // but that's already proven by the coroutine being WF. [], diff --git a/compiler/rustc_trait_selection/src/solve/trait_goals.rs b/compiler/rustc_trait_selection/src/solve/trait_goals.rs index 1cafa970b68..b46edb32f72 100644 --- a/compiler/rustc_trait_selection/src/solve/trait_goals.rs +++ b/compiler/rustc_trait_selection/src/solve/trait_goals.rs @@ -15,7 +15,7 @@ use rustc_middle::traits::solve::inspect::ProbeKind; use rustc_middle::traits::solve::{CandidateSource, Certainty, Goal, QueryResult}; use rustc_middle::traits::{BuiltinImplSource, Reveal}; use rustc_middle::ty::fast_reject::{DeepRejectCtxt, TreatParams}; -use rustc_middle::ty::{self, ToPredicate, Ty, TyCtxt}; +use rustc_middle::ty::{self, Ty, TyCtxt, Upcast}; use rustc_middle::ty::{TraitPredicate, TypeVisitableExt}; use rustc_span::ErrorGuaranteed; @@ -315,7 +315,7 @@ impl<'tcx> assembly::GoalKind<'tcx> for TraitPredicate<'tcx> { .map_bound(|(inputs, _)| { ty::TraitRef::new(tcx, goal.predicate.def_id(), [goal.predicate.self_ty(), inputs]) }) - .to_predicate(tcx); + .upcast(tcx); // A built-in `Fn` impl only holds if the output is sized. // (FIXME: technically we only need to check this if the type is a fn ptr...) Self::probe_and_consider_implied_clause( @@ -363,7 +363,7 @@ impl<'tcx> assembly::GoalKind<'tcx> for TraitPredicate<'tcx> { [goal.predicate.self_ty(), tupled_inputs_ty], ) }) - .to_predicate(tcx); + .upcast(tcx); // A built-in `AsyncFn` impl only holds if the output is sized. // (FIXME: technically we only need to check this if the type is a fn ptr...) Self::probe_and_consider_implied_clause( @@ -560,7 +560,7 @@ impl<'tcx> assembly::GoalKind<'tcx> for TraitPredicate<'tcx> { CandidateSource::BuiltinImpl(BuiltinImplSource::Misc), goal, ty::TraitRef::new(tcx, goal.predicate.def_id(), [self_ty, coroutine.resume_ty()]) - .to_predicate(tcx), + .upcast(tcx), // Technically, we need to check that the coroutine types are Sized, // but that's already proven by the coroutine being WF. [], diff --git a/compiler/rustc_trait_selection/src/traits/auto_trait.rs b/compiler/rustc_trait_selection/src/traits/auto_trait.rs index 60562acfe93..1ea207cc375 100644 --- a/compiler/rustc_trait_selection/src/traits/auto_trait.rs +++ b/compiler/rustc_trait_selection/src/traits/auto_trait.rs @@ -303,7 +303,7 @@ impl<'tcx> AutoTraitFinder<'tcx> { Err(SelectionError::Unimplemented) => { if self.is_param_no_infer(pred.skip_binder().trait_ref.args) { already_visited.remove(&pred); - self.add_user_pred(&mut user_computed_preds, pred.to_predicate(self.tcx)); + self.add_user_pred(&mut user_computed_preds, pred.upcast(self.tcx)); predicates.push_back(pred); } else { debug!( diff --git a/compiler/rustc_trait_selection/src/traits/engine.rs b/compiler/rustc_trait_selection/src/traits/engine.rs index 551c8e7702e..ad56b8f329b 100644 --- a/compiler/rustc_trait_selection/src/traits/engine.rs +++ b/compiler/rustc_trait_selection/src/traits/engine.rs @@ -25,8 +25,8 @@ use rustc_macros::extension; use rustc_middle::arena::ArenaAllocatable; use rustc_middle::traits::query::NoSolution; use rustc_middle::ty::error::TypeError; -use rustc_middle::ty::ToPredicate; use rustc_middle::ty::TypeFoldable; +use rustc_middle::ty::Upcast; use rustc_middle::ty::Variance; use rustc_middle::ty::{self, Ty, TyCtxt}; @@ -96,7 +96,7 @@ impl<'a, 'tcx> ObligationCtxt<'a, 'tcx> { cause, recursion_depth: 0, param_env, - predicate: ty::Binder::dummy(trait_ref).to_predicate(tcx), + predicate: ty::Binder::dummy(trait_ref).upcast(tcx), }); } diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs index 86610855441..921275100d2 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs @@ -31,8 +31,8 @@ use rustc_middle::traits::IsConstable; use rustc_middle::ty::error::TypeError::{self, Sorts}; use rustc_middle::ty::{ self, suggest_arbitrary_trait_bound, suggest_constraining_type_param, AdtKind, GenericArgs, - InferTy, IsSuggestable, ToPredicate, Ty, TyCtxt, TypeFoldable, TypeFolder, TypeSuperFoldable, - TypeVisitableExt, TypeckResults, + InferTy, IsSuggestable, Ty, TyCtxt, TypeFoldable, TypeFolder, TypeSuperFoldable, + TypeVisitableExt, TypeckResults, Upcast, }; use rustc_middle::{bug, span_bug}; use rustc_span::def_id::LocalDefId; @@ -192,7 +192,7 @@ pub fn suggest_restriction<'tcx, G: EmissionGuarantee>( }, // `fn foo(t: impl Trait)` // ^ suggest `where ::A: Bound` - predicate_constraint(hir_generics, trait_pred.to_predicate(tcx)), + predicate_constraint(hir_generics, trait_pred.upcast(tcx)), ]; sugg.extend(ty_spans.into_iter().map(|s| (s, type_param_name.to_string()))); @@ -215,7 +215,7 @@ pub fn suggest_restriction<'tcx, G: EmissionGuarantee>( .find(|p| !matches!(p.kind, hir::GenericParamKind::Type { synthetic: true, .. })), super_traits, ) { - (_, None) => predicate_constraint(hir_generics, trait_pred.to_predicate(tcx)), + (_, None) => predicate_constraint(hir_generics, trait_pred.upcast(tcx)), (None, Some((ident, []))) => ( ident.span.shrink_to_hi(), format!(": {}", trait_pred.print_modifiers_and_trait_path()), @@ -2703,12 +2703,12 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { obligated_types: &mut Vec>, seen_requirements: &mut FxHashSet, ) where - T: ToPredicate<'tcx>, + T: Upcast<'tcx>, { let mut long_ty_file = None; let tcx = self.tcx; - let predicate = predicate.to_predicate(tcx); + let predicate = predicate.upcast(tcx); match *cause_code { ObligationCauseCode::ExprAssignable | ObligationCauseCode::MatchExpressionArm { .. } @@ -3378,7 +3378,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { break; } data = derived; - parent_predicate = child_trait_ref.to_predicate(tcx); + parent_predicate = child_trait_ref.upcast(tcx); parent_trait_pred = child_trait_ref; } } @@ -3392,7 +3392,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { } count += 1; data = &child.derived; - parent_predicate = child_trait_pred.to_predicate(tcx); + parent_predicate = child_trait_pred.upcast(tcx); parent_trait_pred = child_trait_pred; } if count > 0 { diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/type_err_ctxt_ext.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/type_err_ctxt_ext.rs index f9824acdae0..e3e3e30ff92 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/type_err_ctxt_ext.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/type_err_ctxt_ext.rs @@ -42,8 +42,8 @@ use rustc_middle::ty::print::{ PrintTraitRefExt as _, }; use rustc_middle::ty::{ - self, SubtypePredicate, ToPolyTraitRef, ToPredicate, TraitRef, Ty, TyCtxt, TypeFoldable, - TypeVisitable, TypeVisitableExt, + self, SubtypePredicate, ToPolyTraitRef, TraitRef, Ty, TyCtxt, TypeFoldable, TypeVisitable, + TypeVisitableExt, Upcast, }; use rustc_middle::{bug, span_bug}; use rustc_session::config::DumpSolverProofTree; @@ -302,9 +302,9 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { suggest_increasing_limit: bool, ) -> ! where - T: ToPredicate<'tcx> + Clone, + T: Upcast<'tcx> + Clone, { - let predicate = obligation.predicate.clone().to_predicate(self.tcx); + let predicate = obligation.predicate.clone().upcast(self.tcx); let predicate = self.resolve_vars_if_possible(predicate); self.report_overflow_error( OverflowCause::TraitSolver(predicate), diff --git a/compiler/rustc_trait_selection/src/traits/mod.rs b/compiler/rustc_trait_selection/src/traits/mod.rs index 61f47bc1f23..7dd944ba850 100644 --- a/compiler/rustc_trait_selection/src/traits/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/mod.rs @@ -34,7 +34,7 @@ use rustc_middle::query::Providers; use rustc_middle::span_bug; use rustc_middle::ty::fold::TypeFoldable; use rustc_middle::ty::visit::{TypeVisitable, TypeVisitableExt}; -use rustc_middle::ty::{self, ToPredicate, Ty, TyCtxt, TypeFolder, TypeSuperVisitable}; +use rustc_middle::ty::{self, Ty, TyCtxt, TypeFolder, TypeSuperVisitable, Upcast}; use rustc_middle::ty::{GenericArgs, GenericArgsRef}; use rustc_span::def_id::DefId; use rustc_span::Span; @@ -142,7 +142,7 @@ pub fn type_known_to_meet_bound_modulo_regions<'tcx>( fn pred_known_to_hold_modulo_regions<'tcx>( infcx: &InferCtxt<'tcx>, param_env: ty::ParamEnv<'tcx>, - pred: impl ToPredicate<'tcx>, + pred: impl Upcast<'tcx>, ) -> bool { let obligation = Obligation::new(infcx.tcx, ObligationCause::dummy(), param_env, pred); @@ -457,7 +457,7 @@ fn instantiate_and_check_impossible_predicates<'tcx>( // associated items. if let Some(trait_def_id) = tcx.trait_of_item(key.0) { let trait_ref = ty::TraitRef::from_method(tcx, trait_def_id, key.1); - predicates.push(ty::Binder::dummy(trait_ref).to_predicate(tcx)); + predicates.push(ty::Binder::dummy(trait_ref).upcast(tcx)); } predicates.retain(|predicate| !predicate.has_param()); diff --git a/compiler/rustc_trait_selection/src/traits/object_safety.rs b/compiler/rustc_trait_selection/src/traits/object_safety.rs index 41080b3d9d3..9402fb417a6 100644 --- a/compiler/rustc_trait_selection/src/traits/object_safety.rs +++ b/compiler/rustc_trait_selection/src/traits/object_safety.rs @@ -22,7 +22,7 @@ use rustc_middle::ty::{ TypeVisitable, TypeVisitor, }; use rustc_middle::ty::{GenericArg, GenericArgs}; -use rustc_middle::ty::{ToPredicate, TypeVisitableExt}; +use rustc_middle::ty::{TypeVisitableExt, Upcast}; use rustc_session::lint::builtin::WHERE_CLAUSES_OBJECT_SAFETY; use rustc_span::symbol::Symbol; use rustc_span::Span; @@ -649,7 +649,7 @@ fn object_ty_for_trait<'tcx>( )); debug!(?trait_predicate); - let pred: ty::Predicate<'tcx> = trait_ref.to_predicate(tcx); + let pred: ty::Predicate<'tcx> = trait_ref.upcast(tcx); let mut elaborated_predicates: Vec<_> = elaborate(tcx, [pred]) .filter_map(|pred| { debug!(?pred); @@ -753,7 +753,7 @@ fn receiver_is_dispatchable<'tcx>( // Self: Unsize let unsize_predicate = ty::TraitRef::new(tcx, unsize_did, [tcx.types.self_param, unsized_self_ty]) - .to_predicate(tcx); + .upcast(tcx); // U: Trait let trait_predicate = { @@ -762,7 +762,7 @@ fn receiver_is_dispatchable<'tcx>( if param.index == 0 { unsized_self_ty.into() } else { tcx.mk_param_from_def(param) } }); - ty::TraitRef::new(tcx, trait_def_id, args).to_predicate(tcx) + ty::TraitRef::new(tcx, trait_def_id, args).upcast(tcx) }; let caller_bounds = diff --git a/compiler/rustc_trait_selection/src/traits/project.rs b/compiler/rustc_trait_selection/src/traits/project.rs index 2e7d2790dc3..c5590cbf4ef 100644 --- a/compiler/rustc_trait_selection/src/traits/project.rs +++ b/compiler/rustc_trait_selection/src/traits/project.rs @@ -35,7 +35,7 @@ use rustc_infer::infer::DefineOpaqueTypes; use rustc_middle::traits::select::OverflowError; use rustc_middle::ty::fold::TypeFoldable; use rustc_middle::ty::visit::{MaxUniverse, TypeVisitable, TypeVisitableExt}; -use rustc_middle::ty::{self, Term, ToPredicate, Ty, TyCtxt}; +use rustc_middle::ty::{self, Term, Ty, TyCtxt, Upcast}; use rustc_span::symbol::sym; pub use rustc_middle::traits::Reveal; @@ -538,7 +538,7 @@ fn normalize_to_error<'a, 'tcx>( cause, recursion_depth: depth, param_env, - predicate: trait_ref.to_predicate(selcx.tcx()), + predicate: trait_ref.upcast(selcx.tcx()), }; Normalized { value: new_value, obligations: vec![trait_obligation] } } @@ -877,7 +877,7 @@ fn assemble_candidates_from_object_ty<'cx, 'tcx>( let env_predicates = data .projection_bounds() .filter(|bound| bound.item_def_id() == obligation.predicate.def_id) - .map(|p| p.with_self_ty(tcx, object_ty).to_predicate(tcx)); + .map(|p| p.with_self_ty(tcx, object_ty).upcast(tcx)); assemble_candidates_from_predicates( selcx, diff --git a/compiler/rustc_trait_selection/src/traits/select/confirmation.rs b/compiler/rustc_trait_selection/src/traits/select/confirmation.rs index 24c6951a014..27bdc1da7df 100644 --- a/compiler/rustc_trait_selection/src/traits/select/confirmation.rs +++ b/compiler/rustc_trait_selection/src/traits/select/confirmation.rs @@ -14,8 +14,8 @@ use rustc_infer::infer::{DefineOpaqueTypes, InferOk}; use rustc_infer::traits::ObligationCauseCode; use rustc_middle::traits::{BuiltinImplSource, SignatureMismatchData}; use rustc_middle::ty::{ - self, GenericArgs, GenericArgsRef, GenericParamDefKind, ToPolyTraitRef, ToPredicate, - TraitPredicate, Ty, TyCtxt, + self, GenericArgs, GenericArgsRef, GenericParamDefKind, ToPolyTraitRef, TraitPredicate, Ty, + TyCtxt, Upcast, }; use rustc_middle::{bug, span_bug}; use rustc_span::def_id::DefId; @@ -676,7 +676,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { let assoc_ty_args = tcx.mk_args(&args); let bound = bound.map_bound(|b| b.kind().skip_binder()).instantiate(tcx, assoc_ty_args); - ty::Binder::bind_with_vars(bound, bound_vars).to_predicate(tcx) + ty::Binder::bind_with_vars(bound, bound_vars).upcast(tcx) }; let normalized_bound = normalize_with_depth_to( self, @@ -1253,13 +1253,13 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { tcx.require_lang_item(LangItem::Sized, Some(obligation.cause.span)), [source], ); - nested.push(predicate_to_obligation(tr.to_predicate(tcx))); + nested.push(predicate_to_obligation(tr.upcast(tcx))); // If the type is `Foo + 'a`, ensure that the type // being cast to `Foo + 'a` outlives `'a`: let outlives = ty::OutlivesPredicate(source, r); nested.push(predicate_to_obligation( - ty::Binder::dummy(ty::ClauseKind::TypeOutlives(outlives)).to_predicate(tcx), + ty::Binder::dummy(ty::ClauseKind::TypeOutlives(outlives)).upcast(tcx), )); ImplSource::Builtin(BuiltinImplSource::Misc, nested) diff --git a/compiler/rustc_trait_selection/src/traits/select/mod.rs b/compiler/rustc_trait_selection/src/traits/select/mod.rs index 5b25c62689f..501d6f6fd8f 100644 --- a/compiler/rustc_trait_selection/src/traits/select/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/select/mod.rs @@ -45,7 +45,7 @@ use rustc_middle::ty::abstract_const::NotConstEvaluatable; use rustc_middle::ty::print::PrintTraitRefExt as _; use rustc_middle::ty::relate::TypeRelation; use rustc_middle::ty::GenericArgsRef; -use rustc_middle::ty::{self, PolyProjectionPredicate, ToPredicate}; +use rustc_middle::ty::{self, PolyProjectionPredicate, Upcast}; use rustc_middle::ty::{Ty, TyCtxt, TypeFoldable, TypeVisitableExt}; use rustc_span::symbol::sym; use rustc_span::Symbol; @@ -740,7 +740,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { let cycle = stack.iter().take_while(|s| s.depth > stack_arg.1); let tcx = self.tcx(); let cycle = - cycle.map(|stack| stack.obligation.predicate.to_predicate(tcx)); + cycle.map(|stack| stack.obligation.predicate.upcast(tcx)); if self.coinductive_match(cycle) { stack.update_reached_depth(stack_arg.1); return Ok(EvaluatedToOk); @@ -1174,7 +1174,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { // if the regions match exactly. let cycle = stack.iter().skip(1).take_while(|s| s.depth >= cycle_depth); let tcx = self.tcx(); - let cycle = cycle.map(|stack| stack.obligation.predicate.to_predicate(tcx)); + let cycle = cycle.map(|stack| stack.obligation.predicate.upcast(tcx)); if self.coinductive_match(cycle) { debug!("evaluate_stack --> recursive, coinductive"); Some(EvaluatedToOk) @@ -1379,7 +1379,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { error_obligation: &Obligation<'tcx, T>, ) -> Result<(), OverflowError> where - T: ToPredicate<'tcx> + Clone, + T: Upcast<'tcx> + Clone, { if !self.infcx.tcx.recursion_limit().value_within_limit(depth) { match self.query_mode { @@ -1408,7 +1408,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { error_obligation: &Obligation<'tcx, V>, ) -> Result<(), OverflowError> where - V: ToPredicate<'tcx> + Clone, + V: Upcast<'tcx> + Clone, { self.check_recursion_depth(obligation.recursion_depth, error_obligation) } diff --git a/compiler/rustc_trait_selection/src/traits/util.rs b/compiler/rustc_trait_selection/src/traits/util.rs index 83edddb9a96..445fa1761b9 100644 --- a/compiler/rustc_trait_selection/src/traits/util.rs +++ b/compiler/rustc_trait_selection/src/traits/util.rs @@ -8,7 +8,7 @@ use rustc_hir::def_id::DefId; use rustc_infer::infer::{InferCtxt, InferOk}; use rustc_middle::bug; use rustc_middle::ty::GenericArgsRef; -use rustc_middle::ty::{self, ImplSubject, ToPredicate, Ty, TyCtxt, TypeVisitableExt}; +use rustc_middle::ty::{self, ImplSubject, Ty, TyCtxt, TypeVisitableExt, Upcast}; use rustc_middle::ty::{TypeFoldable, TypeFolder, TypeSuperFoldable}; use rustc_span::Span; use smallvec::{smallvec, SmallVec}; @@ -105,7 +105,7 @@ impl<'tcx> TraitAliasExpander<'tcx> { fn expand(&mut self, item: &TraitAliasExpansionInfo<'tcx>) -> bool { let tcx = self.tcx; let trait_ref = item.trait_ref(); - let pred = trait_ref.to_predicate(tcx); + let pred = trait_ref.upcast(tcx); debug!("expand_trait_aliases: trait_ref={:?}", trait_ref); @@ -122,7 +122,7 @@ impl<'tcx> TraitAliasExpander<'tcx> { .iter() .rev() .skip(1) - .any(|&(tr, _)| anonymize_predicate(tcx, tr.to_predicate(tcx)) == anon_pred) + .any(|&(tr, _)| anonymize_predicate(tcx, tr.upcast(tcx)) == anon_pred) { return false; } diff --git a/compiler/rustc_trait_selection/src/traits/vtable.rs b/compiler/rustc_trait_selection/src/traits/vtable.rs index 8fd9889b4ea..c93ec43944a 100644 --- a/compiler/rustc_trait_selection/src/traits/vtable.rs +++ b/compiler/rustc_trait_selection/src/traits/vtable.rs @@ -9,7 +9,7 @@ use rustc_middle::query::Providers; use rustc_middle::traits::BuiltinImplSource; use rustc_middle::ty::visit::TypeVisitableExt; use rustc_middle::ty::GenericArgs; -use rustc_middle::ty::{self, GenericParamDefKind, ToPredicate, Ty, TyCtxt, VtblEntry}; +use rustc_middle::ty::{self, GenericParamDefKind, Ty, TyCtxt, Upcast, VtblEntry}; use rustc_span::{sym, Span}; use smallvec::{smallvec, SmallVec}; @@ -87,7 +87,7 @@ fn prepare_vtable_segments_inner<'tcx, T>( let mut emit_vptr_on_new_entry = false; let mut visited = PredicateSet::new(tcx); - let predicate = trait_ref.to_predicate(tcx); + let predicate = trait_ref.upcast(tcx); let mut stack: SmallVec<[(ty::PolyTraitRef<'tcx>, _, _); 5]> = smallvec![(trait_ref, emit_vptr_on_new_entry, maybe_iter(None))]; visited.insert(predicate); @@ -130,7 +130,7 @@ fn prepare_vtable_segments_inner<'tcx, T>( // Find an unvisited supertrait match direct_super_traits_iter - .find(|&super_trait| visited.insert(super_trait.to_predicate(tcx))) + .find(|&super_trait| visited.insert(super_trait.upcast(tcx))) { // Push it to the stack for the next iteration of 'diving_in to pick up Some(unvisited_super_trait) => { @@ -165,7 +165,7 @@ fn prepare_vtable_segments_inner<'tcx, T>( } if let Some(next_inner_most_trait_ref) = - siblings.find(|&sibling| visited.insert(sibling.to_predicate(tcx))) + siblings.find(|&sibling| visited.insert(sibling.upcast(tcx))) { // We're throwing away potential constness of super traits here. // FIXME: handle ~const super traits diff --git a/compiler/rustc_ty_utils/src/ty.rs b/compiler/rustc_ty_utils/src/ty.rs index 492cc1d55cb..3094956fa5f 100644 --- a/compiler/rustc_ty_utils/src/ty.rs +++ b/compiler/rustc_ty_utils/src/ty.rs @@ -6,7 +6,7 @@ use rustc_index::bit_set::BitSet; use rustc_middle::bug; use rustc_middle::query::Providers; use rustc_middle::ty::{self, EarlyBinder, Ty, TyCtxt, TypeVisitableExt, TypeVisitor}; -use rustc_middle::ty::{ToPredicate, TypeSuperVisitable, TypeVisitable}; +use rustc_middle::ty::{TypeSuperVisitable, TypeVisitable, Upcast}; use rustc_span::def_id::{DefId, LocalDefId, CRATE_DEF_ID}; use rustc_span::DUMMY_SP; use rustc_trait_selection::traits; @@ -220,7 +220,7 @@ impl<'tcx> TypeVisitor> for ImplTraitInTraitFinder<'_, 'tcx> { }, self.bound_vars, ) - .to_predicate(self.tcx), + .upcast(self.tcx), ); // We walk the *un-shifted* alias ty, because we're tracking the de bruijn