aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/expr
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2019-09-02 20:20:24 +0100
committerGitHub <[email protected]>2019-09-02 20:20:24 +0100
commit7faec1c30046769d4ae490e15cf5405bcfbdeef8 (patch)
tree6d268b721027a5350928a6c5a0ec227b5fde8ebc /crates/ra_hir/src/expr
parenta8397deab914240aca8f015fb3736689919c0a5b (diff)
parente94587e3153b52684fd3f6b82c8e7efc09ff5c8d (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.rs5
-rw-r--r--crates/ra_hir/src/expr/validation.rs13
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)]
173mod tests { 173mod 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 @@
1use rustc_hash::FxHashSet;
2use std::sync::Arc; 1use std::sync::Arc;
3 2
4use ra_syntax::ast::{AstNode, RecordLit}; 3use ra_syntax::ast::{self, AstNode};
4use rustc_hash::FxHashSet;
5 5
6use super::{Expr, ExprId, RecordLitField}; 6use super::{Expr, ExprId, RecordLitField};
7use crate::{ 7use 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};
16use ra_syntax::ast;
17 16
18pub(crate) struct ExprValidator<'a, 'b: 'a> { 17pub(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 }