@@ -10,9 +10,8 @@ use rustc_infer::infer::DefineOpaqueTypes;
10
10
use rustc_middle:: mir:: interpret:: ErrorHandled ;
11
11
use rustc_middle:: ty:: { Region , RegionVid } ;
12
12
13
- use rustc_data_structures:: fx:: { FxHashMap , FxHashSet , FxIndexSet } ;
13
+ use rustc_data_structures:: fx:: { FxHashSet , FxIndexMap , FxIndexSet , IndexEntry } ;
14
14
15
- use std:: collections:: hash_map:: Entry ;
16
15
use std:: collections:: VecDeque ;
17
16
use std:: iter;
18
17
@@ -35,17 +34,10 @@ pub enum AutoTraitResult<A> {
35
34
NegativeImpl ,
36
35
}
37
36
38
- #[ allow( dead_code) ]
39
- impl < A > AutoTraitResult < A > {
40
- fn is_auto ( & self ) -> bool {
41
- matches ! ( self , AutoTraitResult :: PositiveImpl ( _) | AutoTraitResult :: NegativeImpl )
42
- }
43
- }
44
-
45
37
pub struct AutoTraitInfo < ' cx > {
46
38
pub full_user_env : ty:: ParamEnv < ' cx > ,
47
39
pub region_data : RegionConstraintData < ' cx > ,
48
- pub vid_to_region : FxHashMap < ty:: RegionVid , ty:: Region < ' cx > > ,
40
+ pub vid_to_region : FxIndexMap < ty:: RegionVid , ty:: Region < ' cx > > ,
49
41
}
50
42
51
43
pub struct AutoTraitFinder < ' tcx > {
@@ -114,7 +106,7 @@ impl<'tcx> AutoTraitFinder<'tcx> {
114
106
}
115
107
116
108
let infcx = tcx. infer_ctxt ( ) . build ( ) ;
117
- let mut fresh_preds = FxHashSet :: default ( ) ;
109
+ let mut fresh_preds = FxIndexSet :: default ( ) ;
118
110
119
111
// Due to the way projections are handled by SelectionContext, we need to run
120
112
// evaluate_predicates twice: once on the original param env, and once on the result of
@@ -239,7 +231,7 @@ impl<'tcx> AutoTraitFinder<'tcx> {
239
231
ty : Ty < ' tcx > ,
240
232
param_env : ty:: ParamEnv < ' tcx > ,
241
233
user_env : ty:: ParamEnv < ' tcx > ,
242
- fresh_preds : & mut FxHashSet < ty:: Predicate < ' tcx > > ,
234
+ fresh_preds : & mut FxIndexSet < ty:: Predicate < ' tcx > > ,
243
235
) -> Option < ( ty:: ParamEnv < ' tcx > , ty:: ParamEnv < ' tcx > ) > {
244
236
let tcx = infcx. tcx ;
245
237
@@ -252,7 +244,7 @@ impl<'tcx> AutoTraitFinder<'tcx> {
252
244
253
245
let mut select = SelectionContext :: new ( infcx) ;
254
246
255
- let mut already_visited = FxHashSet :: default ( ) ;
247
+ let mut already_visited = FxHashSet :: default ( ) ; // NOTE(fmease): not used for iteration
256
248
let mut predicates = VecDeque :: new ( ) ;
257
249
predicates. push_back ( ty:: Binder :: dummy ( ty:: TraitPredicate {
258
250
trait_ref : ty:: TraitRef :: new ( infcx. tcx , trait_did, [ ty] ) ,
@@ -473,9 +465,9 @@ impl<'tcx> AutoTraitFinder<'tcx> {
473
465
fn map_vid_to_region < ' cx > (
474
466
& self ,
475
467
regions : & RegionConstraintData < ' cx > ,
476
- ) -> FxHashMap < ty:: RegionVid , ty:: Region < ' cx > > {
477
- let mut vid_map: FxHashMap < RegionTarget < ' cx > , RegionDeps < ' cx > > = FxHashMap :: default ( ) ;
478
- let mut finished_map = FxHashMap :: default ( ) ;
468
+ ) -> FxIndexMap < ty:: RegionVid , ty:: Region < ' cx > > {
469
+ let mut vid_map = FxIndexMap :: < RegionTarget < ' cx > , RegionDeps < ' cx > > :: default ( ) ;
470
+ let mut finished_map = FxIndexMap :: default ( ) ;
479
471
480
472
for ( constraint, _) in & regions. constraints {
481
473
match constraint {
@@ -513,22 +505,22 @@ impl<'tcx> AutoTraitFinder<'tcx> {
513
505
}
514
506
515
507
while !vid_map. is_empty ( ) {
516
- #[ allow( rustc:: potential_query_instability) ]
517
508
let target = * vid_map. keys ( ) . next ( ) . expect ( "Keys somehow empty" ) ;
518
- let deps = vid_map. remove ( & target) . expect ( "Entry somehow missing" ) ;
509
+ // FIXME(#120456) - is `swap_remove` correct?
510
+ let deps = vid_map. swap_remove ( & target) . expect ( "Entry somehow missing" ) ;
519
511
520
512
for smaller in deps. smaller . iter ( ) {
521
513
for larger in deps. larger . iter ( ) {
522
514
match ( smaller, larger) {
523
515
( & RegionTarget :: Region ( _) , & RegionTarget :: Region ( _) ) => {
524
- if let Entry :: Occupied ( v) = vid_map. entry ( * smaller) {
516
+ if let IndexEntry :: Occupied ( v) = vid_map. entry ( * smaller) {
525
517
let smaller_deps = v. into_mut ( ) ;
526
518
smaller_deps. larger . insert ( * larger) ;
527
519
// FIXME(#120456) - is `swap_remove` correct?
528
520
smaller_deps. larger . swap_remove ( & target) ;
529
521
}
530
522
531
- if let Entry :: Occupied ( v) = vid_map. entry ( * larger) {
523
+ if let IndexEntry :: Occupied ( v) = vid_map. entry ( * larger) {
532
524
let larger_deps = v. into_mut ( ) ;
533
525
larger_deps. smaller . insert ( * smaller) ;
534
526
// FIXME(#120456) - is `swap_remove` correct?
@@ -542,14 +534,14 @@ impl<'tcx> AutoTraitFinder<'tcx> {
542
534
// Do nothing; we don't care about regions that are smaller than vids.
543
535
}
544
536
( & RegionTarget :: RegionVid ( _) , & RegionTarget :: RegionVid ( _) ) => {
545
- if let Entry :: Occupied ( v) = vid_map. entry ( * smaller) {
537
+ if let IndexEntry :: Occupied ( v) = vid_map. entry ( * smaller) {
546
538
let smaller_deps = v. into_mut ( ) ;
547
539
smaller_deps. larger . insert ( * larger) ;
548
540
// FIXME(#120456) - is `swap_remove` correct?
549
541
smaller_deps. larger . swap_remove ( & target) ;
550
542
}
551
543
552
- if let Entry :: Occupied ( v) = vid_map. entry ( * larger) {
544
+ if let IndexEntry :: Occupied ( v) = vid_map. entry ( * larger) {
553
545
let larger_deps = v. into_mut ( ) ;
554
546
larger_deps. smaller . insert ( * smaller) ;
555
547
// FIXME(#120456) - is `swap_remove` correct?
@@ -560,6 +552,7 @@ impl<'tcx> AutoTraitFinder<'tcx> {
560
552
}
561
553
}
562
554
}
555
+
563
556
finished_map
564
557
}
565
558
@@ -588,7 +581,7 @@ impl<'tcx> AutoTraitFinder<'tcx> {
588
581
ty : Ty < ' _ > ,
589
582
nested : impl Iterator < Item = PredicateObligation < ' tcx > > ,
590
583
computed_preds : & mut FxIndexSet < ty:: Predicate < ' tcx > > ,
591
- fresh_preds : & mut FxHashSet < ty:: Predicate < ' tcx > > ,
584
+ fresh_preds : & mut FxIndexSet < ty:: Predicate < ' tcx > > ,
592
585
predicates : & mut VecDeque < ty:: PolyTraitPredicate < ' tcx > > ,
593
586
selcx : & mut SelectionContext < ' _ , ' tcx > ,
594
587
) -> bool {
0 commit comments