Rename ToPredicate for Upcast

This commit is contained in:
Michael Goulet 2024-05-15 10:05:25 -04:00
parent 97bf25c8cf
commit 11ec3eca74
44 changed files with 214 additions and 220 deletions

View file

@ -24,8 +24,8 @@ use rustc_middle::mir::{
}; };
use rustc_middle::ty::print::PrintTraitRefExt as _; use rustc_middle::ty::print::PrintTraitRefExt as _;
use rustc_middle::ty::{ use rustc_middle::ty::{
self, suggest_constraining_type_params, PredicateKind, ToPredicate, Ty, TyCtxt, self, suggest_constraining_type_params, PredicateKind, Ty, TyCtxt, TypeSuperVisitable,
TypeSuperVisitable, TypeVisitor, TypeVisitor, Upcast,
}; };
use rustc_middle::util::CallKind; use rustc_middle::util::CallKind;
use rustc_mir_dataflow::move_paths::{InitKind, MoveOutIndex, MovePathIndex}; 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( self.infcx.err_ctxt().suggest_derive(
&obligation, &obligation,
err, err,
trait_ref.to_predicate(self.infcx.tcx), trait_ref.upcast(self.infcx.tcx),
); );
} }
} }

View file

@ -9,7 +9,7 @@ use rustc_hir::{self as hir, BindingMode, ByRef, Node};
use rustc_infer::traits; use rustc_infer::traits;
use rustc_middle::bug; use rustc_middle::bug;
use rustc_middle::mir::{Mutability, Place, PlaceRef, ProjectionElem}; 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::{ use rustc_middle::{
hir::place::PlaceBase, hir::place::PlaceBase,
mir::{self, BindingForm, Local, LocalDecl, LocalInfo, LocalKind, Location}, mir::{self, BindingForm, Local, LocalDecl, LocalInfo, LocalKind, Location},
@ -1255,7 +1255,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
self.infcx.err_ctxt().suggest_derive( self.infcx.err_ctxt().suggest_derive(
&obligation, &obligation,
err, err,
trait_ref.to_predicate(self.infcx.tcx), trait_ref.upcast(self.infcx.tcx),
); );
} }
Some(errors) => { Some(errors) => {

View file

@ -4,7 +4,7 @@ use rustc_errors::ErrorGuaranteed;
use rustc_infer::infer::canonical::Canonical; use rustc_infer::infer::canonical::Canonical;
use rustc_middle::bug; use rustc_middle::bug;
use rustc_middle::mir::ConstraintCategory; 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::def_id::DefId;
use rustc_span::Span; use rustc_span::Span;
use rustc_trait_selection::traits::query::type_op::{self, TypeOpOutput}; 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( pub(super) fn prove_predicates(
&mut self, &mut self,
predicates: impl IntoIterator<Item: ToPredicate<'tcx> + std::fmt::Debug>, predicates: impl IntoIterator<Item: Upcast<'tcx> + std::fmt::Debug>,
locations: Locations, locations: Locations,
category: ConstraintCategory<'tcx>, category: ConstraintCategory<'tcx>,
) { ) {
@ -127,12 +127,12 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
#[instrument(skip(self), level = "debug")] #[instrument(skip(self), level = "debug")]
pub(super) fn prove_predicate( pub(super) fn prove_predicate(
&mut self, &mut self,
predicate: impl ToPredicate<'tcx> + std::fmt::Debug, predicate: impl Upcast<'tcx> + std::fmt::Debug,
locations: Locations, locations: Locations,
category: ConstraintCategory<'tcx>, category: ConstraintCategory<'tcx>,
) { ) {
let param_env = self.param_env; 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( let _: Result<_, ErrorGuaranteed> = self.fully_perform_op(
locations, locations,
category, category,

View file

@ -546,7 +546,7 @@ impl<'bccx, 'tcx> ObligationEmittingRelation<'tcx> for NllTypeRelating<'_, 'bccx
self.type_checker.param_env self.type_checker.param_env
} }
fn register_predicates(&mut self, obligations: impl IntoIterator<Item: ty::ToPredicate<'tcx>>) { fn register_predicates(&mut self, obligations: impl IntoIterator<Item: ty::Upcast<'tcx>>) {
self.register_obligations( self.register_obligations(
obligations obligations
.into_iter() .into_iter()

View file

@ -2,7 +2,7 @@
//! [`rustc_middle::ty`] form. //! [`rustc_middle::ty`] form.
use rustc_hir::LangItem; use rustc_hir::LangItem;
use rustc_middle::ty::{self, ToPredicate, Ty, TyCtxt}; use rustc_middle::ty::{self, Ty, TyCtxt, Upcast};
use rustc_span::Span; use rustc_span::Span;
/// Collects together a list of type bounds. These lists of bounds occur in many places /// 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, span: Span,
) { ) {
self.clauses 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( pub fn push_trait_bound(
@ -49,7 +49,7 @@ impl<'tcx> Bounds<'tcx> {
.map_bound(|trait_ref| { .map_bound(|trait_ref| {
ty::ClauseKind::Trait(ty::TraitPredicate { trait_ref, polarity }) ty::ClauseKind::Trait(ty::TraitPredicate { trait_ref, polarity })
}) })
.to_predicate(tcx), .upcast(tcx),
span, span,
); );
// FIXME(-Znext-solver): We can likely remove this hack once the new trait solver lands. // 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, span: Span,
) { ) {
self.clauses.push(( 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, span,
)); ));
} }
@ -76,7 +76,7 @@ impl<'tcx> Bounds<'tcx> {
let sized_def_id = tcx.require_lang_item(LangItem::Sized, Some(span)); let sized_def_id = tcx.require_lang_item(LangItem::Sized, Some(span));
let trait_ref = ty::TraitRef::new(tcx, sized_def_id, [ty]); 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. // 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<Item = (ty::Clause<'tcx>, Span)> + '_ { pub fn clauses(&self) -> impl Iterator<Item = (ty::Clause<'tcx>, Span)> + '_ {

View file

@ -14,7 +14,7 @@ use rustc_infer::traits::{util, FulfillmentError};
use rustc_middle::ty::error::{ExpectedFound, TypeError}; use rustc_middle::ty::error::{ExpectedFound, TypeError};
use rustc_middle::ty::fold::BottomUpFolder; use rustc_middle::ty::fold::BottomUpFolder;
use rustc_middle::ty::util::ExplicitSelf; use rustc_middle::ty::util::ExplicitSelf;
use rustc_middle::ty::ToPredicate; use rustc_middle::ty::Upcast;
use rustc_middle::ty::{ use rustc_middle::ty::{
self, GenericArgs, Ty, TypeFoldable, TypeFolder, TypeSuperFoldable, TypeVisitableExt, self, GenericArgs, Ty, TypeFoldable, TypeFolder, TypeSuperFoldable, TypeVisitableExt,
}; };
@ -2211,7 +2211,7 @@ fn param_env_with_gat_bounds<'tcx>(
}, },
bound_vars, bound_vars,
) )
.to_predicate(tcx), .upcast(tcx),
), ),
}; };
} }

View file

@ -20,8 +20,8 @@ use rustc_middle::query::Providers;
use rustc_middle::ty::print::with_no_trimmed_paths; use rustc_middle::ty::print::with_no_trimmed_paths;
use rustc_middle::ty::trait_def::TraitSpecializationKind; use rustc_middle::ty::trait_def::TraitSpecializationKind;
use rustc_middle::ty::{ use rustc_middle::ty::{
self, AdtKind, GenericParamDefKind, ToPredicate, Ty, TyCtxt, TypeFoldable, TypeSuperVisitable, self, AdtKind, GenericParamDefKind, Ty, TyCtxt, TypeFoldable, TypeSuperVisitable,
TypeVisitable, TypeVisitableExt, TypeVisitor, TypeVisitable, TypeVisitableExt, TypeVisitor, Upcast,
}; };
use rustc_middle::ty::{GenericArgKind, GenericArgs}; use rustc_middle::ty::{GenericArgKind, GenericArgs};
use rustc_middle::{bug, span_bug}; use rustc_middle::{bug, span_bug};
@ -685,7 +685,7 @@ fn gather_gat_bounds<'tcx, T: TypeFoldable<TyCtxt<'tcx>>>(
// `Self: 'me`.) // `Self: 'me`.)
bounds.insert( bounds.insert(
ty::ClauseKind::TypeOutlives(ty::OutlivesPredicate(ty_param, region_param)) 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<TyCtxt<'tcx>>>(
region_a_param, region_a_param,
region_b_param, region_b_param,
)) ))
.to_predicate(tcx), .upcast(tcx),
); );
} }
} }

View file

