aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2019-02-01 07:52:36 +0000
committerAleksey Kladov <[email protected]>2019-02-01 07:52:36 +0000
commitde85f1e94740d9a19066f7fda2e57d26973e472c (patch)
tree7346c0bed5398138702c83aafff7ee6752e821ab /crates/ra_hir/src
parent9d3f4624e1a83eb945f4df6427fc650356ea77fa (diff)
remove hard-coded support for ctry macro
It was used mainly to prevent HirFileId infra from bitroting, but the `vec![]` macro can serve that just as well!
Diffstat (limited to 'crates/ra_hir/src')
-rw-r--r--crates/ra_hir/src/macros.rs30
1 files changed, 1 insertions, 29 deletions
diff --git a/crates/ra_hir/src/macros.rs b/crates/ra_hir/src/macros.rs
index 7ca34d434..cf7220875 100644
--- a/crates/ra_hir/src/macros.rs
+++ b/crates/ra_hir/src/macros.rs
@@ -19,7 +19,6 @@ use crate::{HirDatabase, MacroCallId};
19// Hard-coded defs for now :-( 19// Hard-coded defs for now :-(
20#[derive(Debug, Clone, PartialEq, Eq, Hash)] 20#[derive(Debug, Clone, PartialEq, Eq, Hash)]
21pub enum MacroDef { 21pub enum MacroDef {
22 CTry,
23 Vec, 22 Vec,
24 QueryGroup, 23 QueryGroup,
25} 24}
@@ -38,9 +37,7 @@ impl MacroDef {
38 let def = { 37 let def = {
39 let path = macro_call.path()?; 38 let path = macro_call.path()?;
40 let name_ref = path.segment()?.name_ref()?; 39 let name_ref = path.segment()?.name_ref()?;
41 if name_ref.text() == "ctry" { 40 if name_ref.text() == "vec" {
42 MacroDef::CTry
43 } else if name_ref.text() == "vec" {
44 MacroDef::Vec 41 MacroDef::Vec
45 } else if name_ref.text() == "query_group" { 42 } else if name_ref.text() == "query_group" {
46 MacroDef::QueryGroup 43 MacroDef::QueryGroup
@@ -60,35 +57,10 @@ impl MacroDef {
60 57
61 fn expand(self, input: MacroInput) -> Option<MacroExpansion> { 58 fn expand(self, input: MacroInput) -> Option<MacroExpansion> {
62 match self { 59 match self {
63 MacroDef::CTry => self.expand_ctry(input),
64 MacroDef::Vec => self.expand_vec(input), 60 MacroDef::Vec => self.expand_vec(input),
65 MacroDef::QueryGroup => self.expand_query_group(input), 61 MacroDef::QueryGroup => self.expand_query_group(input),
66 } 62 }
67 } 63 }
68 fn expand_ctry(self, input: MacroInput) -> Option<MacroExpansion> {
69 let text = format!(
70 r"
71 fn dummy() {{
72 match {} {{
73 None => return Ok(None),
74 Some(it) => it,
75 }}
76 }}",
77 input.text
78 );
79 let file = SourceFile::parse(&text);
80 let match_expr = file.syntax().descendants().find_map(ast::MatchExpr::cast)?;
81 let match_arg = match_expr.expr()?;
82 let ptr = SyntaxNodePtr::new(match_arg.syntax());
83 let src_range = TextRange::offset_len(0.into(), TextUnit::of_str(&input.text));
84 let ranges_map = vec![(src_range, match_arg.syntax().range())];
85 let res = MacroExpansion {
86 text,
87 ranges_map,
88 ptr,
89 };
90 Some(res)
91 }
92 fn expand_vec(self, input: MacroInput) -> Option<MacroExpansion> { 64 fn expand_vec(self, input: MacroInput) -> Option<MacroExpansion> {
93 let text = format!(r"fn dummy() {{ {}; }}", input.text); 65 let text = format!(r"fn dummy() {{ {}; }}", input.text);
94 let file = SourceFile::parse(&text); 66 let file = SourceFile::parse(&text);