Apply suggestion of Get rid of multiple unwraps
@@ -238,23 +238,21 @@ impl<'a> InferenceContext<'a> {
Ty::unit()
};
- let mut has_brkctx = false;
-
- if self.breakables.last().is_some() {
- has_brkctx = true;
+ let last_ty = if let Some(ctxt) = self.breakables.last() {
+ ctxt.break_ty.clone()
} else {
- self.push_diagnostic(InferenceDiagnostic::BreakOutsideOfLoop {
- expr: tgt_expr,
- });
- }
+ Ty::Unknown
+ };
- if has_brkctx {
- let last_ty = self.breakables.last().expect("This is a bug").break_ty.clone();
let merged_type = self.coerce_merge_branch(&last_ty, &val_ty);
- let ctxt = self.breakables.last_mut().expect("This is a bug");
- ctxt.may_break = true;
+ if let Some(ctxt) = self.breakables.last_mut() {
ctxt.break_ty = merged_type;
+ ctxt.may_break = true;
+ } else {
+ self.push_diagnostic(InferenceDiagnostic::BreakOutsideOfLoop {
+ expr: tgt_expr,
+ });
}
Ty::simple(TypeCtor::Never)
