@@ -1169,7 +1169,6 @@ impl<'gcx, 'tcx, 'exprs, E> CoerceMany<'gcx, 'tcx, 'exprs, E>
1169
1169
// `expression_ty` will be unit).
1170
1170
//
1171
1171
// Another example is `break` with no argument expression.
1172
- assert ! ( expression_ty. is_unit( ) ) ;
1173
1172
assert ! ( expression_ty. is_unit( ) , "if let hack without unit type" ) ;
1174
1173
fcx. at ( cause, fcx. param_env )
1175
1174
. eq_exp ( label_expression_as_expected, expression_ty, self . merged_ty ( ) )
@@ -1210,13 +1209,14 @@ impl<'gcx, 'tcx, 'exprs, E> CoerceMany<'gcx, 'tcx, 'exprs, E>
1210
1209
( self . final_ty . unwrap_or ( self . expected_ty ) , expression_ty)
1211
1210
} ;
1212
1211
1212
+ let reason_label = "expected because of this statement" ;
1213
1213
let mut db;
1214
1214
match cause. code {
1215
1215
ObligationCauseCode :: ReturnNoExpression => {
1216
1216
db = struct_span_err ! (
1217
1217
fcx. tcx. sess, cause. span, E0069 ,
1218
1218
"`return;` in a function whose return type is not `()`" ) ;
1219
- db. span_label ( cause. span , "return type is not () " ) ;
1219
+ db. span_label ( cause. span , "return type is not `()` " ) ;
1220
1220
}
1221
1221
ObligationCauseCode :: BlockTailExpression ( blk_id) => {
1222
1222
db = fcx. report_mismatched_types ( cause, expected, found, err) ;
@@ -1234,9 +1234,19 @@ impl<'gcx, 'tcx, 'exprs, E> CoerceMany<'gcx, 'tcx, 'exprs, E>
1234
1234
cause. span ,
1235
1235
blk_id,
1236
1236
) ;
1237
+ if let Some ( sp) = fcx. ret_coercion_span . borrow ( ) . as_ref ( ) {
1238
+ if !sp. overlaps ( cause. span ) {
1239
+ db. span_label ( * sp, reason_label) ;
1240
+ }
1241
+ }
1237
1242
}
1238
1243
_ => {
1239
1244
db = fcx. report_mismatched_types ( cause, expected, found, err) ;
1245
+ if let Some ( sp) = fcx. ret_coercion_span . borrow ( ) . as_ref ( ) {
1246
+ if !sp. overlaps ( cause. span ) {
1247
+ db. span_label ( * sp, reason_label) ;
1248
+ }
1249
+ }
1240
1250
}
1241
1251
}
1242
1252
0 commit comments