@@ -140,28 +140,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
140
140
Some ( arm. body ) ,
141
141
arm_ty,
142
142
|err| {
143
- if let hir:: ExprKind :: Block ( block, _) = arm. body . kind
144
- && let Some ( expr) = block. expr
145
- && let arm_tail_ty = self . node_ty ( expr. hir_id )
146
- && arm_tail_ty. is_never ( )
147
- && !arm_ty. is_never ( )
148
- {
149
- err. span_label (
150
- expr. span ,
151
- format ! (
152
- "this expression is of type `!`, but it is coerced to \
153
- `{arm_ty}` due to its surrounding expression",
154
- ) ,
155
- ) ;
156
- self . suggest_mismatched_types_on_tail (
157
- err,
158
- expr,
159
- arm_ty,
160
- prior_arm. map_or ( arm_tail_ty, |( _, ty, _) | ty) ,
161
- expr. hir_id ,
162
- ) ;
163
- }
164
- self . suggest_removing_semicolon_for_coerce ( err, expr, arm_ty, prior_arm)
143
+ self . explain_never_type_coerced_to_unit ( err, arm, arm_ty, prior_arm, expr) ;
165
144
} ,
166
145
false ,
167
146
) ;
@@ -200,6 +179,38 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
200
179
coercion. complete ( self )
201
180
}
202
181
182
+ fn explain_never_type_coerced_to_unit (
183
+ & self ,
184
+ err : & mut Diagnostic ,
185
+ arm : & hir:: Arm < ' tcx > ,
186
+ arm_ty : Ty < ' tcx > ,
187
+ prior_arm : Option < ( Option < hir:: HirId > , Ty < ' tcx > , Span ) > ,
188
+ expr : & hir:: Expr < ' tcx > ,
189
+ ) {
190
+ if let hir:: ExprKind :: Block ( block, _) = arm. body . kind
191
+ && let Some ( expr) = block. expr
192
+ && let arm_tail_ty = self . node_ty ( expr. hir_id )
193
+ && arm_tail_ty. is_never ( )
194
+ && !arm_ty. is_never ( )
195
+ {
196
+ err. span_label (
197
+ expr. span ,
198
+ format ! (
199
+ "this expression is of type `!`, but it is coerced to `{arm_ty}` due to its \
200
+ surrounding expression",
201
+ ) ,
202
+ ) ;
203
+ self . suggest_mismatched_types_on_tail (
204
+ err,
205
+ expr,
206
+ arm_ty,
207
+ prior_arm. map_or ( arm_tail_ty, |( _, ty, _) | ty) ,
208
+ expr. hir_id ,
209
+ ) ;
210
+ }
211
+ self . suggest_removing_semicolon_for_coerce ( err, expr, arm_ty, prior_arm)
212
+ }
213
+
203
214
fn suggest_removing_semicolon_for_coerce (
204
215
& self ,
205
216
diag : & mut Diagnostic ,
0 commit comments