aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_ty/src/infer
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2020-12-12 10:18:16 +0000
committerGitHub <[email protected]>2020-12-12 10:18:16 +0000
commit70db57cc5959654004dc8bd044dc65b712e79553 (patch)
treeb5753240aa626ccc30701f132e1538ad86462a7c /crates/hir_ty/src/infer
parent4998807039095cdfbc8725197dfcec1cc4671da9 (diff)
parent378ec2841bf344c05fe6119c0013edeabcf33a35 (diff)
Merge #6839
6839: Infer labeled blocks r=flodiebold a=Veykril The test should cover all the interesting cases I believe(main part of it is copied from the loop label break test above it). The test is indented to stay consistent with the rest of the tests in the file, I can dedent all the tests in the file in a follow up PR if desired. Co-authored-by: Lukas Wirth <[email protected]>
Diffstat (limited to 'crates/hir_ty/src/infer')
-rw-r--r--crates/hir_ty/src/infer/expr.rs22
1 files changed, 18 insertions, 4 deletions
diff --git a/crates/hir_ty/src/infer/expr.rs b/crates/hir_ty/src/infer/expr.rs
index 605951b10..d7ad198b3 100644
--- a/crates/hir_ty/src/infer/expr.rs
+++ b/crates/hir_ty/src/infer/expr.rs
@@ -137,10 +137,24 @@ impl<'a> InferenceContext<'a> {
137 137
138 self.coerce_merge_branch(&then_ty, &else_ty) 138 self.coerce_merge_branch(&then_ty, &else_ty)
139 } 139 }
140 Expr::Block { statements, tail, .. } => { 140 Expr::Block { statements, tail, label } => match label {
141 // FIXME: Breakable block inference 141 Some(_) => {
142 self.infer_block(statements, *tail, expected) 142 let break_ty = self.table.new_type_var();
143 } 143 self.breakables.push(BreakableContext {
144 may_break: false,
145 break_ty: break_ty.clone(),
146 label: label.clone(),
147 });
148 let ty = self.infer_block(statements, *tail, &Expectation::has_type(break_ty));
149 let ctxt = self.breakables.pop().expect("breakable stack broken");
150 if ctxt.may_break {
151 ctxt.break_ty
152 } else {
153 ty
154 }
155 }
156 None => self.infer_block(statements, *tail, expected),
157 },
144 Expr::Unsafe { body } => self.infer_expr(*body, expected), 158 Expr::Unsafe { body } => self.infer_expr(*body, expected),
145 Expr::TryBlock { body } => { 159 Expr::TryBlock { body } => {
146 let _inner = self.infer_expr(*body, expected); 160 let _inner = self.infer_expr(*body, expected);