@@ -8,8 +8,8 @@ use rustc_type_ir as ir;
88use std:: cmp:: Ordering ;
99
1010use crate :: ty:: {
11- self , Binder , DebruijnIndex , EarlyBinder , PredicatePolarity , Term , Ty , TyCtxt , TypeFlags ,
12- Upcast , UpcastFrom , WithCachedTypeInfo ,
11+ self , Binder , DebruijnIndex , EarlyBinder , PredicatePolarity , Ty , TyCtxt , TypeFlags , Upcast ,
12+ UpcastFrom , WithCachedTypeInfo ,
1313} ;
1414
1515pub type TraitRef < ' tcx > = ir:: TraitRef < TyCtxt < ' tcx > > ;
@@ -155,6 +155,8 @@ pub struct Clause<'tcx>(
155155 pub ( super ) Interned < ' tcx , WithCachedTypeInfo < ty:: Binder < ' tcx , PredicateKind < ' tcx > > > > ,
156156) ;
157157
158+ impl < ' tcx > rustc_type_ir:: inherent:: Clause < TyCtxt < ' tcx > > for Clause < ' tcx > { }
159+
158160impl < ' tcx > Clause < ' tcx > {
159161 pub fn as_predicate ( self ) -> Predicate < ' tcx > {
160162 Predicate ( self . 0 )
@@ -231,34 +233,6 @@ impl<'tcx> ExistentialPredicate<'tcx> {
231233
232234pub type PolyExistentialPredicate < ' tcx > = ty:: Binder < ' tcx , ExistentialPredicate < ' tcx > > ;
233235
234- impl < ' tcx > PolyExistentialPredicate < ' tcx > {
235- /// Given an existential predicate like `?Self: PartialEq<u32>` (e.g., derived from `dyn PartialEq<u32>`),
236- /// and a concrete type `self_ty`, returns a full predicate where the existentially quantified variable `?Self`
237- /// has been replaced with `self_ty` (e.g., `self_ty: PartialEq<u32>`, in our example).
238- pub fn with_self_ty ( & self , tcx : TyCtxt < ' tcx > , self_ty : Ty < ' tcx > ) -> ty:: Clause < ' tcx > {
239- match self . skip_binder ( ) {
240- ExistentialPredicate :: Trait ( tr) => {
241- self . rebind ( tr) . with_self_ty ( tcx, self_ty) . upcast ( tcx)
242- }
243- ExistentialPredicate :: Projection ( p) => {
244- self . rebind ( p. with_self_ty ( tcx, self_ty) ) . upcast ( tcx)
245- }
246- ExistentialPredicate :: AutoTrait ( did) => {
247- let generics = tcx. generics_of ( did) ;
248- let trait_ref = if generics. own_params . len ( ) == 1 {
249- ty:: TraitRef :: new ( tcx, did, [ self_ty] )
250- } else {
251- // If this is an ill-formed auto trait, then synthesize
252- // new error args for the missing generics.
253- let err_args = ty:: GenericArgs :: extend_with_error ( tcx, did, & [ self_ty. into ( ) ] ) ;
254- ty:: TraitRef :: new ( tcx, did, err_args)
255- } ;
256- self . rebind ( trait_ref) . upcast ( tcx)
257- }
258- }
259- }
260- }
261-
262236impl < ' tcx > ty:: List < ty:: PolyExistentialPredicate < ' tcx > > {
263237 /// Returns the "principal `DefId`" of this set of existential predicates.
264238 ///
@@ -322,49 +296,9 @@ impl<'tcx> ty::List<ty::PolyExistentialPredicate<'tcx>> {
322296}
323297
324298pub type PolyTraitRef < ' tcx > = ty:: Binder < ' tcx , TraitRef < ' tcx > > ;
325-
326- impl < ' tcx > PolyTraitRef < ' tcx > {
327- pub fn self_ty ( & self ) -> ty:: Binder < ' tcx , Ty < ' tcx > > {
328- self . map_bound_ref ( |tr| tr. self_ty ( ) )
329- }
330-
331- pub fn def_id ( & self ) -> DefId {
332- self . skip_binder ( ) . def_id
333- }
334- }
335-
336299pub type PolyExistentialTraitRef < ' tcx > = ty:: Binder < ' tcx , ExistentialTraitRef < ' tcx > > ;
337-
338- impl < ' tcx > PolyExistentialTraitRef < ' tcx > {
339- pub fn def_id ( & self ) -> DefId {
340- self . skip_binder ( ) . def_id
341- }
342-
343- /// Object types don't have a self type specified. Therefore, when
344- /// we convert the principal trait-ref into a normal trait-ref,
345- /// you must give *some* self type. A common choice is `mk_err()`
346- /// or some placeholder type.
347- pub fn with_self_ty ( & self , tcx : TyCtxt < ' tcx > , self_ty : Ty < ' tcx > ) -> ty:: PolyTraitRef < ' tcx > {
348- self . map_bound ( |trait_ref| trait_ref. with_self_ty ( tcx, self_ty) )
349- }
350- }
351-
352300pub type PolyExistentialProjection < ' tcx > = ty:: Binder < ' tcx , ExistentialProjection < ' tcx > > ;
353301
354- impl < ' tcx > PolyExistentialProjection < ' tcx > {
355- pub fn with_self_ty (
356- & self ,
357- tcx : TyCtxt < ' tcx > ,
358- self_ty : Ty < ' tcx > ,
359- ) -> ty:: PolyProjectionPredicate < ' tcx > {
360- self . map_bound ( |p| p. with_self_ty ( tcx, self_ty) )
361- }
362-
363- pub fn item_def_id ( & self ) -> DefId {
364- self . skip_binder ( ) . def_id
365- }
366- }
367-
368302impl < ' tcx > Clause < ' tcx > {
369303 /// Performs a instantiation suitable for going from a
370304 /// poly-trait-ref to supertraits that must hold if that
@@ -473,22 +407,6 @@ impl<'tcx> Clause<'tcx> {
473407
474408pub type PolyTraitPredicate < ' tcx > = ty:: Binder < ' tcx , TraitPredicate < ' tcx > > ;
475409
476- impl < ' tcx > PolyTraitPredicate < ' tcx > {
477- pub fn def_id ( self ) -> DefId {
478- // Ok to skip binder since trait `DefId` does not care about regions.
479- self . skip_binder ( ) . def_id ( )
480- }
481-
482- pub fn self_ty ( self ) -> ty:: Binder < ' tcx , Ty < ' tcx > > {
483- self . map_bound ( |trait_ref| trait_ref. self_ty ( ) )
484- }
485-
486- #[ inline]
487- pub fn polarity ( self ) -> PredicatePolarity {
488- self . skip_binder ( ) . polarity
489- }
490- }
491-
492410/// `A: B`
493411#[ derive( Clone , Copy , PartialEq , Eq , PartialOrd , Ord , Hash , Debug , TyEncodable , TyDecodable ) ]
494412#[ derive( HashStable , TypeFoldable , TypeVisitable , Lift ) ]
@@ -497,47 +415,10 @@ pub type RegionOutlivesPredicate<'tcx> = OutlivesPredicate<ty::Region<'tcx>, ty:
497415pub type TypeOutlivesPredicate < ' tcx > = OutlivesPredicate < Ty < ' tcx > , ty:: Region < ' tcx > > ;
498416pub type PolyRegionOutlivesPredicate < ' tcx > = ty:: Binder < ' tcx , RegionOutlivesPredicate < ' tcx > > ;
499417pub type PolyTypeOutlivesPredicate < ' tcx > = ty:: Binder < ' tcx , TypeOutlivesPredicate < ' tcx > > ;
500-
501418pub type PolySubtypePredicate < ' tcx > = ty:: Binder < ' tcx , SubtypePredicate < ' tcx > > ;
502-
503419pub type PolyCoercePredicate < ' tcx > = ty:: Binder < ' tcx , CoercePredicate < ' tcx > > ;
504-
505420pub type PolyProjectionPredicate < ' tcx > = Binder < ' tcx , ProjectionPredicate < ' tcx > > ;
506421
507- impl < ' tcx > PolyProjectionPredicate < ' tcx > {
508- /// Returns the `DefId` of the trait of the associated item being projected.
509- #[ inline]
510- pub fn trait_def_id ( & self , tcx : TyCtxt < ' tcx > ) -> DefId {
511- self . skip_binder ( ) . projection_term . trait_def_id ( tcx)
512- }
513-
514- /// Get the [PolyTraitRef] required for this projection to be well formed.
515- /// Note that for generic associated types the predicates of the associated
516- /// type also need to be checked.
517- #[ inline]
518- pub fn required_poly_trait_ref ( & self , tcx : TyCtxt < ' tcx > ) -> PolyTraitRef < ' tcx > {
519- // Note: unlike with `TraitRef::to_poly_trait_ref()`,
520- // `self.0.trait_ref` is permitted to have escaping regions.
521- // This is because here `self` has a `Binder` and so does our
522- // return value, so we are preserving the number of binding
523- // levels.
524- self . map_bound ( |predicate| predicate. projection_term . trait_ref ( tcx) )
525- }
526-
527- pub fn term ( & self ) -> Binder < ' tcx , Term < ' tcx > > {
528- self . map_bound ( |predicate| predicate. term )
529- }
530-
531- /// The `DefId` of the `TraitItem` for the associated type.
532- ///
533- /// Note that this is not the `DefId` of the `TraitRef` containing this
534- /// associated type, which is in `tcx.associated_item(projection_def_id()).container`.
535- pub fn projection_def_id ( & self ) -> DefId {
536- // Ok to skip binder since trait `DefId` does not care about regions.
537- self . skip_binder ( ) . projection_term . def_id
538- }
539- }
540-
541422pub trait ToPolyTraitRef < ' tcx > {
542423 fn to_poly_trait_ref ( & self ) -> PolyTraitRef < ' tcx > ;
543424}
0 commit comments