4
4
//! types computed here.
5
5
6
6
use super :: FnCtxt ;
7
- use rustc_data_structures:: fx:: { FxHashMap , FxHashSet } ;
7
+ use rustc_data_structures:: fx:: { FxHashSet , FxIndexSet } ;
8
8
use rustc_hir as hir;
9
9
use rustc_hir:: def:: { CtorKind , DefKind , Res } ;
10
10
use rustc_hir:: def_id:: DefId ;
@@ -16,7 +16,7 @@ use rustc_span::Span;
16
16
17
17
struct InteriorVisitor < ' a , ' tcx > {
18
18
fcx : & ' a FnCtxt < ' a , ' tcx > ,
19
- types : FxHashMap < ty:: GeneratorInteriorTypeCause < ' tcx > , usize > ,
19
+ types : FxIndexSet < ty:: GeneratorInteriorTypeCause < ' tcx > > ,
20
20
region_scope_tree : & ' tcx region:: ScopeTree ,
21
21
expr_count : usize ,
22
22
kind : hir:: GeneratorKind ,
@@ -88,18 +88,15 @@ impl<'a, 'tcx> InteriorVisitor<'a, 'tcx> {
88
88
. span_note ( yield_data. span , & * note)
89
89
. emit ( ) ;
90
90
} 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.
93
92
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
+ } ) ;
103
100
}
104
101
} else {
105
102
debug ! (
@@ -132,7 +129,7 @@ pub fn resolve_interior<'a, 'tcx>(
132
129
let body = fcx. tcx . hir ( ) . body ( body_id) ;
133
130
let mut visitor = InteriorVisitor {
134
131
fcx,
135
- types : FxHashMap :: default ( ) ,
132
+ types : FxIndexSet :: default ( ) ,
136
133
region_scope_tree : fcx. tcx . region_scope_tree ( def_id) ,
137
134
expr_count : 0 ,
138
135
kind,
@@ -144,10 +141,8 @@ pub fn resolve_interior<'a, 'tcx>(
144
141
let region_expr_count = visitor. region_scope_tree . body_expr_count ( body_id) . unwrap ( ) ;
145
142
assert_eq ! ( region_expr_count, visitor. expr_count) ;
146
143
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 ;
151
146
152
147
// The types in the generator interior contain lifetimes local to the generator itself,
153
148
// which should not be exposed outside of the generator. Therefore, we replace these
@@ -164,7 +159,7 @@ pub fn resolve_interior<'a, 'tcx>(
164
159
let mut captured_tys = FxHashSet :: default ( ) ;
165
160
let type_causes: Vec < _ > = types
166
161
. into_iter ( )
167
- . filter_map ( |( mut cause, _ ) | {
162
+ . filter_map ( |mut cause| {
168
163
// Erase regions and canonicalize late-bound regions to deduplicate as many types as we
169
164
// can.
170
165
let erased = fcx. tcx . erase_regions ( & cause. ty ) ;
0 commit comments