diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2019-09-02 20:20:24 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2019-09-02 20:20:24 +0100 |
commit | 7faec1c30046769d4ae490e15cf5405bcfbdeef8 (patch) | |
tree | 6d268b721027a5350928a6c5a0ec227b5fde8ebc /crates/ra_hir/src/expr | |
parent | a8397deab914240aca8f015fb3736689919c0a5b (diff) | |
parent | e94587e3153b52684fd3f6b82c8e7efc09ff5c8d (diff) |
Merge #1752
1752: Always wrap blocks into block expressions r=flodiebold a=matklad
This way, things like function bodies are expressions, and we don't have to single them out
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_hir/src/expr')
-rw-r--r-- | crates/ra_hir/src/expr/scope.rs | 5 | ||||
-rw-r--r-- | crates/ra_hir/src/expr/validation.rs | 13 |
2 files changed, 10 insertions, 8 deletions
diff --git a/crates/ra_hir/src/expr/scope.rs b/crates/ra_hir/src/expr/scope.rs index 79e1857f9..b6d7f3fc1 100644 --- a/crates/ra_hir/src/expr/scope.rs +++ b/crates/ra_hir/src/expr/scope.rs | |||
@@ -172,7 +172,7 @@ fn compute_expr_scopes(expr: ExprId, body: &Body, scopes: &mut ExprScopes, scope | |||
172 | #[cfg(test)] | 172 | #[cfg(test)] |
173 | mod tests { | 173 | mod tests { |
174 | use ra_db::SourceDatabase; | 174 | use ra_db::SourceDatabase; |
175 | use ra_syntax::{algo::find_node_at_offset, ast, AstNode, SyntaxNodePtr}; | 175 | use ra_syntax::{algo::find_node_at_offset, ast, AstNode}; |
176 | use test_utils::{assert_eq_text, extract_offset}; | 176 | use test_utils::{assert_eq_text, extract_offset}; |
177 | 177 | ||
178 | use crate::{mock::MockDatabase, source_binder::SourceAnalyzer}; | 178 | use crate::{mock::MockDatabase, source_binder::SourceAnalyzer}; |
@@ -194,8 +194,7 @@ mod tests { | |||
194 | let analyzer = SourceAnalyzer::new(&db, file_id, marker.syntax(), None); | 194 | let analyzer = SourceAnalyzer::new(&db, file_id, marker.syntax(), None); |
195 | 195 | ||
196 | let scopes = analyzer.scopes(); | 196 | let scopes = analyzer.scopes(); |
197 | let expr_id = | 197 | let expr_id = analyzer.body_source_map().node_expr(&marker.into()).unwrap(); |
198 | analyzer.body_source_map().syntax_expr(SyntaxNodePtr::new(marker.syntax())).unwrap(); | ||
199 | let scope = scopes.scope_for(expr_id); | 198 | let scope = scopes.scope_for(expr_id); |
200 | 199 | ||
201 | let actual = scopes | 200 | let actual = scopes |
diff --git a/crates/ra_hir/src/expr/validation.rs b/crates/ra_hir/src/expr/validation.rs index c8ae19869..6fdaf1fce 100644 --- a/crates/ra_hir/src/expr/validation.rs +++ b/crates/ra_hir/src/expr/validation.rs | |||
@@ -1,7 +1,7 @@ | |||
1 | use rustc_hash::FxHashSet; | ||
2 | use std::sync::Arc; | 1 | use std::sync::Arc; |
3 | 2 | ||
4 | use ra_syntax::ast::{AstNode, RecordLit}; | 3 | use ra_syntax::ast::{self, AstNode}; |
4 | use rustc_hash::FxHashSet; | ||
5 | 5 | ||
6 | use super::{Expr, ExprId, RecordLitField}; | 6 | use super::{Expr, ExprId, RecordLitField}; |
7 | use crate::{ | 7 | use crate::{ |
@@ -13,7 +13,6 @@ use crate::{ | |||
13 | ty::{ApplicationTy, InferenceResult, Ty, TypeCtor}, | 13 | ty::{ApplicationTy, InferenceResult, Ty, TypeCtor}, |
14 | Function, HasSource, HirDatabase, ModuleDef, Name, Path, PerNs, Resolution, | 14 | Function, HasSource, HirDatabase, ModuleDef, Name, Path, PerNs, Resolution, |
15 | }; | 15 | }; |
16 | use ra_syntax::ast; | ||
17 | 16 | ||
18 | pub(crate) struct ExprValidator<'a, 'b: 'a> { | 17 | pub(crate) struct ExprValidator<'a, 'b: 'a> { |
19 | func: Function, | 18 | func: Function, |
@@ -84,8 +83,12 @@ impl<'a, 'b> ExprValidator<'a, 'b> { | |||
84 | let source_file = parse.tree(); | 83 | let source_file = parse.tree(); |
85 | if let Some(field_list_node) = source_map | 84 | if let Some(field_list_node) = source_map |
86 | .expr_syntax(id) | 85 | .expr_syntax(id) |
86 | .and_then(|ptr| ptr.a()) | ||
87 | .map(|ptr| ptr.to_node(source_file.syntax())) | 87 | .map(|ptr| ptr.to_node(source_file.syntax())) |
88 | .and_then(RecordLit::cast) | 88 | .and_then(|expr| match expr { |
89 | ast::Expr::RecordLit(it) => Some(it), | ||
90 | _ => None, | ||
91 | }) | ||
89 | .and_then(|lit| lit.record_field_list()) | 92 | .and_then(|lit| lit.record_field_list()) |
90 | { | 93 | { |
91 | let field_list_ptr = AstPtr::new(&field_list_node); | 94 | let field_list_ptr = AstPtr::new(&field_list_node); |
@@ -135,7 +138,7 @@ impl<'a, 'b> ExprValidator<'a, 'b> { | |||
135 | let source_map = self.func.body_source_map(db); | 138 | let source_map = self.func.body_source_map(db); |
136 | let file_id = self.func.source(db).file_id; | 139 | let file_id = self.func.source(db).file_id; |
137 | 140 | ||
138 | if let Some(expr) = source_map.expr_syntax(id).and_then(|n| n.cast::<ast::Expr>()) { | 141 | if let Some(expr) = source_map.expr_syntax(id).and_then(|n| n.a()) { |
139 | self.sink.push(MissingOkInTailExpr { file: file_id, expr }); | 142 | self.sink.push(MissingOkInTailExpr { file: file_id, expr }); |
140 | } | 143 | } |
141 | } | 144 | } |