Apply suggestion of @flodiebold: Get rid of multiple unwraps

This commit is contained in:
Roland Ruckerbauer 2020-05-19 22:52:15 +02:00
parent da09f96746
commit 45021cae55

View file

@ -238,25 +238,23 @@ impl<'a> InferenceContext<'a> {
Ty::unit() Ty::unit()
}; };
let mut has_brkctx = false; let last_ty = if let Some(ctxt) = self.breakables.last() {
ctxt.break_ty.clone()
} else {
Ty::Unknown
};
if self.breakables.last().is_some() { let merged_type = self.coerce_merge_branch(&last_ty, &val_ty);
has_brkctx = true;
if let Some(ctxt) = self.breakables.last_mut() {
ctxt.break_ty = merged_type;
ctxt.may_break = true;
} else { } else {
self.push_diagnostic(InferenceDiagnostic::BreakOutsideOfLoop { self.push_diagnostic(InferenceDiagnostic::BreakOutsideOfLoop {
expr: tgt_expr, expr: tgt_expr,
}); });
} }
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;
ctxt.break_ty = merged_type;
}
Ty::simple(TypeCtor::Never) Ty::simple(TypeCtor::Never)
} }
Expr::Return { expr } => { Expr::Return { expr } => {