Skip to content

Commit 2366d8e

Browse files
bors[bot]Jonas Schievink
and
Jonas Schievink
authored
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 #3671 Co-authored-by: Jonas Schievink <[email protected]>
2 parents ee6becc + 9de5457 commit 2366d8e

File tree

1 file changed

+1
-40
lines changed
  • crates/hir_expand/src

1 file changed

+1
-40
lines changed

crates/hir_expand/src/db.rs

Lines changed: 1 addition & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ use limit::Limit;
88
use mbe::syntax_node_to_token_tree;
99
use rustc_hash::FxHashSet;
1010
use syntax::{
11-
algo::diff,
1211
ast::{self, HasAttrs, HasDocComments},
1312
AstNode, GreenNode, Parse, SyntaxNode, SyntaxToken, T,
1413
};
@@ -283,28 +282,7 @@ fn parse_macro_expansion(
283282

284283
let (parse, rev_token_map) = token_tree_to_syntax_node(&tt, expand_to);
285284

286-
match result.err {
287-
Some(err) => {
288-
// Safety check for recursive identity macro.
289-
let node = parse.syntax_node();
290-
let file: HirFileId = macro_file.into();
291-
let call_node = match file.call_node(db) {
292-
Some(it) => it,
293-
None => {
294-
return ExpandResult::only_err(err);
295-
}
296-
};
297-
if is_self_replicating(&node, &call_node.value) {
298-
ExpandResult::only_err(err)
299-
} else {
300-
ExpandResult { value: Some((parse, Arc::new(rev_token_map))), err: Some(err) }
301-
}
302-
}
303-
None => {
304-
tracing::debug!("parse = {:?}", parse.syntax_node().kind());
305-
ExpandResult { value: Some((parse, Arc::new(rev_token_map))), err: None }
306-
}
307-
}
285+
ExpandResult { value: Some((parse, Arc::new(rev_token_map))), err: result.err }
308286
}
309287

310288
fn macro_arg(
@@ -507,23 +485,6 @@ fn expand_proc_macro(db: &dyn AstDatabase, id: MacroCallId) -> ExpandResult<tt::
507485
expander.expand(db, loc.krate, &macro_arg.0, attr_arg.as_ref())
508486
}
509487

510-
fn is_self_replicating(from: &SyntaxNode, to: &SyntaxNode) -> bool {
511-
if diff(from, to).is_empty() {
512-
return true;
513-
}
514-
if let Some(stmts) = ast::MacroStmts::cast(from.clone()) {
515-
if stmts.statements().any(|stmt| diff(stmt.syntax(), to).is_empty()) {
516-
return true;
517-
}
518-
if let Some(expr) = stmts.expr() {
519-
if diff(expr.syntax(), to).is_empty() {
520-
return true;
521-
}
522-
}
523-
}
524-
false
525-
}
526-
527488
fn hygiene_frame(db: &dyn AstDatabase, file_id: HirFileId) -> Arc<HygieneFrame> {
528489
Arc::new(HygieneFrame::new(db, file_id))
529490
}

0 commit comments

Comments
 (0)