Skip to content

Commit c741bc8

Browse files
committed
Fix error message label
1 parent 5312f0c commit c741bc8

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

src/librustc_typeck/check/coercion.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -1104,7 +1104,7 @@ impl<'gcx, 'tcx, 'exprs, E> CoerceMany<'gcx, 'tcx, 'exprs, E>
11041104
// Another example is `break` with no argument expression.
11051105
assert!(expression_ty.is_nil());
11061106
assert!(expression_ty.is_nil(), "if let hack without unit type");
1107-
fcx.eq_types(true, cause, expression_ty, self.merged_ty())
1107+
fcx.eq_types(label_expression_as_expected, cause, expression_ty, self.merged_ty())
11081108
.map(|infer_ok| {
11091109
fcx.register_infer_ok_obligations(infer_ok);
11101110
expression_ty
@@ -1128,6 +1128,10 @@ impl<'gcx, 'tcx, 'exprs, E> CoerceMany<'gcx, 'tcx, 'exprs, E>
11281128
}
11291129
Err(err) => {
11301130
let (expected, found) = if label_expression_as_expected {
1131+
// In the case where this is a "forced unit", like
1132+
// `break`, we want to call the `()` "expected"
1133+
// since it is implied by the syntax.
1134+
// (Note: not all force-units work this way.)"
11311135
(expression_ty, self.final_ty.unwrap_or(self.expected_ty))
11321136
} else {
11331137
// Otherwise, the "expected" type for error

src/test/ui/coercion-missing-tail-expected-type.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ error[E0308]: mismatched types
55
| ____________________________^
66
14 | | x + 1;
77
15 | | }
8-
| |_^ expected (), found i32
8+
| |_^ expected i32, found ()
99
|
1010
= note: expected type `i32`
1111
found type `()`

0 commit comments

Comments
 (0)