Add new ToPredicate
impls and TraitRef
methods to remove some ty::Binber::dummy
calls
This commit is contained in:
parent
4f2532fb53
commit
1b8c7784e5
9 changed files with 46 additions and 32 deletions
|
@ -1207,6 +1207,18 @@ impl<'tcx> ToPredicate<'tcx, PolyTraitPredicate<'tcx>> for Binder<'tcx, TraitRef
|
|||
}
|
||||
}
|
||||
|
||||
impl<'tcx> ToPredicate<'tcx, PolyTraitPredicate<'tcx>> for TraitRef<'tcx> {
|
||||
fn to_predicate(self, tcx: TyCtxt<'tcx>) -> PolyTraitPredicate<'tcx> {
|
||||
ty::Binder::dummy(self).to_predicate(tcx)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> ToPredicate<'tcx, PolyTraitPredicate<'tcx>> for TraitPredicate<'tcx> {
|
||||
fn to_predicate(self, _tcx: TyCtxt<'tcx>) -> PolyTraitPredicate<'tcx> {
|
||||
ty::Binder::dummy(self)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> ToPredicate<'tcx> for PolyTraitPredicate<'tcx> {
|
||||
fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
|
||||
self.map_bound(|p| PredicateKind::Clause(Clause::Trait(p))).to_predicate(tcx)
|
||||
|
@ -1231,6 +1243,12 @@ impl<'tcx> ToPredicate<'tcx> for PolyProjectionPredicate<'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'tcx> ToPredicate<'tcx> for TraitPredicate<'tcx> {
|
||||
fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
|
||||
PredicateKind::Clause(Clause::Trait(self)).to_predicate(tcx)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> Predicate<'tcx> {
|
||||
pub fn to_opt_poly_trait_pred(self) -> Option<PolyTraitPredicate<'tcx>> {
|
||||
let predicate = self.kind();
|
||||
|
|
|
@ -871,6 +871,18 @@ impl<'tcx> TraitRef<'tcx> {
|
|||
)
|
||||
}
|
||||
|
||||
/// Converts this trait ref to a trait predicate with a given `constness` and a positive polarity.
|
||||
#[inline]
|
||||
pub fn with_constness(self, constness: ty::BoundConstness) -> ty::TraitPredicate<'tcx> {
|
||||
ty::TraitPredicate { trait_ref: self, constness, polarity: ty::ImplPolarity::Positive }
|
||||
}
|
||||
|
||||
/// Converts this trait ref to a trait predicate without `const` and a positive polarity.
|
||||
#[inline]
|
||||
pub fn without_const(self) -> ty::TraitPredicate<'tcx> {
|
||||
self.with_constness(ty::BoundConstness::NotConst)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn self_ty(&self) -> Ty<'tcx> {
|
||||
self.substs.type_at(0)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue