Skip to content

Commit

Permalink
Handle yet another case of break type mismatch
Browse files Browse the repository at this point in the history
  • Loading branch information
estebank committed Sep 23, 2023
1 parent 739e321 commit dcd7e61
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
7 changes: 6 additions & 1 deletion compiler/rustc_hir_typeck/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ use rustc_infer::traits::query::NoSolution;
use rustc_infer::traits::ObligationCause;
use rustc_middle::middle::stability;
use rustc_middle::ty::adjustment::{Adjust, Adjustment, AllowTwoPhase};
use rustc_middle::ty::error::TypeError::FieldMisMatch;
use rustc_middle::ty::error::{
ExpectedFound,
TypeError::{FieldMisMatch, Sorts},
};
use rustc_middle::ty::GenericArgsRef;
use rustc_middle::ty::{self, AdtKind, Ty, TypeVisitableExt};
use rustc_session::errors::ExprParenthesesNeeded;
Expand Down Expand Up @@ -664,6 +667,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
self.suggest_mismatched_types_on_tail(
&mut err, expr, ty, e_ty, target_id,
);
let error = Some(Sorts(ExpectedFound { expected: ty, found: e_ty }));
self.annotate_loop_expected_due_to_inference(&mut err, expr, error);
if let Some(val) = ty_kind_suggestion(ty) {
let label = destination
.label
Expand Down
5 changes: 4 additions & 1 deletion tests/ui/loops/loop-break-value.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,10 @@ error[E0308]: mismatched types
--> $DIR/loop-break-value.rs:4:31
|
LL | let val: ! = loop { break break; };
| ^^^^^ expected `!`, found `()`
| --- ---- ^^^^^ expected `!`, found `()`
| | |
| | this loop is expected to be of type `!`
| expected because of this assignment
|
= note: expected type `!`
found unit type `()`
Expand Down

0 comments on commit dcd7e61

Please sign in to comment.