@ -29,7 +29,7 @@ use rustc_infer::traits::ObligationCause;
use rustc_middle::hir::nested_filter; use rustc_middle::hir::nested_filter;
use rustc_middle::query::Providers; use rustc_middle::query::Providers;
use rustc_middle::ty::util::{Discr, IntTypeExt}; 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_middle::{bug, span_bug};
use rustc_span::symbol::{kw, sym, Ident, Symbol}; use rustc_span::symbol::{kw, sym, Ident, Symbol};
use rustc_span::{Span, DUMMY_SP}; 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, def_id, inferred_outlives,
); );
let inferred_outlives_iter = 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() { if result.predicates.is_empty() {
result.predicates = tcx.arena.alloc_from_iter(inferred_outlives_iter); result.predicates = tcx.arena.alloc_from_iter(inferred_outlives_iter);
} else { } else {

View file

@ -9,7 +9,7 @@ use rustc_hir::def::DefKind;
use rustc_hir::def_id::{DefId, LocalDefId}; use rustc_hir::def_id::{DefId, LocalDefId};
use rustc_hir::intravisit::{self, Visitor}; use rustc_hir::intravisit::{self, Visitor};
use rustc_middle::ty::{self, Ty, TyCtxt}; 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_middle::{bug, span_bug};
use rustc_span::symbol::Ident; use rustc_span::symbol::Ident;
use rustc_span::{Span, DUMMY_SP}; use rustc_span::{Span, DUMMY_SP};
@ -42,7 +42,7 @@ pub(super) fn predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericPredic
result.predicates = result.predicates =
tcx.arena.alloc_from_iter(result.predicates.iter().copied().chain(std::iter::once(( 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, 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 // (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. // set of defaults that can be incorporated into another impl.
if let Some(trait_ref) = is_default_impl_trait { 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 // 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"); .expect("const parameters cannot be generic");
let ct = icx.lowerer().lower_const_param(param.hir_id, ct_ty); let ct = icx.lowerer().lower_const_param(param.hir_id, ct_ty);
predicates.insert(( predicates.insert((
ty::ClauseKind::ConstArgHasType(ct, ct_ty).to_predicate(tcx), ty::ClauseKind::ConstArgHasType(ct, ct_ty).upcast(tcx),
param.span, param.span,
)); ));
} }
@ -228,7 +228,7 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Gen
ty::ClauseKind::WellFormed(ty.into()), ty::ClauseKind::WellFormed(ty.into()),
bound_vars, 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)) let pred = ty::ClauseKind::RegionOutlives(ty::OutlivesPredicate(r1, r2))
.to_predicate(tcx); .upcast(tcx);
(pred, span) (pred, span)
})) }))
} }
@ -328,12 +328,12 @@ fn compute_bidirectional_outlives_predicates<'tcx>(
let span = tcx.def_span(param.def_id); let span = tcx.def_span(param.def_id);
predicates.push(( predicates.push((
ty::ClauseKind::RegionOutlives(ty::OutlivesPredicate(orig_lifetime, dup_lifetime)) ty::ClauseKind::RegionOutlives(ty::OutlivesPredicate(orig_lifetime, dup_lifetime))
.to_predicate(tcx), .upcast(tcx),
span, span,
)); ));
predicates.push(( predicates.push((
ty::ClauseKind::RegionOutlives(ty::OutlivesPredicate(dup_lifetime, orig_lifetime)) ty::ClauseKind::RegionOutlives(ty::OutlivesPredicate(dup_lifetime, orig_lifetime))
.to_predicate(tcx), .upcast(tcx),
span, span,
)); ));
} }
@ -355,7 +355,7 @@ fn const_evaluatable_predicates_of(
if let ty::ConstKind::Unevaluated(_) = ct.kind() { if let ty::ConstKind::Unevaluated(_) = ct.kind() {
let span = self.tcx.def_span(c.def_id); let span = self.tcx.def_span(c.def_id);
self.preds 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 && param_id == item_hir_id
{ {
let identity_trait_ref = ty::TraitRef::identity(tcx, item_def_id.to_def_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); let icx = ItemCtxt::new(tcx, item_def_id);

View file

@ -9,7 +9,7 @@ use rustc_lint_defs::builtin::UNUSED_ASSOCIATED_TYPE_BOUNDS;
use rustc_middle::span_bug; use rustc_middle::span_bug;
use rustc_middle::ty::fold::BottomUpFolder; use rustc_middle::ty::fold::BottomUpFolder;
use rustc_middle::ty::{self, ExistentialPredicateStableCmpExt as _, Ty, TyCtxt, TypeFoldable}; 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_span::{ErrorGuaranteed, Span};
use rustc_trait_selection::traits::error_reporting::report_object_safety_error; use rustc_trait_selection::traits::error_reporting::report_object_safety_error;
use rustc_trait_selection::traits::{self, hir_ty_lowering_object_safety_violations}; 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())); .filter(|(trait_ref, _)| !tcx.trait_is_auto(trait_ref.def_id()));
for (base_trait_ref, span) in regular_traits_refs_spans { 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() { for pred in traits::elaborate(tcx, [base_pred]).filter_only_self() {
debug!("observing object predicate `{pred:?}`"); debug!("observing object predicate `{pred:?}`");

View file

@ -2,7 +2,7 @@ use rustc_hir::def::DefKind;
use rustc_hir::def_id::LocalDefId; use rustc_hir::def_id::LocalDefId;
use rustc_middle::query::Providers; use rustc_middle::query::Providers;
use rustc_middle::ty::GenericArgKind; 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; use rustc_span::Span;
mod explicit; mod explicit;
@ -75,14 +75,14 @@ fn inferred_outlives_crate(tcx: TyCtxt<'_>, (): ()) -> CratePredicatesMap<'_> {
match kind1.unpack() { match kind1.unpack() {
GenericArgKind::Type(ty1) => Some(( GenericArgKind::Type(ty1) => Some((
ty::ClauseKind::TypeOutlives(ty::OutlivesPredicate(ty1, *region2)) ty::ClauseKind::TypeOutlives(ty::OutlivesPredicate(ty1, *region2))
.to_predicate(tcx), .upcast(tcx),
span, span,
)), )),
GenericArgKind::Lifetime(region1) => Some(( GenericArgKind::Lifetime(region1) => Some((
ty::ClauseKind::RegionOutlives(ty::OutlivesPredicate( ty::ClauseKind::RegionOutlives(ty::OutlivesPredicate(
region1, *region2, region1, *region2,
)) ))
.to_predicate(tcx), .upcast(tcx),
span, span,
)), )),
GenericArgKind::Const(_) => { GenericArgKind::Const(_) => {

View file

@ -28,8 +28,8 @@ use rustc_middle::middle::stability::EvalResult;
use rustc_middle::span_bug; use rustc_middle::span_bug;
use rustc_middle::ty::print::with_no_trimmed_paths; use rustc_middle::ty::print::with_no_trimmed_paths;
use rustc_middle::ty::{ use rustc_middle::ty::{
self, suggest_constraining_type_params, Article, Binder, IsSuggestable, ToPredicate, Ty, self, suggest_constraining_type_params, Article, Binder, IsSuggestable, Ty, TypeVisitableExt,
TypeVisitableExt, Upcast,
}; };
use rustc_session::errors::ExprParenthesesNeeded; use rustc_session::errors::ExprParenthesesNeeded;
use rustc_span::source_map::Spanned; 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)]);
} }
} }
} }

View file

@ -21,7 +21,7 @@ use rustc_middle::query::Providers;
use rustc_middle::ty::fast_reject::{simplify_type, TreatParams}; use rustc_middle::ty::fast_reject::{simplify_type, TreatParams};
use rustc_middle::ty::AssocItem; use rustc_middle::ty::AssocItem;
use rustc_middle::ty::GenericParamDefKind; 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::{self, ParamEnvAnd, Ty, TyCtxt, TypeVisitableExt};
use rustc_middle::ty::{GenericArgs, GenericArgsRef}; use rustc_middle::ty::{GenericArgs, GenericArgsRef};
use rustc_middle::{bug, span_bug}; 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) => { ObjectCandidate(poly_trait_ref) | WhereClauseCandidate(poly_trait_ref) => {
let trait_ref = self.instantiate_binder_with_fresh_vars( let trait_ref = self.instantiate_binder_with_fresh_vars(

View file

@ -73,7 +73,7 @@ use rustc_middle::bug;
use rustc_middle::dep_graph::DepContext; use rustc_middle::dep_graph::DepContext;
use rustc_middle::ty::print::{with_forced_trimmed_paths, PrintError, PrintTraitRefExt as _}; use rustc_middle::ty::print::{with_forced_trimmed_paths, PrintError, PrintTraitRefExt as _};
use rustc_middle::ty::relate::{self, RelateResult, TypeRelation}; use rustc_middle::ty::relate::{self, RelateResult, TypeRelation};
use rustc_middle::ty::ToPredicate; use rustc_middle::ty::Upcast;
use rustc_middle::ty::{ use rustc_middle::ty::{
self, error::TypeError, IsSuggestable, List, Region, Ty, TyCtxt, TypeFoldable, self, error::TypeError, IsSuggestable, List, Region, Ty, TyCtxt, TypeFoldable,
TypeSuperVisitable, TypeVisitable, TypeVisitableExt, TypeSuperVisitable, TypeVisitable, TypeVisitableExt,
@ -516,7 +516,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
RegionResolutionError::CannotNormalize(clause, origin) => { RegionResolutionError::CannotNormalize(clause, origin) => {
let clause: ty::Clause<'tcx> = 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 self.tcx
.dcx() .dcx()
.struct_span_err(origin.span(), format!("cannot normalize `{clause}`")) .struct_span_err(origin.span(), format!("cannot normalize `{clause}`"))

View file

@ -29,7 +29,7 @@ use rustc_middle::infer::canonical::OriginalQueryValues;
use rustc_middle::infer::unify_key::EffectVarValue; use rustc_middle::infer::unify_key::EffectVarValue;
use rustc_middle::ty::error::{ExpectedFound, TypeError}; use rustc_middle::ty::error::{ExpectedFound, TypeError};
use rustc_middle::ty::relate::{RelateResult, TypeRelation}; 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_middle::ty::{IntType, UintType};
use rustc_span::Span; use rustc_span::Span;
@ -337,7 +337,7 @@ impl<'infcx, 'tcx> CombineFields<'infcx, 'tcx> {
self.obligations.extend(obligations); self.obligations.extend(obligations);
} }
pub fn register_predicates(&mut self, obligations: impl IntoIterator<Item: ToPredicate<'tcx>>) { pub fn register_predicates(&mut self, obligations: impl IntoIterator<Item: Upcast<'tcx>>) {
self.obligations.extend(obligations.into_iter().map(|to_pred| { self.obligations.extend(obligations.into_iter().map(|to_pred| {
Obligation::new(self.infcx.tcx, self.trace.cause.clone(), self.param_env, 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 /// Register predicates that must hold in order for this relation to hold. Uses
/// a default obligation cause, [`ObligationEmittingRelation::register_obligations`] should /// a default obligation cause, [`ObligationEmittingRelation::register_obligations`] should
/// be used if control over the obligation causes is required. /// be used if control over the obligation causes is required.
fn register_predicates(&mut self, obligations: impl IntoIterator<Item: ToPredicate<'tcx>>); fn register_predicates(&mut self, obligations: impl IntoIterator<Item: Upcast<'tcx>>);
/// Register `AliasRelate` obligation(s) that both types must be related to each other. /// 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>); fn register_type_relate_obligation(&mut self, a: Ty<'tcx>, b: Ty<'tcx>);

View file

@ -140,7 +140,7 @@ impl<'tcx> ObligationEmittingRelation<'tcx> for Glb<'_, '_, 'tcx> {
self.fields.param_env self.fields.param_env
} }
fn register_predicates(&mut self, obligations: impl IntoIterator<Item: ty::ToPredicate<'tcx>>) { fn register_predicates(&mut self, obligations: impl IntoIterator<Item: ty::Upcast<'tcx>>) {
self.fields.register_predicates(obligations); self.fields.register_predicates(obligations);
} }

View file

@ -140,7 +140,7 @@ impl<'tcx> ObligationEmittingRelation<'tcx> for Lub<'_, '_, 'tcx> {
self.fields.param_env self.fields.param_env
} }
fn register_predicates(&mut self, obligations: impl IntoIterator<Item: ty::ToPredicate<'tcx>>) { fn register_predicates(&mut self, obligations: impl IntoIterator<Item: ty::Upcast<'tcx>>) {
self.fields.register_predicates(obligations); self.fields.register_predicates(obligations);
} }

View file

@ -312,7 +312,7 @@ impl<'tcx> ObligationEmittingRelation<'tcx> for TypeRelating<'_, '_, 'tcx> {
self.structurally_relate_aliases self.structurally_relate_aliases
} }
fn register_predicates(&mut self, obligations: impl IntoIterator<Item: ty::ToPredicate<'tcx>>) { fn register_predicates(&mut self, obligations: impl IntoIterator<Item: ty::Upcast<'tcx>>) {
self.fields.register_predicates(obligations); self.fields.register_predicates(obligations);
} }

View file

@ -2,7 +2,7 @@ use crate::infer::InferCtxt;
use crate::traits::Obligation; use crate::traits::Obligation;
use rustc_hir::def_id::DefId; use rustc_hir::def_id::DefId;
use rustc_macros::extension; use rustc_macros::extension;
use rustc_middle::ty::{self, ToPredicate, Ty}; use rustc_middle::ty::{self, Ty, Upcast};
use super::FulfillmentError; use super::FulfillmentError;
use super::{ObligationCause, PredicateObligation}; use super::{ObligationCause, PredicateObligation};
@ -26,7 +26,7 @@ pub trait TraitEngine<'tcx>: 'tcx {
cause, cause,
recursion_depth: 0, recursion_depth: 0,
param_env, param_env,
predicate: ty::Binder::dummy(trait_ref).to_predicate(infcx.tcx), predicate: ty::Binder::dummy(trait_ref).upcast(infcx.tcx),
}, },
); );
} }

View file

@ -16,7 +16,7 @@ use rustc_hir as hir;
use rustc_middle::traits::query::NoSolution; use rustc_middle::traits::query::NoSolution;
use rustc_middle::traits::solve::Certainty; use rustc_middle::traits::solve::Certainty;
use rustc_middle::ty::error::{ExpectedFound, TypeError}; 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; use rustc_span::Span;
pub use self::ImplSource::*; pub use self::ImplSource::*;
@ -155,7 +155,7 @@ impl<'tcx, O> Obligation<'tcx, O> {
tcx: TyCtxt<'tcx>, tcx: TyCtxt<'tcx>,
cause: ObligationCause<'tcx>, cause: ObligationCause<'tcx>,
param_env: ty::ParamEnv<'tcx>, param_env: ty::ParamEnv<'tcx>,
predicate: impl ToPredicate<'tcx, O>, predicate: impl Upcast<'tcx, O>,
) -> Obligation<'tcx, O> { ) -> Obligation<'tcx, O> {
Self::with_depth(tcx, cause, 0, param_env, predicate) Self::with_depth(tcx, cause, 0, param_env, predicate)
} }
@ -173,9 +173,9 @@ impl<'tcx, O> Obligation<'tcx, O> {
cause: ObligationCause<'tcx>, cause: ObligationCause<'tcx>,
recursion_depth: usize, recursion_depth: usize,
param_env: ty::ParamEnv<'tcx>, param_env: ty::ParamEnv<'tcx>,
predicate: impl ToPredicate<'tcx, O>, predicate: impl Upcast<'tcx, O>,
) -> Obligation<'tcx, O> { ) -> Obligation<'tcx, O> {
let predicate = predicate.to_predicate(tcx); let predicate = predicate.upcast(tcx);
Obligation { cause, param_env, recursion_depth, predicate } Obligation { cause, param_env, recursion_depth, predicate }
} }
@ -184,16 +184,12 @@ impl<'tcx, O> Obligation<'tcx, O> {
span: Span, span: Span,
body_id: LocalDefId, body_id: LocalDefId,
param_env: ty::ParamEnv<'tcx>, param_env: ty::ParamEnv<'tcx>,
trait_ref: impl ToPredicate<'tcx, O>, trait_ref: impl Upcast<'tcx, O>,
) -> Obligation<'tcx, O> { ) -> Obligation<'tcx, O> {
Obligation::new(tcx, 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>( pub fn with<P>(&self, tcx: TyCtxt<'tcx>, value: impl Upcast<'tcx, P>) -> Obligation<'tcx, 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) Obligation::with_depth(tcx, self.cause.clone(), self.recursion_depth, self.param_env, value)
} }
} }

