aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_hir/src/expr/validation.rs17
-rw-r--r--crates/ra_syntax/src/ptr.rs7
2 files changed, 10 insertions, 14 deletions
diff --git a/crates/ra_hir/src/expr/validation.rs b/crates/ra_hir/src/expr/validation.rs
index fce1c2f14..e35990d2e 100644
--- a/crates/ra_hir/src/expr/validation.rs
+++ b/crates/ra_hir/src/expr/validation.rs
@@ -145,21 +145,10 @@ impl<'a, 'b> ExprValidator<'a, 'b> {
145 if params.len() == 2 && &params[0] == &mismatch.actual { 145 if params.len() == 2 && &params[0] == &mismatch.actual {
146 let source_map = self.func.body_source_map(db); 146 let source_map = self.func.body_source_map(db);
147 let file_id = self.func.source(db).file_id; 147 let file_id = self.func.source(db).file_id;
148 let parse = db.parse(file_id.original_file(db));
149 let source_file = parse.tree();
150 let expr_syntax = source_map.expr_syntax(id);
151 if expr_syntax.is_none() {
152 return;
153 }
154 let expr_syntax = expr_syntax.unwrap();
155 let node = expr_syntax.to_node(source_file.syntax());
156 let ast = ast::Expr::cast(node);
157 if ast.is_none() {
158 return;
159 }
160 let ast = ast.unwrap();
161 148
162 self.sink.push(MissingOkInTailExpr { file: file_id, expr: AstPtr::new(&ast) }); 149 if let Some(expr) = source_map.expr_syntax(id).and_then(|n| n.cast::<ast::Expr>()) {
150 self.sink.push(MissingOkInTailExpr { file: file_id, expr });
151 }
163 } 152 }
164 } 153 }
165} 154}
diff --git a/crates/ra_syntax/src/ptr.rs b/crates/ra_syntax/src/ptr.rs
index d24660ac3..992034ef0 100644
--- a/crates/ra_syntax/src/ptr.rs
+++ b/crates/ra_syntax/src/ptr.rs
@@ -31,6 +31,13 @@ impl SyntaxNodePtr {
31 pub fn kind(self) -> SyntaxKind { 31 pub fn kind(self) -> SyntaxKind {
32 self.kind 32 self.kind
33 } 33 }
34
35 pub fn cast<N: AstNode>(self) -> Option<AstPtr<N>> {
36 if !N::can_cast(self.kind()) {
37 return None;
38 }
39 Some(AstPtr { raw: self, _ty: PhantomData })
40 }
34} 41}
35 42
36/// Like `SyntaxNodePtr`, but remembers the type of node 43/// Like `SyntaxNodePtr`, but remembers the type of node