@@ -1169,7 +1169,6 @@ impl<'gcx, 'tcx, 'exprs, E> CoerceMany<'gcx, 'tcx, 'exprs, E>
11691169 // `expression_ty` will be unit).
11701170 //
11711171 // Another example is `break` with no argument expression.
1172- assert ! ( expression_ty. is_unit( ) ) ;
11731172 assert ! ( expression_ty. is_unit( ) , "if let hack without unit type" ) ;
11741173 fcx. at ( cause, fcx. param_env )
11751174 . 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>
12101209 ( self . final_ty . unwrap_or ( self . expected_ty ) , expression_ty)
12111210 } ;
12121211
1212+ let reason_label = "expected because of this statement" ;
12131213 let mut db;
12141214 match cause. code {
12151215 ObligationCauseCode :: ReturnNoExpression => {
12161216 db = struct_span_err ! (
12171217 fcx. tcx. sess, cause. span, E0069 ,
12181218 "`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 `()` " ) ;
12201220 }
12211221 ObligationCauseCode :: BlockTailExpression ( blk_id) => {
12221222 db = fcx. report_mismatched_types ( cause, expected, found, err) ;
@@ -1234,9 +1234,19 @@ impl<'gcx, 'tcx, 'exprs, E> CoerceMany<'gcx, 'tcx, 'exprs, E>
12341234 cause. span ,
12351235 blk_id,
12361236 ) ;
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+ }
12371242 }
12381243 _ => {
12391244 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+ }
12401250 }
12411251 }
12421252
0 commit comments