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