mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 12:54:58 +00:00
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:
parent
9d3f4624e1
commit
de85f1e947
5 changed files with 16 additions and 73 deletions
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue