From fb5891c4330e577f5d6891be529141695ce36d4f Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 6 Mar 2020 14:44:44 +0100 Subject: Source map returns a result cc #2236 --- crates/ra_hir_ty/src/expr.rs | 4 ++-- crates/ra_hir_ty/src/tests.rs | 17 +++++++++++------ 2 files changed, 13 insertions(+), 8 deletions(-) (limited to 'crates/ra_hir_ty/src') diff --git a/crates/ra_hir_ty/src/expr.rs b/crates/ra_hir_ty/src/expr.rs index 22f24890d..d8cdf5266 100644 --- a/crates/ra_hir_ty/src/expr.rs +++ b/crates/ra_hir_ty/src/expr.rs @@ -100,7 +100,7 @@ impl<'a, 'b> ExprValidator<'a, 'b> { } let (_, source_map) = db.body_with_source_map(self.func.into()); - if let Some(source_ptr) = source_map.expr_syntax(id) { + if let Ok(source_ptr) = source_map.expr_syntax(id) { if let Some(expr) = source_ptr.value.left() { let root = source_ptr.file_syntax(db); if let ast::Expr::RecordLit(record_lit) = expr.to_node(&root) { @@ -145,7 +145,7 @@ impl<'a, 'b> ExprValidator<'a, 'b> { if params.len() == 2 && params[0] == mismatch.actual { let (_, source_map) = db.body_with_source_map(self.func.into()); - if let Some(source_ptr) = source_map.expr_syntax(id) { + if let Ok(source_ptr) = source_map.expr_syntax(id) { if let Some(expr) = source_ptr.value.left() { self.sink.push(MissingOkInTailExpr { file: source_ptr.file_id, expr }); } diff --git a/crates/ra_hir_ty/src/tests.rs b/crates/ra_hir_ty/src/tests.rs index 087edcc92..7e9547340 100644 --- a/crates/ra_hir_ty/src/tests.rs +++ b/crates/ra_hir_ty/src/tests.rs @@ -11,8 +11,13 @@ use std::fmt::Write; use std::sync::Arc; use hir_def::{ - body::BodySourceMap, child_by_source::ChildBySource, db::DefDatabase, item_scope::ItemScope, - keys, nameres::CrateDefMap, AssocItemId, DefWithBodyId, LocalModuleId, Lookup, ModuleDefId, + body::{BodySourceMap, SyntheticSyntax}, + child_by_source::ChildBySource, + db::DefDatabase, + item_scope::ItemScope, + keys, + nameres::CrateDefMap, + AssocItemId, DefWithBodyId, LocalModuleId, Lookup, ModuleDefId, }; use hir_expand::InFile; use insta::assert_snapshot; @@ -67,20 +72,20 @@ fn infer_with_mismatches(content: &str, include_mismatches: bool) -> String { for (pat, ty) in inference_result.type_of_pat.iter() { let syntax_ptr = match body_source_map.pat_syntax(pat) { - Some(sp) => { + Ok(sp) => { sp.map(|ast| ast.either(|it| it.syntax_node_ptr(), |it| it.syntax_node_ptr())) } - None => continue, + Err(SyntheticSyntax) => continue, }; types.push((syntax_ptr, ty)); } for (expr, ty) in inference_result.type_of_expr.iter() { let syntax_ptr = match body_source_map.expr_syntax(expr) { - Some(sp) => { + Ok(sp) => { sp.map(|ast| ast.either(|it| it.syntax_node_ptr(), |it| it.syntax_node_ptr())) } - None => continue, + Err(SyntheticSyntax) => continue, }; types.push((syntax_ptr, ty)); if let Some(mismatch) = inference_result.type_mismatch_for_expr(expr) { -- cgit v1.2.3