aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_def
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2020-03-06 13:44:44 +0000
committerAleksey Kladov <[email protected]>2020-03-06 13:44:44 +0000
commitfb5891c4330e577f5d6891be529141695ce36d4f (patch)
tree6c7f1384e77c29b9bdc3080acfbaadb1bcb01f0f /crates/ra_hir_def
parentea0c124219da33462b9d0be93f7abe0478cc7af2 (diff)
Source map returns a result
cc #2236
Diffstat (limited to 'crates/ra_hir_def')
-rw-r--r--crates/ra_hir_def/src/body.rs11
1 files changed, 7 insertions, 4 deletions
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 {
156 expansions: FxHashMap<InFile<AstPtr<ast::MacroCall>>, HirFileId>, 156 expansions: FxHashMap<InFile<AstPtr<ast::MacroCall>>, HirFileId>,
157} 157}
158 158
159#[derive(Debug)]
160pub struct SyntheticSyntax;
161
159impl Body { 162impl Body {
160 pub(crate) fn body_with_source_map_query( 163 pub(crate) fn body_with_source_map_query(
161 db: &impl DefDatabase, 164 db: &impl DefDatabase,
@@ -219,8 +222,8 @@ impl Index<PatId> for Body {
219} 222}
220 223
221impl BodySourceMap { 224impl BodySourceMap {
222 pub fn expr_syntax(&self, expr: ExprId) -> Option<ExprSource> { 225 pub fn expr_syntax(&self, expr: ExprId) -> Result<ExprSource, SyntheticSyntax> {
223 self.expr_map_back.get(expr).copied() 226 self.expr_map_back.get(expr).copied().ok_or(SyntheticSyntax)
224 } 227 }
225 228
226 pub fn node_expr(&self, node: InFile<&ast::Expr>) -> Option<ExprId> { 229 pub fn node_expr(&self, node: InFile<&ast::Expr>) -> Option<ExprId> {
@@ -238,8 +241,8 @@ impl BodySourceMap {
238 self.expr_map.get(&src).cloned() 241 self.expr_map.get(&src).cloned()
239 } 242 }
240 243
241 pub fn pat_syntax(&self, pat: PatId) -> Option<PatSource> { 244 pub fn pat_syntax(&self, pat: PatId) -> Result<PatSource, SyntheticSyntax> {
242 self.pat_map_back.get(pat).copied() 245 self.pat_map_back.get(pat).copied().ok_or(SyntheticSyntax)
243 } 246 }
244 247
245 pub fn node_pat(&self, node: InFile<&ast::Pat>) -> Option<PatId> { 248 pub fn node_pat(&self, node: InFile<&ast::Pat>) -> Option<PatId> {