View file

@ -3,7 +3,7 @@ use smallvec::smallvec;
use crate::infer::outlives::components::{push_outlives_components, Component}; use crate::infer::outlives::components::{push_outlives_components, Component};
use crate::traits::{self, Obligation, ObligationCauseCode, PredicateObligation}; use crate::traits::{self, Obligation, ObligationCauseCode, PredicateObligation};
use rustc_data_structures::fx::FxHashSet; 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::symbol::Ident;
use rustc_span::Span; use rustc_span::Span;
@ -358,7 +358,7 @@ impl<'tcx, O: Elaboratable<'tcx>> Elaborator<'tcx, O> {
} }
}) })
.map(|clause| { .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>, tcx: TyCtxt<'tcx>,
trait_ref: ty::PolyTraitRef<'tcx>, trait_ref: ty::PolyTraitRef<'tcx>,
) -> FilterToTraits<Elaborator<'tcx, ty::Predicate<'tcx>>> { ) -> FilterToTraits<Elaborator<'tcx, ty::Predicate<'tcx>>> {
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>( pub fn transitive_bounds<'tcx>(
tcx: TyCtxt<'tcx>, tcx: TyCtxt<'tcx>,
trait_refs: impl Iterator<Item = ty::PolyTraitRef<'tcx>>, trait_refs: impl Iterator<Item = ty::PolyTraitRef<'tcx>>,
) -> FilterToTraits<Elaborator<'tcx, ty::Predicate<'tcx>>> { ) -> FilterToTraits<Elaborator<'tcx, ty::Predicate<'tcx>>> {
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_only_self()
.filter_to_traits() .filter_to_traits()
} }
@ -431,7 +431,7 @@ pub fn transitive_bounds_that_define_assoc_item<'tcx>(
trait_refs: impl Iterator<Item = ty::PolyTraitRef<'tcx>>, trait_refs: impl Iterator<Item = ty::PolyTraitRef<'tcx>>,
assoc_name: Ident, assoc_name: Ident,
) -> FilterToTraits<Elaborator<'tcx, ty::Predicate<'tcx>>> { ) -> FilterToTraits<Elaborator<'tcx, ty::Predicate<'tcx>>> {
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_only_self_that_defines(assoc_name)
.filter_to_traits() .filter_to_traits()
} }

View file

@ -57,8 +57,8 @@ use rustc_middle::lint::in_external_macro;
use rustc_middle::ty::layout::LayoutOf; use rustc_middle::ty::layout::LayoutOf;
use rustc_middle::ty::print::with_no_trimmed_paths; use rustc_middle::ty::print::with_no_trimmed_paths;
use rustc_middle::ty::GenericArgKind; use rustc_middle::ty::GenericArgKind;
use rustc_middle::ty::ToPredicate;
use rustc_middle::ty::TypeVisitableExt; use rustc_middle::ty::TypeVisitableExt;
use rustc_middle::ty::Upcast;
use rustc_middle::ty::{self, Ty, TyCtxt, VariantDef}; use rustc_middle::ty::{self, Ty, TyCtxt, VariantDef};
use rustc_session::lint::{BuiltinLintDiag, FutureIncompatibilityReason}; use rustc_session::lint::{BuiltinLintDiag, FutureIncompatibilityReason};
use rustc_session::{declare_lint, declare_lint_pass, impl_lint_pass}; 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(), cause: traits::ObligationCause::dummy(),
param_env, param_env,
recursion_depth: 0, 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) tcx.infer_ctxt().build().predicate_must_hold_modulo_regions(&obligation)

View file

@ -7,8 +7,8 @@ use crate::infer::canonical::{CanonicalVarValues, QueryRegionConstraints};
use crate::traits::query::NoSolution; use crate::traits::query::NoSolution;
use crate::traits::Canonical; use crate::traits::Canonical;
use crate::ty::{ use crate::ty::{
self, FallibleTypeFolder, ToPredicate, Ty, TyCtxt, TypeFoldable, TypeFolder, TypeVisitable, self, FallibleTypeFolder, Ty, TyCtxt, TypeFoldable, TypeFolder, TypeVisitable, TypeVisitor,
TypeVisitor, Upcast,
}; };
use super::BuiltinImplSource; use super::BuiltinImplSource;
@ -33,14 +33,14 @@ impl<'tcx, P> Goal<'tcx, P> {
pub fn new( pub fn new(
tcx: TyCtxt<'tcx>, tcx: TyCtxt<'tcx>,
param_env: ty::ParamEnv<'tcx>, param_env: ty::ParamEnv<'tcx>,
predicate: impl ToPredicate<'tcx, P>, predicate: impl Upcast<'tcx, P>,
) -> Goal<'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`. /// Updates the goal to one with a different `predicate` but the same `param_env`.
pub fn with<Q>(self, tcx: TyCtxt<'tcx>, predicate: impl ToPredicate<'tcx, Q>) -> Goal<'tcx, Q> { pub fn with<Q>(self, tcx: TyCtxt<'tcx>, predicate: impl Upcast<'tcx, Q>) -> Goal<'tcx, Q> {
Goal { param_env: self.param_env, predicate: predicate.to_predicate(tcx) } Goal { param_env: self.param_env, predicate: predicate.upcast(tcx) }
} }
} }

View file

@ -1,6 +1,6 @@
use rustc_data_structures::fx::FxHashSet; 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. /// 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>, tcx: TyCtxt<'tcx>,
trait_ref: PolyTraitRef<'tcx>, trait_ref: PolyTraitRef<'tcx>,
) -> impl Iterator<Item = Clause<'tcx>> { ) -> impl Iterator<Item = Clause<'tcx>> {
let clause = trait_ref.to_predicate(tcx); let clause = trait_ref.upcast(tcx);
Elaborator { tcx, visited: FxHashSet::from_iter([clause]), stack: vec![clause] } Elaborator { tcx, visited: FxHashSet::from_iter([clause]), stack: vec![clause] }
} }

View file

@ -102,7 +102,7 @@ pub use self::predicate::{
PolyExistentialTraitRef, PolyProjectionPredicate, PolyRegionOutlivesPredicate, PolyExistentialTraitRef, PolyProjectionPredicate, PolyRegionOutlivesPredicate,
PolySubtypePredicate, PolyTraitPredicate, PolyTraitRef, PolyTypeOutlivesPredicate, Predicate, PolySubtypePredicate, PolyTraitPredicate, PolyTraitRef, PolyTypeOutlivesPredicate, Predicate,
PredicateKind, ProjectionPredicate, RegionOutlivesPredicate, SubtypePredicate, ToPolyTraitRef, PredicateKind, ProjectionPredicate, RegionOutlivesPredicate, SubtypePredicate, ToPolyTraitRef,
ToPredicate, TraitPredicate, TraitRef, TypeOutlivesPredicate, TraitPredicate, TraitRef, TypeOutlivesPredicate, Upcast,
}; };
pub use self::region::{ pub use self::region::{
BoundRegion, BoundRegionKind, BoundRegionKind::*, EarlyParamRegion, LateParamRegion, Region, BoundRegion, BoundRegionKind, BoundRegionKind::*, EarlyParamRegion, LateParamRegion, Region,

View file

@ -234,10 +234,10 @@ impl<'tcx> PolyExistentialPredicate<'tcx> {
pub fn with_self_ty(&self, tcx: TyCtxt<'tcx>, self_ty: Ty<'tcx>) -> ty::Clause<'tcx> { pub fn with_self_ty(&self, tcx: TyCtxt<'tcx>, self_ty: Ty<'tcx>) -> ty::Clause<'tcx> {
match self.skip_binder() { match self.skip_binder() {
ExistentialPredicate::Trait(tr) => { 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) => { 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) => { ExistentialPredicate::AutoTrait(did) => {
let generics = tcx.generics_of(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()]); let err_args = ty::GenericArgs::extend_with_error(tcx, did, &[self_ty.into()]);
ty::TraitRef::new(tcx, did, err_args) 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>> { pub trait Upcast<'tcx, P = Predicate<'tcx>> {
fn to_predicate(self, tcx: TyCtxt<'tcx>) -> P; fn upcast(self, tcx: TyCtxt<'tcx>) -> P;
} }
impl<'tcx, T> ToPredicate<'tcx, T> for T { impl<'tcx, T> Upcast<'tcx, T> for T {
fn to_predicate(self, _tcx: TyCtxt<'tcx>) -> T { fn upcast(self, _tcx: TyCtxt<'tcx>) -> T {
self self
} }
} }
impl<'tcx> ToPredicate<'tcx> for PredicateKind<'tcx> { impl<'tcx> Upcast<'tcx> for PredicateKind<'tcx> {
#[inline(always)] #[inline(always)]
fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> { fn upcast(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
ty::Binder::dummy(self).to_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)] #[inline(always)]
fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> { fn upcast(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
tcx.mk_predicate(self) tcx.mk_predicate(self)
} }
} }
impl<'tcx> ToPredicate<'tcx> for ClauseKind<'tcx> { impl<'tcx> Upcast<'tcx> for ClauseKind<'tcx> {
#[inline(always)] #[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))) 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)] #[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)) 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)] #[inline(always)]
fn to_predicate(self, _tcx: TyCtxt<'tcx>) -> Predicate<'tcx> { fn upcast(self, _tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
self.as_predicate() self.as_predicate()
} }
} }
impl<'tcx> ToPredicate<'tcx, Clause<'tcx>> for ClauseKind<'tcx> { impl<'tcx> Upcast<'tcx, Clause<'tcx>> for ClauseKind<'tcx> {
#[inline(always)] #[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() 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)] #[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() 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)] #[inline(always)]
fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> { fn upcast(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
ty::Binder::dummy(self).to_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)] #[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 } 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)] #[inline(always)]
fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Clause<'tcx> { fn upcast(self, tcx: TyCtxt<'tcx>) -> Clause<'tcx> {
let p: Predicate<'tcx> = self.to_predicate(tcx); let p: Predicate<'tcx> = self.upcast(tcx);
p.expect_clause() p.expect_clause()
} }
} }
impl<'tcx> ToPredicate<'tcx> for Binder<'tcx, TraitRef<'tcx>> { impl<'tcx> Upcast<'tcx> for Binder<'tcx, TraitRef<'tcx>> {
#[inline(always)] #[inline(always)]
fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> { fn upcast(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
let pred: PolyTraitPredicate<'tcx> = self.to_predicate(tcx); let pred: PolyTraitPredicate<'tcx> = self.upcast(tcx);
pred.to_predicate(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)] #[inline(always)]
fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Clause<'tcx> { fn upcast(self, tcx: TyCtxt<'tcx>) -> Clause<'tcx> {
let pred: PolyTraitPredicate<'tcx> = self.to_predicate(tcx); let pred: PolyTraitPredicate<'tcx> = self.upcast(tcx);
pred.to_predicate(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)] #[inline(always)]
fn to_predicate(self, _: TyCtxt<'tcx>) -> PolyTraitPredicate<'tcx> { fn upcast(self, _: TyCtxt<'tcx>) -> PolyTraitPredicate<'tcx> {
self.map_bound(|trait_ref| TraitPredicate { self.map_bound(|trait_ref| TraitPredicate {
trait_ref, trait_ref,
polarity: ty::PredicatePolarity::Positive, 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> { impl<'tcx> Upcast<'tcx> for TraitPredicate<'tcx> {
fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> { fn upcast(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
PredicateKind::Clause(ClauseKind::Trait(self)).to_predicate(tcx) PredicateKind::Clause(ClauseKind::Trait(self)).upcast(tcx)
} }
} }
impl<'tcx> ToPredicate<'tcx> for PolyTraitPredicate<'tcx> { impl<'tcx> Upcast<'tcx> for PolyTraitPredicate<'tcx> {
fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> { fn upcast(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
self.map_bound(|p| PredicateKind::Clause(ClauseKind::Trait(p))).to_predicate(tcx) self.map_bound(|p| PredicateKind::Clause(ClauseKind::Trait(p))).upcast(tcx)
} }
} }
impl<'tcx> ToPredicate<'tcx, Clause<'tcx>> for TraitPredicate<'tcx> { impl<'tcx> Upcast<'tcx, Clause<'tcx>> for TraitPredicate<'tcx> {
fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Clause<'tcx> { fn upcast(self, tcx: TyCtxt<'tcx>) -> Clause<'tcx> {
let p: Predicate<'tcx> = self.to_predicate(tcx); let p: Predicate<'tcx> = self.upcast(tcx);
p.expect_clause() p.expect_clause()
} }
} }
impl<'tcx> ToPredicate<'tcx, Clause<'tcx>> for PolyTraitPredicate<'tcx> { impl<'tcx> Upcast<'tcx, Clause<'tcx>> for PolyTraitPredicate<'tcx> {
fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Clause<'tcx> { fn upcast(self, tcx: TyCtxt<'tcx>) -> Clause<'tcx> {
let p: Predicate<'tcx> = self.to_predicate(tcx); let p: Predicate<'tcx> = self.upcast(tcx);
p.expect_clause() p.expect_clause()
} }
} }
impl<'tcx> ToPredicate<'tcx> for PolyRegionOutlivesPredicate<'tcx> { impl<'tcx> Upcast<'tcx> for PolyRegionOutlivesPredicate<'tcx> {
fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> { fn upcast(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
self.map_bound(|p| PredicateKind::Clause(ClauseKind::RegionOutlives(p))).to_predicate(tcx) self.map_bound(|p| PredicateKind::Clause(ClauseKind::RegionOutlives(p))).upcast(tcx)
} }
} }
impl<'tcx> ToPredicate<'tcx> for OutlivesPredicate<Ty<'tcx>, ty::Region<'tcx>> { impl<'tcx> Upcast<'tcx> for OutlivesPredicate<Ty<'tcx>, ty::Region<'tcx>> {
fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> { fn upcast(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
ty::Binder::dummy(PredicateKind::Clause(ClauseKind::TypeOutlives(self))).to_predicate(tcx) ty::Binder::dummy(PredicateKind::Clause(ClauseKind::TypeOutlives(self))).upcast(tcx)
} }
} }
impl<'tcx> ToPredicate<'tcx> for ProjectionPredicate<'tcx> { impl<'tcx> Upcast<'tcx> for ProjectionPredicate<'tcx> {
fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> { fn upcast(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
ty::Binder::dummy(PredicateKind::Clause(ClauseKind::Projection(self))).to_predicate(tcx) ty::Binder::dummy(PredicateKind::Clause(ClauseKind::Projection(self))).upcast(tcx)
} }
} }
impl<'tcx> ToPredicate<'tcx> for PolyProjectionPredicate<'tcx> { impl<'tcx> Upcast<'tcx> for PolyProjectionPredicate<'tcx> {
fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> { fn upcast(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
self.map_bound(|p| PredicateKind::Clause(ClauseKind::Projection(p))).to_predicate(tcx) self.map_bound(|p| PredicateKind::Clause(ClauseKind::Projection(p))).upcast(tcx)
} }
} }
impl<'tcx> ToPredicate<'tcx, Clause<'tcx>> for ProjectionPredicate<'tcx> { impl<'tcx> Upcast<'tcx, Clause<'tcx>> for ProjectionPredicate<'tcx> {
fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Clause<'tcx> { fn upcast(self, tcx: TyCtxt<'tcx>) -> Clause<'tcx> {
let p: Predicate<'tcx> = self.to_predicate(tcx); let p: Predicate<'tcx> = self.upcast(tcx);
p.expect_clause() p.expect_clause()
} }
} }
impl<'tcx> ToPredicate<'tcx, Clause<'tcx>> for PolyProjectionPredicate<'tcx> { impl<'tcx> Upcast<'tcx, Clause<'tcx>> for PolyProjectionPredicate<'tcx> {
fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Clause<'tcx> { fn upcast(self, tcx: TyCtxt<'tcx>) -> Clause<'tcx> {
let p: Predicate<'tcx> = self.to_predicate(tcx); let p: Predicate<'tcx> = self.upcast(tcx);
p.expect_clause() p.expect_clause()
} }
} }
impl<'tcx> ToPredicate<'tcx> for NormalizesTo<'tcx> { impl<'tcx> Upcast<'tcx> for NormalizesTo<'tcx> {
fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> { fn upcast(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
PredicateKind::NormalizesTo(self).to_predicate(tcx) PredicateKind::NormalizesTo(self).upcast(tcx)
} }
} }

View file

@ -4,8 +4,8 @@ use crate::middle::codegen_fn_attrs::CodegenFnAttrFlags;
use crate::query::{IntoQueryParam, Providers}; use crate::query::{IntoQueryParam, Providers};
use crate::ty::layout::{FloatExt, IntegerExt}; use crate::ty::layout::{FloatExt, IntegerExt};
use crate::ty::{ use crate::ty::{
self, FallibleTypeFolder, ToPredicate, Ty, TyCtxt, TypeFoldable, TypeFolder, TypeSuperFoldable, self, FallibleTypeFolder, Ty, TyCtxt, TypeFoldable, TypeFolder, TypeSuperFoldable,
TypeVisitableExt, TypeVisitableExt, Upcast,
}; };
use crate::ty::{GenericArgKind, GenericArgsRef}; use crate::ty::{GenericArgKind, GenericArgsRef};
use rustc_apfloat::Float as _; use rustc_apfloat::Float as _;
@ -1094,7 +1094,7 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for OpaqueTypeExpander<'tcx> {
// anything that requires `ParamEnv::with_reveal_all_normalized`. // anything that requires `ParamEnv::with_reveal_all_normalized`.
term: projection_pred.term, term: projection_pred.term,
}) })
.to_predicate(self.tcx) .upcast(self.tcx)
} else { } else {
p.super_fold_with(self) p.super_fold_with(self)
} }

View file

@ -10,7 +10,7 @@ use rustc_middle::infer::canonical::{Canonical, CanonicalQueryResponse, QueryRes
use rustc_middle::traits::query::NoSolution; use rustc_middle::traits::query::NoSolution;
use rustc_middle::traits::ObligationCause; use rustc_middle::traits::ObligationCause;
use rustc_middle::ty::{self, Ty, TyCtxt, TypeFoldable, TypeVisitableExt}; 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 rustc_span::DUMMY_SP;
use std::fmt::Debug; use std::fmt::Debug;
@ -63,7 +63,7 @@ impl<'tcx> InferCtxt<'tcx> {
cause: traits::ObligationCause::dummy(), cause: traits::ObligationCause::dummy(),
param_env, param_env,
recursion_depth: 0, 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) self.evaluate_obligation(&obligation).unwrap_or(traits::EvaluationResult::EvaluatedToErr)
} }

View file

@ -13,7 +13,7 @@ use rustc_middle::traits::BuiltinImplSource;
use rustc_middle::ty::fast_reject::{SimplifiedType, TreatParams}; use rustc_middle::ty::fast_reject::{SimplifiedType, TreatParams};
use rustc_middle::ty::{self, Ty, TyCtxt}; use rustc_middle::ty::{self, Ty, TyCtxt};
use rustc_middle::ty::{fast_reject, TypeFoldable}; 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 rustc_span::{ErrorGuaranteed, DUMMY_SP};
use std::fmt::Debug; use std::fmt::Debug;
@ -744,7 +744,7 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
ecx, ecx,
CandidateSource::BuiltinImpl(BuiltinImplSource::Object { vtable_base }), CandidateSource::BuiltinImpl(BuiltinImplSource::Object { vtable_base }),
goal, goal,
assumption.to_predicate(tcx), assumption.upcast(tcx),
)); ));
}); });
} }

View file

@ -7,9 +7,7 @@ use rustc_infer::traits::query::NoSolution;
use rustc_macros::{TypeFoldable, TypeVisitable}; use rustc_macros::{TypeFoldable, TypeVisitable};
use rustc_middle::bug; use rustc_middle::bug;
use rustc_middle::traits::solve::Goal; use rustc_middle::traits::solve::Goal;
use rustc_middle::ty::{ use rustc_middle::ty::{self, Ty, TyCtxt, TypeFoldable, TypeFolder, TypeSuperFoldable, Upcast};
self, ToPredicate, Ty, TyCtxt, TypeFoldable, TypeFolder, TypeSuperFoldable,
};
use rustc_span::sym; use rustc_span::sym;
use crate::solve::EvalCtxt; 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), tcx.require_lang_item(LangItem::AsyncFnKindHelper, None),
[kind_ty, Ty::from_closure_kind(tcx, goal_kind)], [kind_ty, Ty::from_closure_kind(tcx, goal_kind)],
) )
.to_predicate(tcx), .upcast(tcx),
); );
coroutine_closure_to_ambiguous_coroutine( 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![ let nested = vec![
bound_sig bound_sig
.rebind(ty::TraitRef::new(tcx, future_trait_def_id, [sig.output()])) .rebind(ty::TraitRef::new(tcx, future_trait_def_id, [sig.output()]))
.to_predicate(tcx), .upcast(tcx),
]; ];
let future_output_def_id = tcx let future_output_def_id = tcx
.associated_items(future_trait_def_id) .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![ let mut nested = vec![
bound_sig bound_sig
.rebind(ty::TraitRef::new(tcx, future_trait_def_id, [sig.output()])) .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 // 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, async_fn_kind_trait_def_id,
[kind_ty, Ty::from_closure_kind(tcx, goal_kind)], [kind_ty, Ty::from_closure_kind(tcx, goal_kind)],
) )
.to_predicate(tcx), .upcast(tcx),
); );
} }

View file

@ -16,7 +16,7 @@ use rustc_middle::traits::BuiltinImplSource;
use rustc_middle::ty::fast_reject::{DeepRejectCtxt, TreatParams}; use rustc_middle::ty::fast_reject::{DeepRejectCtxt, TreatParams};
use rustc_middle::ty::NormalizesTo; use rustc_middle::ty::NormalizesTo;
use rustc_middle::ty::{self, Ty, TyCtxt}; 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_middle::{bug, span_bug};
use rustc_span::{sym, ErrorGuaranteed, DUMMY_SP}; use rustc_span::{sym, ErrorGuaranteed, DUMMY_SP};
@ -370,7 +370,7 @@ impl<'tcx> assembly::GoalKind<'tcx> for NormalizesTo<'tcx> {
), ),
term: output.into(), term: output.into(),
}) })
.to_predicate(tcx); .upcast(tcx);
// A built-in `Fn` impl only holds if the output is sized. // 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...) // (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 } ty::ProjectionPredicate { projection_term, term }
}, },
) )
.to_predicate(tcx); .upcast(tcx);
// A built-in `AsyncFn` impl only holds if the output is sized. // 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...) // (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]), projection_term: ty::AliasTerm::new(ecx.tcx(), goal.predicate.def_id(), [self_ty]),
term, term,
} }
.to_predicate(tcx), .upcast(tcx),
// Technically, we need to check that the future type is Sized, // Technically, we need to check that the future type is Sized,
// but that's already proven by the coroutine being WF. // 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]), projection_term: ty::AliasTerm::new(ecx.tcx(), goal.predicate.def_id(), [self_ty]),
term, term,
} }
.to_predicate(tcx), .upcast(tcx),
// Technically, we need to check that the iterator type is Sized, // Technically, we need to check that the iterator type is Sized,
// but that's already proven by the generator being WF. // but that's already proven by the generator being WF.
[], [],
@ -749,7 +749,7 @@ impl<'tcx> assembly::GoalKind<'tcx> for NormalizesTo<'tcx> {
), ),
term, term,
} }
.to_predicate(tcx), .upcast(tcx),
// Technically, we need to check that the coroutine type is Sized, // Technically, we need to check that the coroutine type is Sized,
// but that's already proven by the coroutine being WF. // but that's already proven by the coroutine being WF.
[], [],

View file

@ -15,7 +15,7 @@ use rustc_middle::traits::solve::inspect::ProbeKind;
use rustc_middle::traits::solve::{CandidateSource, Certainty, Goal, QueryResult}; use rustc_middle::traits::solve::{CandidateSource, Certainty, Goal, QueryResult};
use rustc_middle::traits::{BuiltinImplSource, Reveal}; use rustc_middle::traits::{BuiltinImplSource, Reveal};
use rustc_middle::ty::fast_reject::{DeepRejectCtxt, TreatParams}; 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_middle::ty::{TraitPredicate, TypeVisitableExt};
use rustc_span::ErrorGuaranteed; use rustc_span::ErrorGuaranteed;
@ -315,7 +315,7 @@ impl<'tcx> assembly::GoalKind<'tcx> for TraitPredicate<'tcx> {
.map_bound(|(inputs, _)| { .map_bound(|(inputs, _)| {
ty::TraitRef::new(tcx, goal.predicate.def_id(), [goal.predicate.self_ty(), 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. // 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...) // (FIXME: technically we only need to check this if the type is a fn ptr...)
Self::probe_and_consider_implied_clause( 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], [goal.predicate.self_ty(), tupled_inputs_ty],
) )
}) })
.to_predicate(tcx); .upcast(tcx);
// A built-in `AsyncFn` impl only holds if the output is sized. // 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...) // (FIXME: technically we only need to check this if the type is a fn ptr...)
Self::probe_and_consider_implied_clause( Self::probe_and_consider_implied_clause(
@ -560,7 +560,7 @@ impl<'tcx> assembly::GoalKind<'tcx> for TraitPredicate<'tcx> {
CandidateSource::BuiltinImpl(BuiltinImplSource::Misc), CandidateSource::BuiltinImpl(BuiltinImplSource::Misc),
goal, goal,
ty::TraitRef::new(tcx, goal.predicate.def_id(), [self_ty, coroutine.resume_ty()]) 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, // Technically, we need to check that the coroutine types are Sized,
// but that's already proven by the coroutine being WF. // but that's already proven by the coroutine being WF.
[], [],

View file

@ -303,7 +303,7 @@ impl<'tcx> AutoTraitFinder<'tcx> {
Err(SelectionError::Unimplemented) => { Err(SelectionError::Unimplemented) => {
if self.is_param_no_infer(pred.skip_binder().trait_ref.args) { if self.is_param_no_infer(pred.skip_binder().trait_ref.args) {
already_visited.remove(&pred); 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); predicates.push_back(pred);
} else { } else {
debug!( debug!(

View file

@ -25,8 +25,8 @@ use rustc_macros::extension;
use rustc_middle::arena::ArenaAllocatable; use rustc_middle::arena::ArenaAllocatable;
use rustc_middle::traits::query::NoSolution; use rustc_middle::traits::query::NoSolution;
use rustc_middle::ty::error::TypeError; use rustc_middle::ty::error::TypeError;
use rustc_middle::ty::ToPredicate;
use rustc_middle::ty::TypeFoldable; use rustc_middle::ty::TypeFoldable;
use rustc_middle::ty::Upcast;
use rustc_middle::ty::Variance; use rustc_middle::ty::Variance;
use rustc_middle::ty::{self, Ty, TyCtxt}; use rustc_middle::ty::{self, Ty, TyCtxt};
@ -96,7 +96,7 @@ impl<'a, 'tcx> ObligationCtxt<'a, 'tcx> {
cause, cause,
recursion_depth: 0, recursion_depth: 0,
param_env, param_env,
predicate: ty::Binder::dummy(trait_ref).to_predicate(tcx), predicate: ty::Binder::dummy(trait_ref).upcast(tcx),
}); });
} }

View file

@ -31,8 +31,8 @@ use rustc_middle::traits::IsConstable;
use rustc_middle::ty::error::TypeError::{self, Sorts}; use rustc_middle::ty::error::TypeError::{self, Sorts};
use rustc_middle::ty::{ use rustc_middle::ty::{
self, suggest_arbitrary_trait_bound, suggest_constraining_type_param, AdtKind, GenericArgs, self, suggest_arbitrary_trait_bound, suggest_constraining_type_param, AdtKind, GenericArgs,
InferTy, IsSuggestable, ToPredicate, Ty, TyCtxt, TypeFoldable, TypeFolder, TypeSuperFoldable, InferTy, IsSuggestable, Ty, TyCtxt, TypeFoldable, TypeFolder, TypeSuperFoldable,
TypeVisitableExt, TypeckResults, TypeVisitableExt, TypeckResults, Upcast,
}; };
use rustc_middle::{bug, span_bug}; use rustc_middle::{bug, span_bug};
use rustc_span::def_id::LocalDefId; use rustc_span::def_id::LocalDefId;
@ -192,7 +192,7 @@ pub fn suggest_restriction<'tcx, G: EmissionGuarantee>(
}, },
// `fn foo(t: impl Trait)` // `fn foo(t: impl Trait)`
// ^ suggest `where <T as Trait>::A: Bound` // ^ suggest `where <T as Trait>::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()))); 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, .. })), .find(|p| !matches!(p.kind, hir::GenericParamKind::Type { synthetic: true, .. })),
super_traits, super_traits,
) { ) {
(_, None) => predicate_constraint(hir_generics, trait_pred.to_predicate(tcx)), (_, None) => predicate_constraint(hir_generics, trait_pred.upcast(tcx)),
(None, Some((ident, []))) => ( (None, Some((ident, []))) => (
ident.span.shrink_to_hi(), ident.span.shrink_to_hi(),
format!(": {}", trait_pred.print_modifiers_and_trait_path()), format!(": {}", trait_pred.print_modifiers_and_trait_path()),
@ -2703,12 +2703,12 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
obligated_types: &mut Vec<Ty<'tcx>>, obligated_types: &mut Vec<Ty<'tcx>>,
seen_requirements: &mut FxHashSet<DefId>, seen_requirements: &mut FxHashSet<DefId>,
) where ) where
T: ToPredicate<'tcx>, T: Upcast<'tcx>,
{ {
let mut long_ty_file = None; let mut long_ty_file = None;
let tcx = self.tcx; let tcx = self.tcx;
let predicate = predicate.to_predicate(tcx); let predicate = predicate.upcast(tcx);
match *cause_code { match *cause_code {
ObligationCauseCode::ExprAssignable ObligationCauseCode::ExprAssignable
| ObligationCauseCode::MatchExpressionArm { .. } | ObligationCauseCode::MatchExpressionArm { .. }
@ -3378,7 +3378,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
break; break;
} }
data = derived; data = derived;
parent_predicate = child_trait_ref.to_predicate(tcx); parent_predicate = child_trait_ref.upcast(tcx);
parent_trait_pred = child_trait_ref; parent_trait_pred = child_trait_ref;
} }
} }
@ -3392,7 +3392,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
} }
count += 1; count += 1;
data = &child.derived; data = &child.derived;
parent_predicate = child_trait_pred.to_predicate(tcx); parent_predicate = child_trait_pred.upcast(tcx);
parent_trait_pred = child_trait_pred; parent_trait_pred = child_trait_pred;
} }
if count > 0 { if count > 0 {

View file

@ -42,8 +42,8 @@ use rustc_middle::ty::print::{
PrintTraitRefExt as _, PrintTraitRefExt as _,
}; };
use rustc_middle::ty::{ use rustc_middle::ty::{
self, SubtypePredicate, ToPolyTraitRef, ToPredicate, TraitRef, Ty, TyCtxt, TypeFoldable, self, SubtypePredicate, ToPolyTraitRef, TraitRef, Ty, TyCtxt, TypeFoldable, TypeVisitable,
TypeVisitable, TypeVisitableExt, TypeVisitableExt, Upcast,
}; };
use rustc_middle::{bug, span_bug}; use rustc_middle::{bug, span_bug};
use rustc_session::config::DumpSolverProofTree; use rustc_session::config::DumpSolverProofTree;
@ -302,9 +302,9 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
suggest_increasing_limit: bool, suggest_increasing_limit: bool,
) -> ! ) -> !
where 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); let predicate = self.resolve_vars_if_possible(predicate);
self.report_overflow_error( self.report_overflow_error(
OverflowCause::TraitSolver(predicate), OverflowCause::TraitSolver(predicate),

View file

@ -34,7 +34,7 @@ use rustc_middle::query::Providers;
use rustc_middle::span_bug; use rustc_middle::span_bug;
use rustc_middle::ty::fold::TypeFoldable; use rustc_middle::ty::fold::TypeFoldable;
use rustc_middle::ty::visit::{TypeVisitable, TypeVisitableExt}; 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_middle::ty::{GenericArgs, GenericArgsRef};
use rustc_span::def_id::DefId; use rustc_span::def_id::DefId;
use rustc_span::Span; 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>( fn pred_known_to_hold_modulo_regions<'tcx>(
infcx: &InferCtxt<'tcx>, infcx: &InferCtxt<'tcx>,
param_env: ty::ParamEnv<'tcx>, param_env: ty::ParamEnv<'tcx>,
pred: impl ToPredicate<'tcx>, pred: impl Upcast<'tcx>,
) -> bool { ) -> bool {
let obligation = Obligation::new(infcx.tcx, ObligationCause::dummy(), param_env, pred); let obligation = Obligation::new(infcx.tcx, ObligationCause::dummy(), param_env, pred);
@ -457,7 +457,7 @@ fn instantiate_and_check_impossible_predicates<'tcx>(
// associated items. // associated items.
if let Some(trait_def_id) = tcx.trait_of_item(key.0) { 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); 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()); predicates.retain(|predicate| !predicate.has_param());

View file

@ -22,7 +22,7 @@ use rustc_middle::ty::{
TypeVisitable, TypeVisitor, TypeVisitable, TypeVisitor,
}; };
use rustc_middle::ty::{GenericArg, GenericArgs}; 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_session::lint::builtin::WHERE_CLAUSES_OBJECT_SAFETY;
use rustc_span::symbol::Symbol; use rustc_span::symbol::Symbol;
use rustc_span::Span; use rustc_span::Span;
@ -649,7 +649,7 @@ fn object_ty_for_trait<'tcx>(
)); ));
debug!(?trait_predicate); 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]) let mut elaborated_predicates: Vec<_> = elaborate(tcx, [pred])
.filter_map(|pred| { .filter_map(|pred| {
debug!(?pred); debug!(?pred);
@ -753,7 +753,7 @@ fn receiver_is_dispatchable<'tcx>(
// Self: Unsize<U> // Self: Unsize<U>
let unsize_predicate = let unsize_predicate =
ty::TraitRef::new(tcx, unsize_did, [tcx.types.self_param, unsized_self_ty]) ty::TraitRef::new(tcx, unsize_did, [tcx.types.self_param, unsized_self_ty])
.to_predicate(tcx); .upcast(tcx);
// U: Trait<Arg1, ..., ArgN> // U: Trait<Arg1, ..., ArgN>
let trait_predicate = { 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) } 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 = let caller_bounds =

View file

@ -35,7 +35,7 @@ use rustc_infer::infer::DefineOpaqueTypes;
use rustc_middle::traits::select::OverflowError; use rustc_middle::traits::select::OverflowError;
use rustc_middle::ty::fold::TypeFoldable; use rustc_middle::ty::fold::TypeFoldable;
use rustc_middle::ty::visit::{MaxUniverse, TypeVisitable, TypeVisitableExt}; 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; use rustc_span::symbol::sym;
pub use rustc_middle::traits::Reveal; pub use rustc_middle::traits::Reveal;
@ -538,7 +538,7 @@ fn normalize_to_error<'a, 'tcx>(
cause, cause,
recursion_depth: depth, recursion_depth: depth,
param_env, param_env,
predicate: trait_ref.to_predicate(selcx.tcx()), predicate: trait_ref.upcast(selcx.tcx()),
}; };
Normalized { value: new_value, obligations: vec![trait_obligation] } Normalized { value: new_value, obligations: vec![trait_obligation] }
} }
@ -877,7 +877,7 @@ fn assemble_candidates_from_object_ty<'cx, 'tcx>(
let env_predicates = data let env_predicates = data
.projection_bounds() .projection_bounds()
.filter(|bound| bound.item_def_id() == obligation.predicate.def_id) .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( assemble_candidates_from_predicates(
selcx, selcx,

View file

@ -14,8 +14,8 @@ use rustc_infer::infer::{DefineOpaqueTypes, InferOk};
use rustc_infer::traits::ObligationCauseCode; use rustc_infer::traits::ObligationCauseCode;
use rustc_middle::traits::{BuiltinImplSource, SignatureMismatchData}; use rustc_middle::traits::{BuiltinImplSource, SignatureMismatchData};
use rustc_middle::ty::{ use rustc_middle::ty::{
self, GenericArgs, GenericArgsRef, GenericParamDefKind, ToPolyTraitRef, ToPredicate, self, GenericArgs, GenericArgsRef, GenericParamDefKind, ToPolyTraitRef, TraitPredicate, Ty,
TraitPredicate, Ty, TyCtxt, TyCtxt, Upcast,
}; };
use rustc_middle::{bug, span_bug}; use rustc_middle::{bug, span_bug};
use rustc_span::def_id::DefId; 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 assoc_ty_args = tcx.mk_args(&args);
let bound = let bound =
bound.map_bound(|b| b.kind().skip_binder()).instantiate(tcx, assoc_ty_args); 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( let normalized_bound = normalize_with_depth_to(
self, self,
@ -1253,13 +1253,13 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
tcx.require_lang_item(LangItem::Sized, Some(obligation.cause.span)), tcx.require_lang_item(LangItem::Sized, Some(obligation.cause.span)),
[source], [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 // If the type is `Foo + 'a`, ensure that the type
// being cast to `Foo + 'a` outlives `'a`: // being cast to `Foo + 'a` outlives `'a`:
let outlives = ty::OutlivesPredicate(source, r); let outlives = ty::OutlivesPredicate(source, r);
nested.push(predicate_to_obligation( 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) ImplSource::Builtin(BuiltinImplSource::Misc, nested)

View file

@ -45,7 +45,7 @@ use rustc_middle::ty::abstract_const::NotConstEvaluatable;
use rustc_middle::ty::print::PrintTraitRefExt as _; use rustc_middle::ty::print::PrintTraitRefExt as _;
use rustc_middle::ty::relate::TypeRelation; use rustc_middle::ty::relate::TypeRelation;
use rustc_middle::ty::GenericArgsRef; 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_middle::ty::{Ty, TyCtxt, TypeFoldable, TypeVisitableExt};
use rustc_span::symbol::sym; use rustc_span::symbol::sym;
use rustc_span::Symbol; 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 cycle = stack.iter().take_while(|s| s.depth > stack_arg.1);
let tcx = self.tcx(); let tcx = self.tcx();
let cycle = let cycle =
cycle.map(|stack| stack.obligation.predicate.to_predicate(tcx)); cycle.map(|stack| stack.obligation.predicate.upcast(tcx));
if self.coinductive_match(cycle) { if self.coinductive_match(cycle) {
stack.update_reached_depth(stack_arg.1); stack.update_reached_depth(stack_arg.1);
return Ok(EvaluatedToOk); return Ok(EvaluatedToOk);
@ -1174,7 +1174,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
// if the regions match exactly. // if the regions match exactly.
let cycle = stack.iter().skip(1).take_while(|s| s.depth >= cycle_depth); let cycle = stack.iter().skip(1).take_while(|s| s.depth >= cycle_depth);
let tcx = self.tcx(); 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) { if self.coinductive_match(cycle) {
debug!("evaluate_stack --> recursive, coinductive"); debug!("evaluate_stack --> recursive, coinductive");
Some(EvaluatedToOk) Some(EvaluatedToOk)
@ -1379,7 +1379,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
error_obligation: &Obligation<'tcx, T>, error_obligation: &Obligation<'tcx, T>,
) -> Result<(), OverflowError> ) -> Result<(), OverflowError>
where where
T: ToPredicate<'tcx> + Clone, T: Upcast<'tcx> + Clone,
{ {
if !self.infcx.tcx.recursion_limit().value_within_limit(depth) { if !self.infcx.tcx.recursion_limit().value_within_limit(depth) {
match self.query_mode { match self.query_mode {
@ -1408,7 +1408,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
error_obligation: &Obligation<'tcx, V>, error_obligation: &Obligation<'tcx, V>,
) -> Result<(), OverflowError> ) -> Result<(), OverflowError>
where where
V: ToPredicate<'tcx> + Clone, V: Upcast<'tcx> + Clone,
{ {
self.check_recursion_depth(obligation.recursion_depth, error_obligation) self.check_recursion_depth(obligation.recursion_depth, error_obligation)
} }

View file

@ -8,7 +8,7 @@ use rustc_hir::def_id::DefId;
use rustc_infer::infer::{InferCtxt, InferOk}; use rustc_infer::infer::{InferCtxt, InferOk};
use rustc_middle::bug; use rustc_middle::bug;
use rustc_middle::ty::GenericArgsRef; 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_middle::ty::{TypeFoldable, TypeFolder, TypeSuperFoldable};
use rustc_span::Span; use rustc_span::Span;
use smallvec::{smallvec, SmallVec}; use smallvec::{smallvec, SmallVec};
@ -105,7 +105,7 @@ impl<'tcx> TraitAliasExpander<'tcx> {
fn expand(&mut self, item: &TraitAliasExpansionInfo<'tcx>) -> bool { fn expand(&mut self, item: &TraitAliasExpansionInfo<'tcx>) -> bool {
let tcx = self.tcx; let tcx = self.tcx;
let trait_ref = item.trait_ref(); 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); debug!("expand_trait_aliases: trait_ref={:?}", trait_ref);
@ -122,7 +122,7 @@ impl<'tcx> TraitAliasExpander<'tcx> {
.iter() .iter()
.rev() .rev()
.skip(1) .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; return false;
} }

View file

@ -9,7 +9,7 @@ use rustc_middle::query::Providers;
use rustc_middle::traits::BuiltinImplSource; use rustc_middle::traits::BuiltinImplSource;
use rustc_middle::ty::visit::TypeVisitableExt; use rustc_middle::ty::visit::TypeVisitableExt;
use rustc_middle::ty::GenericArgs; 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 rustc_span::{sym, Span};
use smallvec::{smallvec, SmallVec}; 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 emit_vptr_on_new_entry = false;
let mut visited = PredicateSet::new(tcx); 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]> = let mut stack: SmallVec<[(ty::PolyTraitRef<'tcx>, _, _); 5]> =
smallvec![(trait_ref, emit_vptr_on_new_entry, maybe_iter(None))]; smallvec![(trait_ref, emit_vptr_on_new_entry, maybe_iter(None))];
visited.insert(predicate); visited.insert(predicate);
@ -130,7 +130,7 @@ fn prepare_vtable_segments_inner<'tcx, T>(
// Find an unvisited supertrait // Find an unvisited supertrait
match direct_super_traits_iter 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 // Push it to the stack for the next iteration of 'diving_in to pick up
Some(unvisited_super_trait) => { Some(unvisited_super_trait) => {
@ -165,7 +165,7 @@ fn prepare_vtable_segments_inner<'tcx, T>(
} }
if let Some(next_inner_most_trait_ref) = 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. // We're throwing away potential constness of super traits here.
// FIXME: handle ~const super traits // FIXME: handle ~const super traits

View file

@ -6,7 +6,7 @@ use rustc_index::bit_set::BitSet;
use rustc_middle::bug; use rustc_middle::bug;
use rustc_middle::query::Providers; use rustc_middle::query::Providers;
use rustc_middle::ty::{self, EarlyBinder, Ty, TyCtxt, TypeVisitableExt, TypeVisitor}; 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::def_id::{DefId, LocalDefId, CRATE_DEF_ID};
use rustc_span::DUMMY_SP; use rustc_span::DUMMY_SP;
use rustc_trait_selection::traits; use rustc_trait_selection::traits;
@ -220,7 +220,7 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for ImplTraitInTraitFinder<'_, 'tcx> {
}, },
self.bound_vars, self.bound_vars,
) )
.to_predicate(self.tcx), .upcast(self.tcx),
); );
// We walk the *un-shifted* alias ty, because we're tracking the de bruijn // We walk the *un-shifted* alias ty, because we're tracking the de bruijn