aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src
diff options
context:
space:
mode:
authorbors[bot] <bors[bot]@users.noreply.github.com>2019-02-01 07:54:32 +0000
committerbors[bot] <bors[bot]@users.noreply.github.com>2019-02-01 07:54:32 +0000
commit21c593593163c22b996f7c8bffe05b9708f5b2d0 (patch)
tree7346c0bed5398138702c83aafff7ee6752e821ab /crates/ra_hir/src
parent9d3f4624e1a83eb945f4df6427fc650356ea77fa (diff)
parentde85f1e94740d9a19066f7fda2e57d26973e472c (diff)
Merge #722
722: remove hard-coded support for ctry macro r=matklad a=matklad It was used mainly to prevent HirFileId infra from bitroting, but the `vec![]` macro can serve that just as well! Co-authored-by: Aleksey Kladov <[email protected]>
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);