remove impl<'tcx> ToPredicate<'tcx, Clause<'tcx>> for PolyProjectionPredicate<'tcx>

This commit is contained in:
Ziru Niu 2023-09-05 07:21:38 +08:00
parent 2694b84fbf
commit 3c69a107d0
6 changed files with 23 additions and 26 deletions

View File

@ -18,7 +18,7 @@
use rustc_middle::ty::{ use rustc_middle::ty::{
self, GenericArgs, Ty, TypeFoldable, TypeFolder, TypeSuperFoldable, TypeVisitableExt, self, GenericArgs, Ty, TypeFoldable, TypeFolder, TypeSuperFoldable, TypeVisitableExt,
}; };
use rustc_middle::ty::{GenericParamDefKind, ToPredicate, TyCtxt}; use rustc_middle::ty::{GenericParamDefKind, TyCtxt};
use rustc_span::{Span, DUMMY_SP}; use rustc_span::{Span, DUMMY_SP};
use rustc_trait_selection::traits::error_reporting::TypeErrCtxtExt; use rustc_trait_selection::traits::error_reporting::TypeErrCtxtExt;
use rustc_trait_selection::traits::outlives_bounds::InferCtxtExt as _; use rustc_trait_selection::traits::outlives_bounds::InferCtxtExt as _;
@ -2196,16 +2196,16 @@ pub(super) fn check_type_bounds<'tcx>(
// //
// impl<T> X for T where T: X { type Y = <T as X>::Y; } // impl<T> X for T where T: X { type Y = <T as X>::Y; }
} }
_ => predicates.push( _ => predicates.push(ty::Clause::from_projection_clause(
tcx,
ty::Binder::bind_with_vars( ty::Binder::bind_with_vars(
ty::ProjectionPredicate { ty::ProjectionPredicate {
projection_ty: tcx.mk_alias_ty(trait_ty.def_id, rebased_args), projection_ty: tcx.mk_alias_ty(trait_ty.def_id, rebased_args),
term: normalize_impl_ty.into(), term: normalize_impl_ty.into(),
}, },
bound_vars, bound_vars,
) ),
.to_predicate(tcx), )),
),
}; };
ty::ParamEnv::new(tcx.mk_clauses(&predicates), Reveal::UserFacing) ty::ParamEnv::new(tcx.mk_clauses(&predicates), Reveal::UserFacing)
}; };

View File

@ -566,6 +566,11 @@ fn into_diagnostic_arg(self) -> rustc_errors::DiagnosticArgValue<'static> {
pub struct Clause<'tcx>(Interned<'tcx, WithCachedTypeInfo<ty::Binder<'tcx, PredicateKind<'tcx>>>>); pub struct Clause<'tcx>(Interned<'tcx, WithCachedTypeInfo<ty::Binder<'tcx, PredicateKind<'tcx>>>>);
impl<'tcx> Clause<'tcx> { impl<'tcx> Clause<'tcx> {
pub fn from_projection_clause(tcx: TyCtxt<'tcx>, pred: PolyProjectionPredicate<'tcx>) -> Self {
let pred: Predicate<'tcx> = pred.to_predicate(tcx);
pred.expect_clause()
}
pub fn as_predicate(self) -> Predicate<'tcx> { pub fn as_predicate(self) -> Predicate<'tcx> {
Predicate(self.0) Predicate(self.0)
} }
@ -1323,13 +1328,6 @@ fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Clause<'tcx> {
} }
} }
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);
p.expect_clause()
}
}
impl<'tcx> ToPredicate<'tcx> for TraitPredicate<'tcx> { impl<'tcx> ToPredicate<'tcx> for TraitPredicate<'tcx> {
fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> { fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
PredicateKind::Clause(ClauseKind::Trait(self)).to_predicate(tcx) PredicateKind::Clause(ClauseKind::Trait(self)).to_predicate(tcx)

View File

@ -725,7 +725,7 @@ pub fn with_self_ty(&self, tcx: TyCtxt<'tcx>, self_ty: Ty<'tcx>) -> ty::Clause<'
self.rebind(tr).with_self_ty(tcx, self_ty).to_predicate(tcx) self.rebind(tr).with_self_ty(tcx, self_ty).to_predicate(tcx)
} }
ExistentialPredicate::Projection(p) => { ExistentialPredicate::Projection(p) => {
self.rebind(p.with_self_ty(tcx, self_ty)).to_predicate(tcx) ty::Clause::from_projection_clause(tcx, self.rebind(p.with_self_ty(tcx, self_ty)))
} }
ExistentialPredicate::AutoTrait(did) => { ExistentialPredicate::AutoTrait(did) => {
let generics = tcx.generics_of(did); let generics = tcx.generics_of(did);

View File

@ -346,13 +346,15 @@ fn consider_builtin_fn_trait_candidates(
ty::TraitRef::from_lang_item(tcx, LangItem::Sized, DUMMY_SP, [output]) ty::TraitRef::from_lang_item(tcx, LangItem::Sized, DUMMY_SP, [output])
}); });
let pred = tupled_inputs_and_output let pred = ty::Clause::from_projection_clause(
.map_bound(|(inputs, output)| ty::ProjectionPredicate { tcx,
tupled_inputs_and_output.map_bound(|(inputs, output)| ty::ProjectionPredicate {
projection_ty: tcx projection_ty: tcx
.mk_alias_ty(goal.predicate.def_id(), [goal.predicate.self_ty(), inputs]), .mk_alias_ty(goal.predicate.def_id(), [goal.predicate.self_ty(), inputs]),
term: output.into(), term: output.into(),
}) }),
.to_predicate(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::consider_implied_clause(ecx, goal, pred, [goal.with(tcx, output_is_sized_pred)]) Self::consider_implied_clause(ecx, goal, pred, [goal.with(tcx, output_is_sized_pred)])

View File

@ -1644,7 +1644,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| ty::Clause::from_projection_clause(tcx, p.with_self_ty(tcx, object_ty)));
assemble_candidates_from_predicates( assemble_candidates_from_predicates(
selcx, selcx,

View File

@ -4,7 +4,7 @@
use rustc_index::bit_set::BitSet; use rustc_index::bit_set::BitSet;
use rustc_middle::query::Providers; use rustc_middle::query::Providers;
use rustc_middle::ty::{ use rustc_middle::ty::{
self, EarlyBinder, ToPredicate, Ty, TyCtxt, TypeSuperVisitable, TypeVisitable, TypeVisitor, self, EarlyBinder, Ty, TyCtxt, TypeSuperVisitable, TypeVisitable, TypeVisitor,
}; };
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;
@ -220,13 +220,10 @@ fn visit_ty(&mut self, ty: Ty<'tcx>) -> std::ops::ControlFlow<Self::BreakTy> {
// strategy, then just reinterpret the associated type like an opaque :^) // strategy, then just reinterpret the associated type like an opaque :^)
let default_ty = self.tcx.type_of(shifted_alias_ty.def_id).instantiate(self.tcx, shifted_alias_ty.args); let default_ty = self.tcx.type_of(shifted_alias_ty.def_id).instantiate(self.tcx, shifted_alias_ty.args);
self.predicates.push( self.predicates.push(ty::Clause::from_projection_clause(self.tcx, ty::Binder::bind_with_vars(
ty::Binder::bind_with_vars( ty::ProjectionPredicate { projection_ty: shifted_alias_ty, term: default_ty.into() },
ty::ProjectionPredicate { projection_ty: shifted_alias_ty, term: default_ty.into() }, self.bound_vars,
self.bound_vars, )));
)
.to_predicate(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
// binder depth, and if we were to walk `shifted_alias_ty` instead, we'd // binder depth, and if we were to walk `shifted_alias_ty` instead, we'd