Skip to content

Commit e5ecded

Browse files
authored
Rollup merge of #86484 - fee1-dead:builtin-macro-recursion, r=petrochenkov
Do not set depth to 0 in fully_expand_fragment Fixes #84632.
2 parents 504c378 + 37d0d27 commit e5ecded

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

Diff for: compiler/rustc_expand/src/expand.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,6 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
427427
pub fn fully_expand_fragment(&mut self, input_fragment: AstFragment) -> AstFragment {
428428
let orig_expansion_data = self.cx.current_expansion.clone();
429429
let orig_force_mode = self.cx.force_mode;
430-
self.cx.current_expansion.depth = 0;
431430

432431
// Collect all macro invocations and replace them with placeholders.
433432
let (mut fragment_with_placeholders, mut invocations) =
@@ -488,6 +487,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
488487
};
489488

490489
let ExpansionData { depth, id: expn_id, .. } = invoc.expansion_data;
490+
let depth = depth - orig_expansion_data.depth;
491491
self.cx.current_expansion = invoc.expansion_data.clone();
492492
self.cx.force_mode = force;
493493

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Regression test for #84632: Recursion limit is ignored
2+
// for builtin macros that eagerly expands.
3+
4+
#![recursion_limit = "15"]
5+
macro_rules! a {
6+
() => ("");
7+
(A) => (concat!("", a!()));
8+
(A, $($A:ident),*) => (concat!("", a!($($A),*)))
9+
//~^ ERROR recursion limit reached
10+
//~| HELP consider adding
11+
}
12+
13+
fn main() {
14+
a!(A, A, A, A, A);
15+
a!(A, A, A, A, A, A, A, A, A, A, A);
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
error: recursion limit reached while expanding `concat!`
2+
--> $DIR/issue-84632-eager-expansion-recursion-limit.rs:8:28
3+
|
4+
LL | (A, $($A:ident),*) => (concat!("", a!($($A),*)))
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^
6+
...
7+
LL | a!(A, A, A, A, A, A, A, A, A, A, A);
8+
| ------------------------------------ in this macro invocation
9+
|
10+
= help: consider adding a `#![recursion_limit="30"]` attribute to your crate (`issue_84632_eager_expansion_recursion_limit`)
11+
= note: this error originates in the macro `a` (in Nightly builds, run with -Z macro-backtrace for more info)
12+
13+
error: aborting due to previous error
14+

0 commit comments

Comments
 (0)