@@ -2,16 +2,16 @@ use crate::astconv::{AstConv, OnlySelfBounds, PredicateFilter};
2
2
use crate :: bounds:: Bounds ;
3
3
use crate :: collect:: ItemCtxt ;
4
4
use crate :: constrained_generic_params as cgp;
5
- use hir:: { HirId , Lifetime , Node } ;
5
+ use hir:: { HirId , Node } ;
6
6
use rustc_data_structures:: fx:: FxIndexSet ;
7
7
use rustc_hir as hir;
8
8
use rustc_hir:: def:: DefKind ;
9
9
use rustc_hir:: def_id:: { DefId , LocalDefId } ;
10
10
use rustc_hir:: intravisit:: { self , Visitor } ;
11
11
use rustc_middle:: ty:: { self , Ty , TyCtxt } ;
12
- use rustc_middle:: ty:: { GenericPredicates , Generics , ImplTraitInTraitData , ToPredicate } ;
12
+ use rustc_middle:: ty:: { GenericPredicates , ImplTraitInTraitData , ToPredicate } ;
13
13
use rustc_span:: symbol:: Ident ;
14
- use rustc_span:: { Span , Symbol , DUMMY_SP } ;
14
+ use rustc_span:: { Span , DUMMY_SP } ;
15
15
16
16
/// Returns a list of all type predicates (explicit and implicit) for the definition with
17
17
/// ID `def_id`. This includes all predicates returned by `predicates_defined_on`, plus
@@ -55,17 +55,7 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Gen
55
55
use rustc_hir:: * ;
56
56
57
57
match tcx. opt_rpitit_info ( def_id. to_def_id ( ) ) {
58
- Some ( ImplTraitInTraitData :: Trait { opaque_def_id, fn_def_id } ) => {
59
- let opaque_ty_id = tcx. hir ( ) . local_def_id_to_hir_id ( opaque_def_id. expect_local ( ) ) ;
60
- let opaque_ty_node = tcx. hir ( ) . get ( opaque_ty_id) ;
61
- let Node :: Item ( & Item {
62
- kind : ItemKind :: OpaqueTy ( OpaqueTy { lifetime_mapping, .. } ) ,
63
- ..
64
- } ) = opaque_ty_node
65
- else {
66
- bug ! ( "unexpected {opaque_ty_node:?}" )
67
- } ;
68
-
58
+ Some ( ImplTraitInTraitData :: Trait { fn_def_id, .. } ) => {
69
59
let mut predicates = Vec :: new ( ) ;
70
60
71
61
// RPITITs should inherit the predicates of their parent. This is
@@ -78,13 +68,12 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Gen
78
68
79
69
// We also install bidirectional outlives predicates for the RPITIT
80
70
// to keep the duplicates lifetimes from opaque lowering in sync.
71
+ // We only need to compute bidirectional outlives for the duplicated
72
+ // opaque lifetimes, which explains the slicing below.
81
73
compute_bidirectional_outlives_predicates (
82
74
tcx,
83
- def_id,
84
- lifetime_mapping. iter ( ) . map ( |( lifetime, def_id) | {
85
- ( * * lifetime, ( * def_id, lifetime. ident . name , lifetime. ident . span ) )
86
- } ) ,
87
- tcx. generics_of ( def_id. to_def_id ( ) ) ,
75
+ & tcx. generics_of ( def_id. to_def_id ( ) ) . params
76
+ [ tcx. generics_of ( fn_def_id) . params . len ( ) ..] ,
88
77
& mut predicates,
89
78
) ;
90
79
@@ -351,21 +340,7 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Gen
351
340
} ;
352
341
debug ! ( ?lifetimes) ;
353
342
354
- let lifetime_mapping = std:: iter:: zip ( lifetimes, ast_generics. params )
355
- . map ( |( arg, dup) | {
356
- let hir:: GenericArg :: Lifetime ( arg) = arg else { bug ! ( ) } ;
357
- ( * * arg, dup)
358
- } )
359
- . filter ( |( _, dup) | matches ! ( dup. kind, hir:: GenericParamKind :: Lifetime { .. } ) )
360
- . map ( |( lifetime, dup) | ( lifetime, ( dup. def_id , dup. name . ident ( ) . name , dup. span ) ) ) ;
361
-
362
- compute_bidirectional_outlives_predicates (
363
- tcx,
364
- def_id,
365
- lifetime_mapping,
366
- generics,
367
- & mut predicates,
368
- ) ;
343
+ compute_bidirectional_outlives_predicates ( tcx, & generics. params , & mut predicates) ;
369
344
debug ! ( ?predicates) ;
370
345
}
371
346
@@ -379,41 +354,28 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Gen
379
354
/// enforce that these lifetimes stay in sync.
380
355
fn compute_bidirectional_outlives_predicates < ' tcx > (
381
356
tcx : TyCtxt < ' tcx > ,
382
- item_def_id : LocalDefId ,
383
- lifetime_mapping : impl Iterator < Item = ( Lifetime , ( LocalDefId , Symbol , Span ) ) > ,
384
- generics : & Generics ,
357
+ opaque_own_params : & [ ty:: GenericParamDef ] ,
385
358
predicates : & mut Vec < ( ty:: Clause < ' tcx > , Span ) > ,
386
359
) {
387
- let icx = ItemCtxt :: new ( tcx, item_def_id) ;
388
-
389
- for ( arg, ( dup_def, name, span) ) in lifetime_mapping {
390
- let orig_region = icx. astconv ( ) . ast_region_to_region ( & arg, None ) ;
391
- if !matches ! ( orig_region. kind( ) , ty:: ReEarlyBound ( ..) ) {
392
- // There is no late-bound lifetime to actually match up here, since the lifetime doesn't
393
- // show up in the opaque's parent's args.
394
- continue ;
360
+ for param in opaque_own_params {
361
+ let orig_lifetime = tcx. map_rpit_lifetime_to_fn_lifetime ( param. def_id . expect_local ( ) ) ;
362
+ if let ty:: ReEarlyBound ( ..) = * orig_lifetime {
363
+ let dup_lifetime = ty:: Region :: new_early_bound (
364
+ tcx,
365
+ ty:: EarlyBoundRegion { def_id : param. def_id , index : param. index , name : param. name } ,
366
+ ) ;
367
+ let span = tcx. def_span ( param. def_id ) ;
368
+ predicates. push ( (
369
+ ty:: ClauseKind :: RegionOutlives ( ty:: OutlivesPredicate ( orig_lifetime, dup_lifetime) )
370
+ . to_predicate ( tcx) ,
371
+ span,
372
+ ) ) ;
373
+ predicates. push ( (
374
+ ty:: ClauseKind :: RegionOutlives ( ty:: OutlivesPredicate ( dup_lifetime, orig_lifetime) )
375
+ . to_predicate ( tcx) ,
376
+ span,
377
+ ) ) ;
395
378
}
396
-
397
- let Some ( dup_index) = generics. param_def_id_to_index ( icx. tcx , dup_def. to_def_id ( ) ) else {
398
- bug ! ( )
399
- } ;
400
-
401
- let dup_region = ty:: Region :: new_early_bound (
402
- tcx,
403
- ty:: EarlyBoundRegion { def_id : dup_def. to_def_id ( ) , index : dup_index, name } ,
404
- ) ;
405
-
406
- predicates. push ( (
407
- ty:: ClauseKind :: RegionOutlives ( ty:: OutlivesPredicate ( orig_region, dup_region) )
408
- . to_predicate ( tcx) ,
409
- span,
410
- ) ) ;
411
-
412
- predicates. push ( (
413
- ty:: ClauseKind :: RegionOutlives ( ty:: OutlivesPredicate ( dup_region, orig_region) )
414
- . to_predicate ( tcx) ,
415
- span,
416
- ) ) ;
417
379
}
418
380
}
419
381
0 commit comments