Skip to content

Commit dfc4a3d

Browse files
committed
Handle yet another case of break type mismatch
1 parent 3cb68f8 commit dfc4a3d

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

compiler/rustc_hir_typeck/src/expr.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,10 @@ use rustc_infer::traits::query::NoSolution;
4343
use rustc_infer::traits::ObligationCause;
4444
use rustc_middle::middle::stability;
4545
use rustc_middle::ty::adjustment::{Adjust, Adjustment, AllowTwoPhase};
46-
use rustc_middle::ty::error::TypeError::FieldMisMatch;
46+
use rustc_middle::ty::error::{
47+
ExpectedFound,
48+
TypeError::{FieldMisMatch, Sorts},
49+
};
4750
use rustc_middle::ty::GenericArgsRef;
4851
use rustc_middle::ty::{self, AdtKind, Ty, TypeVisitableExt};
4952
use rustc_session::errors::ExprParenthesesNeeded;
@@ -658,6 +661,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
658661
self.suggest_mismatched_types_on_tail(
659662
&mut err, expr, ty, e_ty, target_id,
660663
);
664+
let error = Some(Sorts(ExpectedFound { expected: ty, found: e_ty }));
665+
self.annotate_loop_expected_due_to_inference(&mut err, expr, error);
661666
if let Some(val) = ty_kind_suggestion(ty) {
662667
let label = destination
663668
.label

tests/ui/loops/loop-break-value.stderr

+4-1
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,10 @@ error[E0308]: mismatched types
134134
--> $DIR/loop-break-value.rs:4:31
135135
|
136136
LL | let val: ! = loop { break break; };
137-
| ^^^^^ expected `!`, found `()`
137+
| --- ---- ^^^^^ expected `!`, found `()`
138+
| | |
139+
| | this loop is expected to be of type `!`
140+
| expected because of this assignment
138141
|
139142
= note: expected type `!`
140143
found unit type `()`

0 commit comments

Comments
 (0)