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_def/src/body.rs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'crates/ra_hir_def') diff --git a/crates/ra_hir_def/src/body.rs b/crates/ra_hir_def/src/body.rs index 010d35e55..cd9e22c42 100644 --- a/crates/ra_hir_def/src/body.rs +++ b/crates/ra_hir_def/src/body.rs @@ -156,6 +156,9 @@ pub struct BodySourceMap { expansions: FxHashMap>, HirFileId>, } +#[derive(Debug)] +pub struct SyntheticSyntax; + impl Body { pub(crate) fn body_with_source_map_query( db: &impl DefDatabase, @@ -219,8 +222,8 @@ impl Index for Body { } impl BodySourceMap { - pub fn expr_syntax(&self, expr: ExprId) -> Option { - self.expr_map_back.get(expr).copied() + pub fn expr_syntax(&self, expr: ExprId) -> Result { + self.expr_map_back.get(expr).copied().ok_or(SyntheticSyntax) } pub fn node_expr(&self, node: InFile<&ast::Expr>) -> Option { @@ -238,8 +241,8 @@ impl BodySourceMap { self.expr_map.get(&src).cloned() } - pub fn pat_syntax(&self, pat: PatId) -> Option { - self.pat_map_back.get(pat).copied() + pub fn pat_syntax(&self, pat: PatId) -> Result { + self.pat_map_back.get(pat).copied().ok_or(SyntheticSyntax) } pub fn node_pat(&self, node: InFile<&ast::Pat>) -> Option { -- cgit v1.2.3