mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-24 07:44:10 +00:00
Merge #11905
11905: internal: Remove hir_expand macro recursion check r=jonas-schievink a=jonas-schievink This check is insufficient to ensure finite macro nesting, and so all callers already have their own recursion limit, which makes this check redundant. ...at least I hope it's redundant. Would be great if someone could double-check this. Originally, this check was added in https://github.com/rust-analyzer/rust-analyzer/pull/3671 Co-authored-by: Jonas Schievink <jonas.schievink@ferrous-systems.com>
This commit is contained in:
commit
2366d8e05f
@ -8,7 +8,6 @@ use limit::Limit;
|
||||
use mbe::syntax_node_to_token_tree;
|
||||
use rustc_hash::FxHashSet;
|
||||
use syntax::{
|
||||
algo::diff,
|
||||
ast::{self, HasAttrs, HasDocComments},
|
||||
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);
|
||||
|
||||
match 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 }
|
||||
}
|
||||
}
|
||||
ExpandResult { value: Some((parse, Arc::new(rev_token_map))), err: result.err }
|
||||
}
|
||||
|
||||
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())
|
||||
}
|
||||
|
||||
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> {
|
||||
Arc::new(HygieneFrame::new(db, file_id))
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user