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!
This commit is contained in:
Aleksey Kladov 2019-02-01 10:52:36 +03:00
parent 9d3f4624e1
commit de85f1e947
5 changed files with 16 additions and 73 deletions

View file

@ -19,7 +19,6 @@ use crate::{HirDatabase, MacroCallId};
// Hard-coded defs for now :-(
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum MacroDef {
CTry,
Vec,
QueryGroup,
}
@ -38,9 +37,7 @@ impl MacroDef {
let def = {
let path = macro_call.path()?;
let name_ref = path.segment()?.name_ref()?;
if name_ref.text() == "ctry" {
MacroDef::CTry
} else if name_ref.text() == "vec" {
if name_ref.text() == "vec" {
MacroDef::Vec
} else if name_ref.text() == "query_group" {
MacroDef::QueryGroup
@ -60,35 +57,10 @@ impl MacroDef {
fn expand(self, input: MacroInput) -> Option<MacroExpansion> {
match self {
MacroDef::CTry => self.expand_ctry(input),
MacroDef::Vec => self.expand_vec(input),
MacroDef::QueryGroup => self.expand_query_group(input),
}
}
fn expand_ctry(self, input: MacroInput) -> Option<MacroExpansion> {
let text = format!(
r"
fn dummy() {{
match {} {{
None => return Ok(None),
Some(it) => it,
}}
}}",
input.text
);
let file = SourceFile::parse(&text);
let match_expr = file.syntax().descendants().find_map(ast::MatchExpr::cast)?;
let match_arg = match_expr.expr()?;
let ptr = SyntaxNodePtr::new(match_arg.syntax());
let src_range = TextRange::offset_len(0.into(), TextUnit::of_str(&input.text));
let ranges_map = vec![(src_range, match_arg.syntax().range())];
let res = MacroExpansion {
text,
ranges_map,
ptr,
};
Some(res)
}
fn expand_vec(self, input: MacroInput) -> Option<MacroExpansion> {
let text = format!(r"fn dummy() {{ {}; }}", input.text);
let file = SourceFile::parse(&text);