diff options
| author | Yuki Okushi <jtitor@2k36.org> | 2021-06-21 09:42:18 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-06-21 09:42:18 +0900 |
| commit | e5ecded392916860dfc9bad840a115572610f1fb (patch) | |
| tree | 0e2e5811cbd18d0d72de96143d9b5d5969462b88 | |
| parent | 504c378159c43869c148b4a0396134ab9c17de3e (diff) | |
| parent | 37d0d2705de7f4103527ab769e61934c9c4a8953 (diff) | |
Rollup merge of #86484 - fee1-dead:builtin-macro-recursion, r=petrochenkov
Do not set depth to 0 in fully_expand_fragment Fixes #84632.
3 files changed, 31 insertions, 1 deletions
diff --git a/compiler/rustc_expand/src/expand.rs b/compiler/rustc_expand/src/expand.rs index 39c0447bd09..37a4765a4be 100644 --- a/compiler/rustc_expand/src/expand.rs +++ b/compiler/rustc_expand/src/expand.rs @@ -427,7 +427,6 @@ impl<'a, 'b> MacroExpander<'a, 'b> { pub fn fully_expand_fragment(&mut self, input_fragment: AstFragment) -> AstFragment { let orig_expansion_data = self.cx.current_expansion.clone(); let orig_force_mode = self.cx.force_mode; - self.cx.current_expansion.depth = 0; // Collect all macro invocations and replace them with placeholders. let (mut fragment_with_placeholders, mut invocations) = @@ -488,6 +487,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> { }; let ExpansionData { depth, id: expn_id, .. } = invoc.expansion_data; + let depth = depth - orig_expansion_data.depth; self.cx.current_expansion = invoc.expansion_data.clone(); self.cx.force_mode = force; diff --git a/src/test/ui/macros/issue-84632-eager-expansion-recursion-limit.rs b/src/test/ui/macros/issue-84632-eager-expansion-recursion-limit.rs new file mode 100644 index 00000000000..9139775c805 --- /dev/null +++ b/src/test/ui/macros/issue-84632-eager-expansion-recursion-limit.rs @@ -0,0 +1,16 @@ +// Regression test for #84632: Recursion limit is ignored +// for builtin macros that eagerly expands. + +#![recursion_limit = "15"] +macro_rules! a { + () => (""); + (A) => (concat!("", a!())); + (A, $($A:ident),*) => (concat!("", a!($($A),*))) + //~^ ERROR recursion limit reached + //~| HELP consider adding +} + +fn main() { + a!(A, A, A, A, A); + a!(A, A, A, A, A, A, A, A, A, A, A); +} diff --git a/src/test/ui/macros/issue-84632-eager-expansion-recursion-limit.stderr b/src/test/ui/macros/issue-84632-eager-expansion-recursion-limit.stderr new file mode 100644 index 00000000000..e6067e33349 --- /dev/null +++ b/src/test/ui/macros/issue-84632-eager-expansion-recursion-limit.stderr @@ -0,0 +1,14 @@ +error: recursion limit reached while expanding `concat!` + --> $DIR/issue-84632-eager-expansion-recursion-limit.rs:8:28 + | +LL | (A, $($A:ident),*) => (concat!("", a!($($A),*))) + | ^^^^^^^^^^^^^^^^^^^^^^^^ +... +LL | a!(A, A, A, A, A, A, A, A, A, A, A); + | ------------------------------------ in this macro invocation + | + = help: consider adding a `#![recursion_limit="30"]` attribute to your crate (`issue_84632_eager_expansion_recursion_limit`) + = note: this error originates in the macro `a` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: aborting due to previous error + |
