@@ -53,25 +53,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
53
53
// Otherwise, we have to union together the types that the arms produce and so forth.
54
54
let scrut_diverges = self . diverges . replace ( Diverges :: Maybe ) ;
55
55
56
- // rust-lang/rust#55810: Typecheck patterns first (via eager
57
- // collection into `Vec`), so we get types for all bindings.
58
- let all_arm_pats_diverge: Vec < _ > = arms
59
- . iter ( )
60
- . map ( |arm| {
61
- let mut all_pats_diverge = Diverges :: WarnedAlways ;
62
- self . diverges . set ( Diverges :: Maybe ) ;
63
- self . check_pat_top ( & arm. pat , scrut_ty, Some ( scrut. span ) , true ) ;
64
- all_pats_diverge &= self . diverges . get ( ) ;
65
-
66
- // As discussed with @eddyb, this is for disabling unreachable_code
67
- // warnings on patterns (they're now subsumed by unreachable_patterns
68
- // warnings).
69
- match all_pats_diverge {
70
- Diverges :: Maybe => Diverges :: Maybe ,
71
- Diverges :: Always { .. } | Diverges :: WarnedAlways => Diverges :: WarnedAlways ,
72
- }
73
- } )
74
- . collect ( ) ;
56
+ // #55810: Type check patterns first so we get types for all bindings.
57
+ for arm in arms {
58
+ self . check_pat_top ( & arm. pat , scrut_ty, Some ( scrut. span ) , true ) ;
59
+ }
75
60
76
61
// Now typecheck the blocks.
77
62
//
@@ -102,19 +87,19 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
102
87
CoerceMany :: with_coercion_sites ( coerce_first, arms)
103
88
} ;
104
89
105
- let mut other_arms = vec ! [ ] ; // used only for diagnostics
90
+ let mut other_arms = vec ! [ ] ; // Used only for diagnostics.
106
91
let mut prior_arm_ty = None ;
107
- for ( i, ( arm, pats_diverge ) ) in arms. iter ( ) . zip ( all_arm_pats_diverge ) . enumerate ( ) {
92
+ for ( i, arm) in arms. iter ( ) . enumerate ( ) {
108
93
if let Some ( g) = & arm. guard {
109
- self . diverges . set ( pats_diverge ) ;
94
+ self . diverges . set ( Diverges :: Maybe ) ;
110
95
match g {
111
96
hir:: Guard :: If ( e) => {
112
97
self . check_expr_has_type_or_error ( e, tcx. types . bool , |_| { } )
113
98
}
114
99
} ;
115
100
}
116
101
117
- self . diverges . set ( pats_diverge ) ;
102
+ self . diverges . set ( Diverges :: Maybe ) ;
118
103
let arm_ty = if source_if
119
104
&& if_no_else
120
105
&& i != 0
0 commit comments