@@ -6,13 +6,13 @@ use super::*;
66use crate :: errors:: UnableToConstructConstantValue ;
77use crate :: infer:: region_constraints:: { Constraint , RegionConstraintData } ;
88use crate :: traits:: project:: ProjectAndUnifyResult ;
9+
10+ use rustc_data_structures:: fx:: { FxIndexMap , FxIndexSet , IndexEntry } ;
11+ use rustc_data_structures:: unord:: UnordSet ;
912use rustc_infer:: infer:: DefineOpaqueTypes ;
1013use rustc_middle:: mir:: interpret:: ErrorHandled ;
1114use rustc_middle:: ty:: { Region , RegionVid } ;
1215
13- use rustc_data_structures:: fx:: { FxHashMap , FxHashSet , FxIndexSet } ;
14-
15- use std:: collections:: hash_map:: Entry ;
1616use std:: collections:: VecDeque ;
1717use std:: iter;
1818
@@ -35,17 +35,10 @@ pub enum AutoTraitResult<A> {
3535 NegativeImpl ,
3636}
3737
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-
4538pub struct AutoTraitInfo < ' cx > {
4639 pub full_user_env : ty:: ParamEnv < ' cx > ,
4740 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 > > ,
4942}
5043
5144pub struct AutoTraitFinder < ' tcx > {
@@ -114,7 +107,7 @@ impl<'tcx> AutoTraitFinder<'tcx> {
114107 }
115108
116109 let infcx = tcx. infer_ctxt ( ) . build ( ) ;
117- let mut fresh_preds = FxHashSet :: default ( ) ;
110+ let mut fresh_preds = FxIndexSet :: default ( ) ;
118111
119112 // Due to the way projections are handled by SelectionContext, we need to run
120113 // evaluate_predicates twice: once on the original param env, and once on the result of
@@ -239,7 +232,7 @@ impl<'tcx> AutoTraitFinder<'tcx> {
239232 ty : Ty < ' tcx > ,
240233 param_env : ty:: ParamEnv < ' tcx > ,
241234 user_env : ty:: ParamEnv < ' tcx > ,
242- fresh_preds : & mut FxHashSet < ty:: Predicate < ' tcx > > ,
235+ fresh_preds : & mut FxIndexSet < ty:: Predicate < ' tcx > > ,
243236 ) -> Option < ( ty:: ParamEnv < ' tcx > , ty:: ParamEnv < ' tcx > ) > {
244237 let tcx = infcx. tcx ;
245238
@@ -252,7 +245,7 @@ impl<'tcx> AutoTraitFinder<'tcx> {
252245
253246 let mut select = SelectionContext :: new ( infcx) ;
254247
255- let mut already_visited = FxHashSet :: default ( ) ;
248+ let mut already_visited = UnordSet :: new ( ) ;
256249 let mut predicates = VecDeque :: new ( ) ;
257250 predicates. push_back ( ty:: Binder :: dummy ( ty:: TraitPredicate {
258251 trait_ref : ty:: TraitRef :: new ( infcx. tcx , trait_did, [ ty] ) ,
@@ -473,9 +466,9 @@ impl<'tcx> AutoTraitFinder<'tcx> {
473466 fn map_vid_to_region < ' cx > (
474467 & self ,
475468 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 ( ) ;
479472
480473 for ( constraint, _) in & regions. constraints {
481474 match constraint {
@@ -513,25 +506,22 @@ impl<'tcx> AutoTraitFinder<'tcx> {
513506 }
514507
515508 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 ( ) ;
519511
520512 for smaller in deps. smaller . iter ( ) {
521513 for larger in deps. larger . iter ( ) {
522514 match ( smaller, larger) {
523515 ( & RegionTarget :: Region ( _) , & RegionTarget :: Region ( _) ) => {
524- if let Entry :: Occupied ( v) = vid_map. entry ( * smaller) {
516+ if let IndexEntry :: Occupied ( v) = vid_map. entry ( * smaller) {
525517 let smaller_deps = v. into_mut ( ) ;
526518 smaller_deps. larger . insert ( * larger) ;
527- // FIXME(#120456) - is `swap_remove` correct?
528519 smaller_deps. larger . swap_remove ( & target) ;
529520 }
530521
531- if let Entry :: Occupied ( v) = vid_map. entry ( * larger) {
522+ if let IndexEntry :: Occupied ( v) = vid_map. entry ( * larger) {
532523 let larger_deps = v. into_mut ( ) ;
533524 larger_deps. smaller . insert ( * smaller) ;
534- // FIXME(#120456) - is `swap_remove` correct?
535525 larger_deps. smaller . swap_remove ( & target) ;
536526 }
537527 }
@@ -542,24 +532,23 @@ impl<'tcx> AutoTraitFinder<'tcx> {
542532 // Do nothing; we don't care about regions that are smaller than vids.
543533 }
544534 ( & RegionTarget :: RegionVid ( _) , & RegionTarget :: RegionVid ( _) ) => {
545- if let Entry :: Occupied ( v) = vid_map. entry ( * smaller) {
535+ if let IndexEntry :: Occupied ( v) = vid_map. entry ( * smaller) {
546536 let smaller_deps = v. into_mut ( ) ;
547537 smaller_deps. larger . insert ( * larger) ;
548- // FIXME(#120456) - is `swap_remove` correct?
549538 smaller_deps. larger . swap_remove ( & target) ;
550539 }
551540
552- if let Entry :: Occupied ( v) = vid_map. entry ( * larger) {
541+ if let IndexEntry :: Occupied ( v) = vid_map. entry ( * larger) {
553542 let larger_deps = v. into_mut ( ) ;
554543 larger_deps. smaller . insert ( * smaller) ;
555- // FIXME(#120456) - is `swap_remove` correct?
556544 larger_deps. smaller . swap_remove ( & target) ;
557545 }
558546 }
559547 }
560548 }
561549 }
562550 }
551+
563552 finished_map
564553 }
565554
@@ -588,7 +577,7 @@ impl<'tcx> AutoTraitFinder<'tcx> {
588577 ty : Ty < ' _ > ,
589578 nested : impl Iterator < Item = PredicateObligation < ' tcx > > ,
590579 computed_preds : & mut FxIndexSet < ty:: Predicate < ' tcx > > ,
591- fresh_preds : & mut FxHashSet < ty:: Predicate < ' tcx > > ,
580+ fresh_preds : & mut FxIndexSet < ty:: Predicate < ' tcx > > ,
592581 predicates : & mut VecDeque < ty:: PolyTraitPredicate < ' tcx > > ,
593582 selcx : & mut SelectionContext < ' _ , ' tcx > ,
594583 ) -> bool {
0 commit comments