44//! types computed here.
55
66use super :: FnCtxt ;
7- use rustc_data_structures:: fx:: { FxHashMap , FxHashSet } ;
7+ use rustc_data_structures:: fx:: { FxHashSet , FxIndexSet } ;
88use rustc_hir as hir;
99use rustc_hir:: def:: { CtorKind , DefKind , Res } ;
1010use rustc_hir:: def_id:: DefId ;
@@ -16,7 +16,7 @@ use rustc_span::Span;
1616
1717struct InteriorVisitor < ' a , ' tcx > {
1818 fcx : & ' a FnCtxt < ' a , ' tcx > ,
19- types : FxHashMap < ty:: GeneratorInteriorTypeCause < ' tcx > , usize > ,
19+ types : FxIndexSet < ty:: GeneratorInteriorTypeCause < ' tcx > > ,
2020 region_scope_tree : & ' tcx region:: ScopeTree ,
2121 expr_count : usize ,
2222 kind : hir:: GeneratorKind ,
@@ -88,18 +88,15 @@ impl<'a, 'tcx> InteriorVisitor<'a, 'tcx> {
8888 . span_note ( yield_data. span , & * note)
8989 . emit ( ) ;
9090 } else {
91- // Map the type to the number of types added before it
92- let entries = self . types . len ( ) ;
91+ // Insert the type into the ordered set.
9392 let scope_span = scope. map ( |s| s. span ( self . fcx . tcx , self . region_scope_tree ) ) ;
94- self . types
95- . entry ( ty:: GeneratorInteriorTypeCause {
96- span : source_span,
97- ty : & ty,
98- scope_span,
99- yield_span : yield_data. span ,
100- expr : expr. map ( |e| e. hir_id ) ,
101- } )
102- . or_insert ( entries) ;
93+ self . types . insert ( ty:: GeneratorInteriorTypeCause {
94+ span : source_span,
95+ ty : & ty,
96+ scope_span,
97+ yield_span : yield_data. span ,
98+ expr : expr. map ( |e| e. hir_id ) ,
99+ } ) ;
103100 }
104101 } else {
105102 debug ! (
@@ -132,7 +129,7 @@ pub fn resolve_interior<'a, 'tcx>(
132129 let body = fcx. tcx . hir ( ) . body ( body_id) ;
133130 let mut visitor = InteriorVisitor {
134131 fcx,
135- types : FxHashMap :: default ( ) ,
132+ types : FxIndexSet :: default ( ) ,
136133 region_scope_tree : fcx. tcx . region_scope_tree ( def_id) ,
137134 expr_count : 0 ,
138135 kind,
@@ -144,10 +141,8 @@ pub fn resolve_interior<'a, 'tcx>(
144141 let region_expr_count = visitor. region_scope_tree . body_expr_count ( body_id) . unwrap ( ) ;
145142 assert_eq ! ( region_expr_count, visitor. expr_count) ;
146143
147- let mut types: Vec < _ > = visitor. types . drain ( ) . collect ( ) ;
148-
149- // Sort types by insertion order
150- types. sort_by_key ( |t| t. 1 ) ;
144+ // The types are already kept in insertion order.
145+ let types = visitor. types ;
151146
152147 // The types in the generator interior contain lifetimes local to the generator itself,
153148 // which should not be exposed outside of the generator. Therefore, we replace these
@@ -164,7 +159,7 @@ pub fn resolve_interior<'a, 'tcx>(
164159 let mut captured_tys = FxHashSet :: default ( ) ;
165160 let type_causes: Vec < _ > = types
166161 . into_iter ( )
167- . filter_map ( |( mut cause, _ ) | {
162+ . filter_map ( |mut cause| {
168163 // Erase regions and canonicalize late-bound regions to deduplicate as many types as we
169164 // can.
170165 let erased = fcx. tcx . erase_regions ( & cause. ty ) ;
0 commit comments