mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-03 10:33:34 +00:00
Make impls UpcastFrom, implement Upcast for UpcastFrom
This commit is contained in:
parent
412dc28d6a
commit
2684655602
@ -544,180 +544,182 @@ impl<'tcx> ToPolyTraitRef<'tcx> for PolyTraitPredicate<'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
/// An `Into`-like trait that takes `TyCtxt` to perform interner-specific transformations.
|
||||
pub trait Upcast<'tcx, T> {
|
||||
fn upcast(self, tcx: TyCtxt<'tcx>) -> T;
|
||||
}
|
||||
|
||||
impl<'tcx, T> Upcast<'tcx, T> for T {
|
||||
fn upcast(self, _tcx: TyCtxt<'tcx>) -> T {
|
||||
self
|
||||
impl<'tcx, T, U> Upcast<'tcx, U> for T
|
||||
where
|
||||
U: UpcastFrom<'tcx, T>,
|
||||
{
|
||||
fn upcast(self, tcx: TyCtxt<'tcx>) -> U {
|
||||
U::upcast_from(self, tcx)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> Upcast<'tcx, ty::Predicate<'tcx>> for PredicateKind<'tcx> {
|
||||
#[inline(always)]
|
||||
fn upcast(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
|
||||
ty::Binder::dummy(self).upcast(tcx)
|
||||
/// A `From`-like trait that takes `TyCtxt` to perform interner-specific transformations.
|
||||
pub trait UpcastFrom<'tcx, T> {
|
||||
fn upcast_from(from: T, tcx: TyCtxt<'tcx>) -> Self;
|
||||
}
|
||||
|
||||
impl<'tcx, T> UpcastFrom<'tcx, T> for T {
|
||||
fn upcast_from(from: T, _tcx: TyCtxt<'tcx>) -> Self {
|
||||
from
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> Upcast<'tcx, ty::Predicate<'tcx>> for Binder<'tcx, PredicateKind<'tcx>> {
|
||||
#[inline(always)]
|
||||
fn upcast(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
|
||||
tcx.mk_predicate(self)
|
||||
impl<'tcx> UpcastFrom<'tcx, PredicateKind<'tcx>> for Predicate<'tcx> {
|
||||
fn upcast_from(from: PredicateKind<'tcx>, tcx: TyCtxt<'tcx>) -> Self {
|
||||
ty::Binder::dummy(from).upcast(tcx)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> Upcast<'tcx, ty::Predicate<'tcx>> for ClauseKind<'tcx> {
|
||||
#[inline(always)]
|
||||
fn upcast(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
|
||||
tcx.mk_predicate(ty::Binder::dummy(ty::PredicateKind::Clause(self)))
|
||||
impl<'tcx> UpcastFrom<'tcx, Binder<'tcx, PredicateKind<'tcx>>> for Predicate<'tcx> {
|
||||
fn upcast_from(from: Binder<'tcx, PredicateKind<'tcx>>, tcx: TyCtxt<'tcx>) -> Self {
|
||||
tcx.mk_predicate(from)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> Upcast<'tcx, ty::Predicate<'tcx>> for Binder<'tcx, ClauseKind<'tcx>> {
|
||||
#[inline(always)]
|
||||
fn upcast(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
|
||||
tcx.mk_predicate(self.map_bound(ty::PredicateKind::Clause))
|
||||
impl<'tcx> UpcastFrom<'tcx, ClauseKind<'tcx>> for Predicate<'tcx> {
|
||||
fn upcast_from(from: ClauseKind<'tcx>, tcx: TyCtxt<'tcx>) -> Self {
|
||||
tcx.mk_predicate(ty::Binder::dummy(PredicateKind::Clause(from)))
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> Upcast<'tcx, ty::Predicate<'tcx>> for Clause<'tcx> {
|
||||
#[inline(always)]
|
||||
fn upcast(self, _tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
|
||||
self.as_predicate()
|
||||
impl<'tcx> UpcastFrom<'tcx, Binder<'tcx, ClauseKind<'tcx>>> for Predicate<'tcx> {
|
||||
fn upcast_from(from: Binder<'tcx, ClauseKind<'tcx>>, tcx: TyCtxt<'tcx>) -> Self {
|
||||
tcx.mk_predicate(from.map_bound(PredicateKind::Clause))
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> Upcast<'tcx, Clause<'tcx>> for ClauseKind<'tcx> {
|
||||
#[inline(always)]
|
||||
fn upcast(self, tcx: TyCtxt<'tcx>) -> Clause<'tcx> {
|
||||
tcx.mk_predicate(Binder::dummy(ty::PredicateKind::Clause(self))).expect_clause()
|
||||
impl<'tcx> UpcastFrom<'tcx, Clause<'tcx>> for Predicate<'tcx> {
|
||||
fn upcast_from(from: Clause<'tcx>, _tcx: TyCtxt<'tcx>) -> Self {
|
||||
from.as_predicate()
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> Upcast<'tcx, Clause<'tcx>> for Binder<'tcx, ClauseKind<'tcx>> {
|
||||
#[inline(always)]
|
||||
fn upcast(self, tcx: TyCtxt<'tcx>) -> Clause<'tcx> {
|
||||
tcx.mk_predicate(self.map_bound(|clause| ty::PredicateKind::Clause(clause))).expect_clause()
|
||||
impl<'tcx> UpcastFrom<'tcx, ClauseKind<'tcx>> for Clause<'tcx> {
|
||||
fn upcast_from(from: ClauseKind<'tcx>, tcx: TyCtxt<'tcx>) -> Self {
|
||||
tcx.mk_predicate(Binder::dummy(PredicateKind::Clause(from))).expect_clause()
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> Upcast<'tcx, ty::Predicate<'tcx>> for TraitRef<'tcx> {
|
||||
#[inline(always)]
|
||||
fn upcast(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
|
||||
ty::Binder::dummy(self).upcast(tcx)
|
||||
impl<'tcx> UpcastFrom<'tcx, Binder<'tcx, ClauseKind<'tcx>>> for Clause<'tcx> {
|
||||
fn upcast_from(from: Binder<'tcx, ClauseKind<'tcx>>, tcx: TyCtxt<'tcx>) -> Self {
|
||||
tcx.mk_predicate(from.map_bound(|clause| PredicateKind::Clause(clause))).expect_clause()
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> Upcast<'tcx, TraitPredicate<'tcx>> for TraitRef<'tcx> {
|
||||
#[inline(always)]
|
||||
fn upcast(self, _tcx: TyCtxt<'tcx>) -> TraitPredicate<'tcx> {
|
||||
TraitPredicate { trait_ref: self, polarity: PredicatePolarity::Positive }
|
||||
impl<'tcx> UpcastFrom<'tcx, TraitRef<'tcx>> for Predicate<'tcx> {
|
||||
fn upcast_from(from: TraitRef<'tcx>, tcx: TyCtxt<'tcx>) -> Self {
|
||||
ty::Binder::dummy(from).upcast(tcx)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> Upcast<'tcx, Clause<'tcx>> for TraitRef<'tcx> {
|
||||
#[inline(always)]
|
||||
fn upcast(self, tcx: TyCtxt<'tcx>) -> Clause<'tcx> {
|
||||
let p: Predicate<'tcx> = self.upcast(tcx);
|
||||
impl<'tcx> UpcastFrom<'tcx, TraitRef<'tcx>> for TraitPredicate<'tcx> {
|
||||
fn upcast_from(from: TraitRef<'tcx>, _tcx: TyCtxt<'tcx>) -> Self {
|
||||
TraitPredicate { trait_ref: from, polarity: PredicatePolarity::Positive }
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> UpcastFrom<'tcx, TraitRef<'tcx>> for Clause<'tcx> {
|
||||
fn upcast_from(from: TraitRef<'tcx>, tcx: TyCtxt<'tcx>) -> Self {
|
||||
let p: Predicate<'tcx> = from.upcast(tcx);
|
||||
p.expect_clause()
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> Upcast<'tcx, ty::Predicate<'tcx>> for Binder<'tcx, TraitRef<'tcx>> {
|
||||
#[inline(always)]
|
||||
fn upcast(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
|
||||
let pred: PolyTraitPredicate<'tcx> = self.upcast(tcx);
|
||||
impl<'tcx> UpcastFrom<'tcx, Binder<'tcx, TraitRef<'tcx>>> for Predicate<'tcx> {
|
||||
fn upcast_from(from: Binder<'tcx, TraitRef<'tcx>>, tcx: TyCtxt<'tcx>) -> Self {
|
||||
let pred: PolyTraitPredicate<'tcx> = from.upcast(tcx);
|
||||
pred.upcast(tcx)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> Upcast<'tcx, Clause<'tcx>> for Binder<'tcx, TraitRef<'tcx>> {
|
||||
#[inline(always)]
|
||||
fn upcast(self, tcx: TyCtxt<'tcx>) -> Clause<'tcx> {
|
||||
let pred: PolyTraitPredicate<'tcx> = self.upcast(tcx);
|
||||
impl<'tcx> UpcastFrom<'tcx, Binder<'tcx, TraitRef<'tcx>>> for Clause<'tcx> {
|
||||
fn upcast_from(from: Binder<'tcx, TraitRef<'tcx>>, tcx: TyCtxt<'tcx>) -> Self {
|
||||
let pred: PolyTraitPredicate<'tcx> = from.upcast(tcx);
|
||||
pred.upcast(tcx)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> Upcast<'tcx, PolyTraitPredicate<'tcx>> for Binder<'tcx, TraitRef<'tcx>> {
|
||||
#[inline(always)]
|
||||
fn upcast(self, _: TyCtxt<'tcx>) -> PolyTraitPredicate<'tcx> {
|
||||
self.map_bound(|trait_ref| TraitPredicate {
|
||||
impl<'tcx> UpcastFrom<'tcx, Binder<'tcx, TraitRef<'tcx>>> for PolyTraitPredicate<'tcx> {
|
||||
fn upcast_from(from: Binder<'tcx, TraitRef<'tcx>>, _tcx: TyCtxt<'tcx>) -> Self {
|
||||
from.map_bound(|trait_ref| TraitPredicate {
|
||||
trait_ref,
|
||||
polarity: ty::PredicatePolarity::Positive,
|
||||
polarity: PredicatePolarity::Positive,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> Upcast<'tcx, ty::Predicate<'tcx>> for TraitPredicate<'tcx> {
|
||||
fn upcast(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
|
||||
PredicateKind::Clause(ClauseKind::Trait(self)).upcast(tcx)
|
||||
impl<'tcx> UpcastFrom<'tcx, TraitPredicate<'tcx>> for Predicate<'tcx> {
|
||||
fn upcast_from(from: TraitPredicate<'tcx>, tcx: TyCtxt<'tcx>) -> Self {
|
||||
PredicateKind::Clause(ClauseKind::Trait(from)).upcast(tcx)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> Upcast<'tcx, ty::Predicate<'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> UpcastFrom<'tcx, PolyTraitPredicate<'tcx>> for Predicate<'tcx> {
|
||||
fn upcast_from(from: PolyTraitPredicate<'tcx>, tcx: TyCtxt<'tcx>) -> Self {
|
||||
from.map_bound(|p| PredicateKind::Clause(ClauseKind::Trait(p))).upcast(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);
|
||||
impl<'tcx> UpcastFrom<'tcx, TraitPredicate<'tcx>> for Clause<'tcx> {
|
||||
fn upcast_from(from: TraitPredicate<'tcx>, tcx: TyCtxt<'tcx>) -> Self {
|
||||
let p: Predicate<'tcx> = from.upcast(tcx);
|
||||
p.expect_clause()
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> Upcast<'tcx, Clause<'tcx>> for PolyTraitPredicate<'tcx> {
|
||||
fn upcast(self, tcx: TyCtxt<'tcx>) -> Clause<'tcx> {
|
||||
let p: Predicate<'tcx> = self.upcast(tcx);
|
||||
impl<'tcx> UpcastFrom<'tcx, PolyTraitPredicate<'tcx>> for Clause<'tcx> {
|
||||
fn upcast_from(from: PolyTraitPredicate<'tcx>, tcx: TyCtxt<'tcx>) -> Self {
|
||||
let p: Predicate<'tcx> = from.upcast(tcx);
|
||||
p.expect_clause()
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> Upcast<'tcx, ty::Predicate<'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> UpcastFrom<'tcx, PolyRegionOutlivesPredicate<'tcx>> for Predicate<'tcx> {
|
||||
fn upcast_from(from: PolyRegionOutlivesPredicate<'tcx>, tcx: TyCtxt<'tcx>) -> Self {
|
||||
from.map_bound(|p| PredicateKind::Clause(ClauseKind::RegionOutlives(p))).upcast(tcx)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> Upcast<'tcx, ty::Predicate<'tcx>> for OutlivesPredicate<Ty<'tcx>, ty::Region<'tcx>> {
|
||||
fn upcast(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
|
||||
ty::Binder::dummy(PredicateKind::Clause(ClauseKind::TypeOutlives(self))).upcast(tcx)
|
||||
impl<'tcx> UpcastFrom<'tcx, OutlivesPredicate<Ty<'tcx>, ty::Region<'tcx>>> for Predicate<'tcx> {
|
||||
fn upcast_from(from: OutlivesPredicate<Ty<'tcx>, ty::Region<'tcx>>, tcx: TyCtxt<'tcx>) -> Self {
|
||||
ty::Binder::dummy(PredicateKind::Clause(ClauseKind::TypeOutlives(from))).upcast(tcx)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> Upcast<'tcx, ty::Predicate<'tcx>> for ProjectionPredicate<'tcx> {
|
||||
fn upcast(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
|
||||
ty::Binder::dummy(PredicateKind::Clause(ClauseKind::Projection(self))).upcast(tcx)
|
||||
impl<'tcx> UpcastFrom<'tcx, ProjectionPredicate<'tcx>> for Predicate<'tcx> {
|
||||
fn upcast_from(from: ProjectionPredicate<'tcx>, tcx: TyCtxt<'tcx>) -> Self {
|
||||
ty::Binder::dummy(PredicateKind::Clause(ClauseKind::Projection(from))).upcast(tcx)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> Upcast<'tcx, ty::Predicate<'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> UpcastFrom<'tcx, PolyProjectionPredicate<'tcx>> for Predicate<'tcx> {
|
||||
fn upcast_from(from: PolyProjectionPredicate<'tcx>, tcx: TyCtxt<'tcx>) -> Self {
|
||||
from.map_bound(|p| PredicateKind::Clause(ClauseKind::Projection(p))).upcast(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);
|
||||
impl<'tcx> UpcastFrom<'tcx, ProjectionPredicate<'tcx>> for Clause<'tcx> {
|
||||
fn upcast_from(from: ProjectionPredicate<'tcx>, tcx: TyCtxt<'tcx>) -> Self {
|
||||
let p: Predicate<'tcx> = from.upcast(tcx);
|
||||
p.expect_clause()
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> Upcast<'tcx, Clause<'tcx>> for PolyProjectionPredicate<'tcx> {
|
||||
fn upcast(self, tcx: TyCtxt<'tcx>) -> Clause<'tcx> {
|
||||
let p: Predicate<'tcx> = self.upcast(tcx);
|
||||
impl<'tcx> UpcastFrom<'tcx, PolyProjectionPredicate<'tcx>> for Clause<'tcx> {
|
||||
fn upcast_from(from: PolyProjectionPredicate<'tcx>, tcx: TyCtxt<'tcx>) -> Self {
|
||||
let p: Predicate<'tcx> = from.upcast(tcx);
|
||||
p.expect_clause()
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> Upcast<'tcx, ty::Predicate<'tcx>> for NormalizesTo<'tcx> {
|
||||
fn upcast(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
|
||||
PredicateKind::NormalizesTo(self).upcast(tcx)
|
||||
impl<'tcx> UpcastFrom<'tcx, NormalizesTo<'tcx>> for Predicate<'tcx> {
|
||||
fn upcast_from(from: NormalizesTo<'tcx>, tcx: TyCtxt<'tcx>) -> Self {
|
||||
PredicateKind::NormalizesTo(from).upcast(tcx)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -286,7 +286,7 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
|
||||
return self.forced_ambiguity(MaybeCause::Ambiguity).into_iter().collect();
|
||||
}
|
||||
|
||||
let goal =
|
||||
let goal: Goal<'tcx, G> =
|
||||
goal.with(self.tcx(), goal.predicate.with_self_ty(self.tcx(), normalized_self_ty));
|
||||
// Vars that show up in the rest of the goal substs may have been constrained by
|
||||
// normalizing the self type as well, since type variables are not uniquified.
|
||||
|
Loading…
Reference in New Issue
Block a user