@@ -8,8 +8,8 @@ use rustc_type_ir as ir;
8
8
use std:: cmp:: Ordering ;
9
9
10
10
use 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 ,
13
13
} ;
14
14
15
15
pub type TraitRef < ' tcx > = ir:: TraitRef < TyCtxt < ' tcx > > ;
@@ -155,6 +155,8 @@ pub struct Clause<'tcx>(
155
155
pub ( super ) Interned < ' tcx , WithCachedTypeInfo < ty:: Binder < ' tcx , PredicateKind < ' tcx > > > > ,
156
156
) ;
157
157
158
+ impl < ' tcx > rustc_type_ir:: inherent:: Clause < TyCtxt < ' tcx > > for Clause < ' tcx > { }
159
+
158
160
impl < ' tcx > Clause < ' tcx > {
159
161
pub fn as_predicate ( self ) -> Predicate < ' tcx > {
160
162
Predicate ( self . 0 )
@@ -231,34 +233,6 @@ impl<'tcx> ExistentialPredicate<'tcx> {
231
233
232
234
pub type PolyExistentialPredicate < ' tcx > = ty:: Binder < ' tcx , ExistentialPredicate < ' tcx > > ;
233
235
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
-
262
236
impl < ' tcx > ty:: List < ty:: PolyExistentialPredicate < ' tcx > > {
263
237
/// Returns the "principal `DefId`" of this set of existential predicates.
264
238
///
@@ -322,49 +296,9 @@ impl<'tcx> ty::List<ty::PolyExistentialPredicate<'tcx>> {
322
296
}
323
297
324
298
pub 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
-
336
299
pub 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
-
352
300
pub type PolyExistentialProjection < ' tcx > = ty:: Binder < ' tcx , ExistentialProjection < ' tcx > > ;
353
301
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
-
368
302
impl < ' tcx > Clause < ' tcx > {
369
303
/// Performs a instantiation suitable for going from a
370
304
/// poly-trait-ref to supertraits that must hold if that
@@ -473,22 +407,6 @@ impl<'tcx> Clause<'tcx> {
473
407
474
408
pub type PolyTraitPredicate < ' tcx > = ty:: Binder < ' tcx , TraitPredicate < ' tcx > > ;
475
409
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
-
492
410
/// `A: B`
493
411
#[ derive( Clone , Copy , PartialEq , Eq , PartialOrd , Ord , Hash , Debug , TyEncodable , TyDecodable ) ]
494
412
#[ derive( HashStable , TypeFoldable , TypeVisitable , Lift ) ]
@@ -497,47 +415,10 @@ pub type RegionOutlivesPredicate<'tcx> = OutlivesPredicate<ty::Region<'tcx>, ty:
497
415
pub type TypeOutlivesPredicate < ' tcx > = OutlivesPredicate < Ty < ' tcx > , ty:: Region < ' tcx > > ;
498
416
pub type PolyRegionOutlivesPredicate < ' tcx > = ty:: Binder < ' tcx , RegionOutlivesPredicate < ' tcx > > ;
499
417
pub type PolyTypeOutlivesPredicate < ' tcx > = ty:: Binder < ' tcx , TypeOutlivesPredicate < ' tcx > > ;
500
-
501
418
pub type PolySubtypePredicate < ' tcx > = ty:: Binder < ' tcx , SubtypePredicate < ' tcx > > ;
502
-
503
419
pub type PolyCoercePredicate < ' tcx > = ty:: Binder < ' tcx , CoercePredicate < ' tcx > > ;
504
-
505
420
pub type PolyProjectionPredicate < ' tcx > = Binder < ' tcx , ProjectionPredicate < ' tcx > > ;
506
421
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
-
541
422
pub trait ToPolyTraitRef < ' tcx > {
542
423
fn to_poly_trait_ref ( & self ) -> PolyTraitRef < ' tcx > ;
543
424
}
0 commit comments