@@ -3213,9 +3213,10 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
3213
3213
PatKind :: Or ( ref ps) => {
3214
3214
// Check the consistency of this or-pattern and
3215
3215
// then add all bindings to the larger map.
3216
- let ( bm, np) = self . compute_and_check_or_pat_binding_map ( ps) ;
3217
- binding_map. extend ( bm) ;
3218
- is_never_pat |= np;
3216
+ match self . compute_and_check_or_pat_binding_map ( ps) {
3217
+ Ok ( bm) => binding_map. extend ( bm) ,
3218
+ Err ( IsNeverPattern ) => is_never_pat = true ,
3219
+ }
3219
3220
return false ;
3220
3221
}
3221
3222
PatKind :: Never => is_never_pat = true ,
@@ -3249,7 +3250,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
3249
3250
fn compute_and_check_or_pat_binding_map (
3250
3251
& mut self ,
3251
3252
pats : & [ P < Pat > ] ,
3252
- ) -> ( FxIndexMap < Ident , BindingInfo > , bool ) {
3253
+ ) -> Result < FxIndexMap < Ident , BindingInfo > , IsNeverPattern > {
3253
3254
let mut missing_vars = FxIndexMap :: default ( ) ;
3254
3255
let mut inconsistent_vars = FxIndexMap :: default ( ) ;
3255
3256
@@ -3314,12 +3315,16 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
3314
3315
}
3315
3316
3316
3317
// 5) Bubble up the final binding map.
3317
- let is_never_pat = not_never_pats. is_empty ( ) ;
3318
- let mut binding_map = FxIndexMap :: default ( ) ;
3319
- for ( bm, _) in not_never_pats {
3320
- binding_map. extend ( bm) ;
3318
+ if not_never_pats. is_empty ( ) {
3319
+ // All the patterns are never patterns, so the whole or-pattern is one too.
3320
+ Err ( IsNeverPattern )
3321
+ } else {
3322
+ let mut binding_map = FxIndexMap :: default ( ) ;
3323
+ for ( bm, _) in not_never_pats {
3324
+ binding_map. extend ( bm) ;
3325
+ }
3326
+ Ok ( binding_map)
3321
3327
}
3322
- ( binding_map, is_never_pat)
3323
3328
}
3324
3329
3325
3330
/// Check the consistency of bindings wrt or-patterns and never patterns.
0 commit comments