diff options
author | Roland Ruckerbauer <[email protected]> | 2020-05-19 21:52:15 +0100 |
---|---|---|
committer | Roland Ruckerbauer <[email protected]> | 2020-05-19 21:53:19 +0100 |
commit | 45021cae551826727c32c7499c68ca48d046890f (patch) | |
tree | d8d974f6939ab55ebf362088ff130c3c4216936f | |
parent | da09f967469127576d9a87a7c143f754777a4f6b (diff) |
Apply suggestion of @flodiebold: Get rid of multiple unwraps
-rw-r--r-- | crates/ra_hir_ty/src/infer/expr.rs | 22 |
1 files changed, 10 insertions, 12 deletions
diff --git a/crates/ra_hir_ty/src/infer/expr.rs b/crates/ra_hir_ty/src/infer/expr.rs index 83702ada0..b28724f0e 100644 --- a/crates/ra_hir_ty/src/infer/expr.rs +++ b/crates/ra_hir_ty/src/infer/expr.rs | |||
@@ -238,25 +238,23 @@ impl<'a> InferenceContext<'a> { | |||
238 | Ty::unit() | 238 | Ty::unit() |
239 | }; | 239 | }; |
240 | 240 | ||
241 | let mut has_brkctx = false; | 241 | let last_ty = if let Some(ctxt) = self.breakables.last() { |
242 | ctxt.break_ty.clone() | ||
243 | } else { | ||
244 | Ty::Unknown | ||
245 | }; | ||
242 | 246 | ||
243 | if self.breakables.last().is_some() { | 247 | let merged_type = self.coerce_merge_branch(&last_ty, &val_ty); |
244 | has_brkctx = true; | 248 | |
249 | if let Some(ctxt) = self.breakables.last_mut() { | ||
250 | ctxt.break_ty = merged_type; | ||
251 | ctxt.may_break = true; | ||
245 | } else { | 252 | } else { |
246 | self.push_diagnostic(InferenceDiagnostic::BreakOutsideOfLoop { | 253 | self.push_diagnostic(InferenceDiagnostic::BreakOutsideOfLoop { |
247 | expr: tgt_expr, | 254 | expr: tgt_expr, |
248 | }); | 255 | }); |
249 | } | 256 | } |
250 | 257 | ||
251 | if has_brkctx { | ||
252 | let last_ty = self.breakables.last().expect("This is a bug").break_ty.clone(); | ||
253 | let merged_type = self.coerce_merge_branch(&last_ty, &val_ty); | ||
254 | |||
255 | let ctxt = self.breakables.last_mut().expect("This is a bug"); | ||
256 | ctxt.may_break = true; | ||
257 | ctxt.break_ty = merged_type; | ||
258 | } | ||
259 | |||
260 | Ty::simple(TypeCtor::Never) | 258 | Ty::simple(TypeCtor::Never) |
261 | } | 259 | } |
262 | Expr::Return { expr } => { | 260 | Expr::Return { expr } => { |