mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-01 07:48:45 +00:00
Remove hir_expand macro recursion check
This commit is contained in:
parent
b5eaf56666
commit
9de54570d6
1 changed files with 1 additions and 40 deletions
|
@ -8,7 +8,6 @@ use limit::Limit;
|
||||||
use mbe::syntax_node_to_token_tree;
|
use mbe::syntax_node_to_token_tree;
|
||||||
use rustc_hash::FxHashSet;
|
use rustc_hash::FxHashSet;
|
||||||
use syntax::{
|
use syntax::{
|
||||||
algo::diff,
|
|
||||||
ast::{self, HasAttrs, HasDocComments},
|
ast::{self, HasAttrs, HasDocComments},
|
||||||
AstNode, GreenNode, Parse, SyntaxNode, SyntaxToken, T,
|
AstNode, GreenNode, Parse, SyntaxNode, SyntaxToken, T,
|
||||||
};
|
};
|
||||||
|
@ -283,28 +282,7 @@ fn parse_macro_expansion(
|
||||||
|
|
||||||
let (parse, rev_token_map) = token_tree_to_syntax_node(&tt, expand_to);
|
let (parse, rev_token_map) = token_tree_to_syntax_node(&tt, expand_to);
|
||||||
|
|
||||||
match result.err {
|
ExpandResult { value: Some((parse, Arc::new(rev_token_map))), err: result.err }
|
||||||
Some(err) => {
|
|
||||||
// Safety check for recursive identity macro.
|
|
||||||
let node = parse.syntax_node();
|
|
||||||
let file: HirFileId = macro_file.into();
|
|
||||||
let call_node = match file.call_node(db) {
|
|
||||||
Some(it) => it,
|
|
||||||
None => {
|
|
||||||
return ExpandResult::only_err(err);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
if is_self_replicating(&node, &call_node.value) {
|
|
||||||
ExpandResult::only_err(err)
|
|
||||||
} else {
|
|
||||||
ExpandResult { value: Some((parse, Arc::new(rev_token_map))), err: Some(err) }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
None => {
|
|
||||||
tracing::debug!("parse = {:?}", parse.syntax_node().kind());
|
|
||||||
ExpandResult { value: Some((parse, Arc::new(rev_token_map))), err: None }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn macro_arg(
|
fn macro_arg(
|
||||||
|
@ -507,23 +485,6 @@ fn expand_proc_macro(db: &dyn AstDatabase, id: MacroCallId) -> ExpandResult<tt::
|
||||||
expander.expand(db, loc.krate, ¯o_arg.0, attr_arg.as_ref())
|
expander.expand(db, loc.krate, ¯o_arg.0, attr_arg.as_ref())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_self_replicating(from: &SyntaxNode, to: &SyntaxNode) -> bool {
|
|
||||||
if diff(from, to).is_empty() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if let Some(stmts) = ast::MacroStmts::cast(from.clone()) {
|
|
||||||
if stmts.statements().any(|stmt| diff(stmt.syntax(), to).is_empty()) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if let Some(expr) = stmts.expr() {
|
|
||||||
if diff(expr.syntax(), to).is_empty() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
false
|
|
||||||
}
|
|
||||||
|
|
||||||
fn hygiene_frame(db: &dyn AstDatabase, file_id: HirFileId) -> Arc<HygieneFrame> {
|
fn hygiene_frame(db: &dyn AstDatabase, file_id: HirFileId) -> Arc<HygieneFrame> {
|
||||||
Arc::new(HygieneFrame::new(db, file_id))
|
Arc::new(HygieneFrame::new(db, file_id))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue