From b79fd82559642f4fe504c0c382b86d57c666be1d Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 18 Apr 2020 22:16:04 +0200 Subject: Correctly infer types in guard expressions The root cause was that we forgot to add bindings from the arm to the guard expression closes #3980 --- crates/ra_hir_def/src/body/scope.rs | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'crates/ra_hir_def/src') diff --git a/crates/ra_hir_def/src/body/scope.rs b/crates/ra_hir_def/src/body/scope.rs index 4d489f692..fe4137176 100644 --- a/crates/ra_hir_def/src/body/scope.rs +++ b/crates/ra_hir_def/src/body/scope.rs @@ -157,6 +157,10 @@ fn compute_expr_scopes(expr: ExprId, body: &Body, scopes: &mut ExprScopes, scope for arm in arms { let scope = scopes.new_scope(scope); scopes.add_bindings(body, scope, arm.pat); + if let Some(guard) = arm.guard { + scopes.set_scope(guard, scope); + compute_expr_scopes(guard, body, scopes, scope); + } scopes.set_scope(arm.expr, scope); compute_expr_scopes(arm.expr, body, scopes, scope); } -- cgit v1.2.3 From d7f3d858add197f91969c69b1d4a14dbcb801f03 Mon Sep 17 00:00:00 2001 From: Jeremy Kolb Date: Sun, 19 Apr 2020 15:15:49 -0400 Subject: Some clippy fixes --- crates/ra_hir_def/src/body/lower.rs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'crates/ra_hir_def/src') diff --git a/crates/ra_hir_def/src/body/lower.rs b/crates/ra_hir_def/src/body/lower.rs index 82a52804d..0caedd8d8 100644 --- a/crates/ra_hir_def/src/body/lower.rs +++ b/crates/ra_hir_def/src/body/lower.rs @@ -473,16 +473,14 @@ impl ExprCollector<'_> { self.collect_block_items(&block); let statements = block .statements() - .filter_map(|s| match s { + .map(|s| match s { ast::Stmt::LetStmt(stmt) => { let pat = self.collect_pat_opt(stmt.pat()); let type_ref = stmt.ascribed_type().map(TypeRef::from_ast); let initializer = stmt.initializer().map(|e| self.collect_expr(e)); - Some(Statement::Let { pat, type_ref, initializer }) - } - ast::Stmt::ExprStmt(stmt) => { - Some(Statement::Expr(self.collect_expr_opt(stmt.expr()))) + Statement::Let { pat, type_ref, initializer } } + ast::Stmt::ExprStmt(stmt) => Statement::Expr(self.collect_expr_opt(stmt.expr())), }) .collect(); let tail = block.expr().map(|e| self.collect_expr(e)); -- cgit v1.2.3