@@ -41,9 +41,6 @@ type Res = def::Res<NodeId>;
41
41
42
42
type IdentMap < T > = FxHashMap < Ident , T > ;
43
43
44
- /// Map from the name in a pattern to its binding mode.
45
- type BindingMap = IdentMap < BindingInfo > ;
46
-
47
44
use diagnostics:: {
48
45
ElisionFnParameter , LifetimeElisionCandidate , MissingLifetime , MissingLifetimeKind ,
49
46
} ;
@@ -3164,8 +3161,8 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
3164
3161
/// this is done hygienically. This could arise for a macro
3165
3162
/// that expands into an or-pattern where one 'x' was from the
3166
3163
/// user and one 'x' came from the macro.
3167
- fn binding_mode_map ( & mut self , pat : & Pat ) -> BindingMap {
3168
- let mut binding_map = FxHashMap :: default ( ) ;
3164
+ fn binding_mode_map ( & mut self , pat : & Pat ) -> FxIndexMap < Ident , BindingInfo > {
3165
+ let mut binding_map = FxIndexMap :: default ( ) ;
3169
3166
3170
3167
pat. walk ( & mut |pat| {
3171
3168
match pat. kind {
@@ -3200,22 +3197,28 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
3200
3197
3201
3198
/// Checks that all of the arms in an or-pattern have exactly the
3202
3199
/// same set of bindings, with the same binding modes for each.
3203
- fn check_consistent_bindings ( & mut self , pats : & [ P < Pat > ] ) -> Vec < BindingMap > {
3204
- let mut missing_vars = FxHashMap :: default ( ) ;
3205
- let mut inconsistent_vars = FxHashMap :: default ( ) ;
3200
+ fn check_consistent_bindings (
3201
+ & mut self ,
3202
+ pats : & [ P < Pat > ] ,
3203
+ ) -> Vec < FxIndexMap < Ident , BindingInfo > > {
3204
+ // pats is consistent.
3205
+ let mut missing_vars = FxIndexMap :: default ( ) ;
3206
+ let mut inconsistent_vars = FxIndexMap :: default ( ) ;
3206
3207
3207
3208
// 1) Compute the binding maps of all arms.
3208
3209
let maps = pats. iter ( ) . map ( |pat| self . binding_mode_map ( pat) ) . collect :: < Vec < _ > > ( ) ;
3209
3210
3210
3211
// 2) Record any missing bindings or binding mode inconsistencies.
3211
- for ( map_outer, pat_outer) in pats . iter ( ) . enumerate ( ) . map ( | ( idx , pat ) | ( & maps [ idx ] , pat ) ) {
3212
+ for ( map_outer, pat_outer) in maps . iter ( ) . zip ( pats . iter ( ) ) {
3212
3213
// Check against all arms except for the same pattern which is always self-consistent.
3213
- let inners = pats
3214
+ let inners = maps
3214
3215
. iter ( )
3215
- . enumerate ( )
3216
+ . zip ( pats . iter ( ) )
3216
3217
. filter ( |( _, pat) | pat. id != pat_outer. id )
3217
- . flat_map ( |( idx, _) | maps[ idx] . iter ( ) )
3218
- . map ( |( key, binding) | ( key. name , map_outer. get ( & key) , binding) ) ;
3218
+ . flat_map ( |( map, _) | map)
3219
+ . map ( |( key, binding) | ( key. name , map_outer. get ( key) , binding) ) ;
3220
+
3221
+ let inners = inners. collect :: < Vec < _ > > ( ) ;
3219
3222
3220
3223
for ( name, info, & binding_inner) in inners {
3221
3224
match info {
@@ -3244,10 +3247,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
3244
3247
}
3245
3248
3246
3249
// 3) Report all missing variables we found.
3247
- let mut missing_vars = missing_vars. into_iter ( ) . collect :: < Vec < _ > > ( ) ;
3248
- missing_vars. sort_by_key ( |& ( sym, ref _err) | sym) ;
3249
-
3250
- for ( name, mut v) in missing_vars. into_iter ( ) {
3250
+ for ( name, mut v) in missing_vars {
3251
3251
if inconsistent_vars. contains_key ( & name) {
3252
3252
v. could_be_path = false ;
3253
3253
}
@@ -3258,10 +3258,8 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
3258
3258
}
3259
3259
3260
3260
// 4) Report all inconsistencies in binding modes we found.
3261
- let mut inconsistent_vars = inconsistent_vars. iter ( ) . collect :: < Vec < _ > > ( ) ;
3262
- inconsistent_vars. sort ( ) ;
3263
3261
for ( name, v) in inconsistent_vars {
3264
- self . report_error ( v. 0 , ResolutionError :: VariableBoundWithDifferentMode ( * name, v. 1 ) ) ;
3262
+ self . report_error ( v. 0 , ResolutionError :: VariableBoundWithDifferentMode ( name, v. 1 ) ) ;
3265
3263
}
3266
3264
3267
3265
// 5) Finally bubble up all the binding maps.
0 commit comments