@@ -8,7 +8,7 @@ use rustc_infer::infer::InferCtxt;
8
8
use rustc_middle:: ty:: {
9
9
fold:: { BottomUpFolder , TypeFoldable , TypeFolder } ,
10
10
subst:: { GenericArg , InternalSubsts , SubstsRef } ,
11
- GenericParamDefKind , ParamEnv , Predicate , Region , TraitRef , Ty , TyCtxt ,
11
+ GenericParamDefKind , ParamEnv , Predicate , Region , TraitRef , Ty , TyCtxt , Unevaluated ,
12
12
} ;
13
13
use std:: collections:: HashMap ;
14
14
@@ -376,97 +376,99 @@ impl<'a, 'tcx> TranslationContext<'a, 'tcx> {
376
376
predicate : Predicate < ' tcx > ,
377
377
) -> Option < Predicate < ' tcx > > {
378
378
use rustc_middle:: ty:: {
379
- OutlivesPredicate , PredicateKind , ProjectionPredicate , ProjectionTy , SubtypePredicate ,
380
- ToPredicate , TraitPredicate , WithOptConstParam ,
379
+ self , CoercePredicate , OutlivesPredicate , PredicateKind , ProjectionPredicate ,
380
+ ProjectionTy , SubtypePredicate , ToPredicate , TraitPredicate , WithOptConstParam ,
381
381
} ;
382
382
383
- Some (
384
- match predicate. kind ( ) . skip_binder ( ) {
385
- PredicateKind :: Trait ( pred, constness) => PredicateKind :: Trait (
386
- if let Some ( ( target_def_id, target_substs) ) = self . translate_orig_substs (
387
- index_map,
388
- pred. trait_ref . def_id ,
389
- pred. trait_ref . substs ,
390
- ) {
391
- TraitPredicate {
392
- trait_ref : TraitRef {
393
- def_id : target_def_id,
394
- substs : target_substs,
395
- } ,
396
- }
397
- } else {
398
- return None ;
399
- } ,
400
- constness,
401
- ) ,
402
- PredicateKind :: RegionOutlives ( pred) => PredicateKind :: RegionOutlives ( {
403
- let l = self . translate_region ( pred. 0 ) ;
404
- let r = self . translate_region ( pred. 1 ) ;
405
- OutlivesPredicate ( l, r)
406
- } ) ,
407
- PredicateKind :: TypeOutlives ( pred) => PredicateKind :: TypeOutlives ( {
408
- let l = self . translate ( index_map, pred. 0 ) ;
409
- let r = self . translate_region ( pred. 1 ) ;
410
- OutlivesPredicate ( l, r)
411
- } ) ,
412
- PredicateKind :: Projection ( pred) => PredicateKind :: Projection (
413
- if let Some ( ( target_def_id, target_substs) ) = self . translate_orig_substs (
414
- index_map,
415
- pred. projection_ty . item_def_id ,
416
- pred. projection_ty . substs ,
417
- ) {
418
- ProjectionPredicate {
419
- projection_ty : ProjectionTy {
420
- substs : target_substs,
421
- item_def_id : target_def_id,
422
- } ,
423
- ty : self . translate ( index_map, pred. ty ) ,
424
- }
425
- } else {
426
- return None ;
427
- } ,
428
- ) ,
429
- PredicateKind :: WellFormed ( ty) => {
430
- PredicateKind :: WellFormed ( self . translate ( index_map, ty) )
431
- }
432
- PredicateKind :: ObjectSafe ( did) => {
433
- PredicateKind :: ObjectSafe ( self . translate_orig ( did) )
434
- }
435
- PredicateKind :: ClosureKind ( did, substs, kind) => PredicateKind :: ClosureKind (
436
- self . translate_orig ( did) ,
437
- self . translate ( index_map, substs) ,
438
- kind,
439
- ) ,
440
- PredicateKind :: Subtype ( pred) => PredicateKind :: Subtype ( {
441
- let l = self . translate ( index_map, pred. a ) ;
442
- let r = self . translate ( index_map, pred. b ) ;
443
- SubtypePredicate {
444
- a_is_expected : pred. a_is_expected ,
445
- a : l,
446
- b : r,
383
+ let pred = match predicate. kind ( ) . skip_binder ( ) {
384
+ PredicateKind :: Trait ( pred) => PredicateKind :: Trait (
385
+ if let Some ( ( target_def_id, target_substs) ) = self . translate_orig_substs (
386
+ index_map,
387
+ pred. trait_ref . def_id ,
388
+ pred. trait_ref . substs ,
389
+ ) {
390
+ TraitPredicate {
391
+ trait_ref : TraitRef {
392
+ def_id : target_def_id,
393
+ substs : target_substs,
394
+ } ,
395
+ constness : pred. constness ,
447
396
}
448
- } ) ,
449
- PredicateKind :: ConstEvaluatable ( param, orig_substs) => {
450
- if let Some ( ( target_def_id, target_substs) ) =
451
- self . translate_orig_substs ( index_map, param. did , orig_substs)
452
- {
453
- // TODO: We could probably use translated version for
454
- // `WithOptConstParam::const_param_did`
455
- let const_param = WithOptConstParam :: unknown ( target_def_id) ;
456
- PredicateKind :: ConstEvaluatable ( const_param, target_substs)
457
- } else {
458
- return None ;
397
+ } else {
398
+ return None ;
399
+ } ,
400
+ ) ,
401
+ PredicateKind :: RegionOutlives ( pred) => PredicateKind :: RegionOutlives ( {
402
+ let l = self . translate_region ( pred. 0 ) ;
403
+ let r = self . translate_region ( pred. 1 ) ;
404
+ OutlivesPredicate ( l, r)
405
+ } ) ,
406
+ PredicateKind :: TypeOutlives ( pred) => PredicateKind :: TypeOutlives ( {
407
+ let l = self . translate ( index_map, pred. 0 ) ;
408
+ let r = self . translate_region ( pred. 1 ) ;
409
+ OutlivesPredicate ( l, r)
410
+ } ) ,
411
+ PredicateKind :: Projection ( pred) => PredicateKind :: Projection (
412
+ if let Some ( ( target_def_id, target_substs) ) = self . translate_orig_substs (
413
+ index_map,
414
+ pred. projection_ty . item_def_id ,
415
+ pred. projection_ty . substs ,
416
+ ) {
417
+ ProjectionPredicate {
418
+ projection_ty : ProjectionTy {
419
+ substs : target_substs,
420
+ item_def_id : target_def_id,
421
+ } ,
422
+ ty : self . translate ( index_map, pred. ty ) ,
459
423
}
424
+ } else {
425
+ return None ;
426
+ } ,
427
+ ) ,
428
+ PredicateKind :: WellFormed ( ty) => {
429
+ PredicateKind :: WellFormed ( self . translate ( index_map, ty) )
430
+ }
431
+ PredicateKind :: ObjectSafe ( did) => PredicateKind :: ObjectSafe ( self . translate_orig ( did) ) ,
432
+ PredicateKind :: ClosureKind ( did, substs, kind) => PredicateKind :: ClosureKind (
433
+ self . translate_orig ( did) ,
434
+ self . translate ( index_map, substs) ,
435
+ kind,
436
+ ) ,
437
+ PredicateKind :: Subtype ( pred) => PredicateKind :: Subtype ( {
438
+ let l = self . translate ( index_map, pred. a ) ;
439
+ let r = self . translate ( index_map, pred. b ) ;
440
+ SubtypePredicate {
441
+ a_is_expected : pred. a_is_expected ,
442
+ a : l,
443
+ b : r,
444
+ }
445
+ } ) ,
446
+ PredicateKind :: Coerce ( pred) => PredicateKind :: Coerce ( {
447
+ let a = self . translate ( index_map, pred. a ) ;
448
+ let b = self . translate ( index_map, pred. b ) ;
449
+ CoercePredicate { a, b }
450
+ } ) ,
451
+ PredicateKind :: ConstEvaluatable ( uv) => {
452
+ if let Some ( ( target_def_id, target_substs) ) =
453
+ self . translate_orig_substs ( index_map, uv. def . did , uv. substs ( self . tcx ) )
454
+ {
455
+ // TODO: We could probably use translated version for
456
+ // `WithOptConstParam::const_param_did`
457
+ let const_param = WithOptConstParam :: unknown ( target_def_id) ;
458
+ PredicateKind :: ConstEvaluatable ( Unevaluated :: new ( const_param, target_substs) )
459
+ } else {
460
+ return None ;
460
461
}
461
- PredicateKind :: ConstEquate ( c1, c2) => PredicateKind :: ConstEquate (
462
- self . translate ( index_map, c1) ,
463
- self . translate ( index_map, c2) ,
464
- ) ,
465
- // NOTE: Only used for Chalk trait solver
466
- PredicateKind :: TypeWellFormedFromEnv ( _) => unimplemented ! ( ) ,
467
462
}
468
- . to_predicate ( self . tcx ) ,
469
- )
463
+ PredicateKind :: ConstEquate ( c1, c2) => PredicateKind :: ConstEquate (
464
+ self . translate ( index_map, c1) ,
465
+ self . translate ( index_map, c2) ,
466
+ ) ,
467
+ // NOTE: Only used for Chalk trait solver
468
+ PredicateKind :: TypeWellFormedFromEnv ( _) => unimplemented ! ( ) ,
469
+ } ;
470
+
471
+ Some ( ty:: Binder :: dummy ( pred) . to_predicate ( self . tcx ) )
470
472
}
471
473
472
474
/// Translate a slice of predicates in the context of an item.
0 commit comments