Skip to content

Commit 9b8243a

Browse files
committed
Point at more cases involving return types
1 parent c431850 commit 9b8243a

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

src/librustc_typeck/check/mod.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4347,11 +4347,15 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
43474347
struct_span_err!(self.tcx.sess, expr.span, E0572,
43484348
"return statement outside of function body").emit();
43494349
} else if let Some(ref e) = *expr_opt {
4350-
*self.ret_coercion_span.borrow_mut() = Some(e.span);
4350+
if self.ret_coercion_span.borrow().is_none() {
4351+
*self.ret_coercion_span.borrow_mut() = Some(e.span);
4352+
}
43514353
self.check_return_expr(e);
43524354
} else {
43534355
let mut coercion = self.ret_coercion.as_ref().unwrap().borrow_mut();
4354-
*self.ret_coercion_span.borrow_mut() = Some(expr.span);
4356+
if self.ret_coercion_span.borrow().is_none() {
4357+
*self.ret_coercion_span.borrow_mut() = Some(expr.span);
4358+
}
43554359
let cause = self.cause(expr.span, ObligationCauseCode::ReturnNoExpression);
43564360
if let Some((fn_decl, _)) = self.get_fn_decl(expr.id) {
43574361
coercion.coerce_forced_unit(

src/test/ui/point-to-type-err-cause-on-impl-trait-return.stderr

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ LL | 1u32
1313
error[E0308]: mismatched types
1414
--> $DIR/point-to-type-err-cause-on-impl-trait-return.rs:13:16
1515
|
16+
LL | return 0i32;
17+
| ---- expected because of this statement
18+
LL | } else {
1619
LL | return 1u32;
1720
| ^^^^ expected i32, found u32
1821
|

0 commit comments

Comments
 (0)