Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not set depth to 0 in fully_expand_fragment #86484

Merged
merged 1 commit into from
Jun 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/rustc_expand/src/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) =
Expand Down Expand Up @@ -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;

Expand Down
16 changes: 16 additions & 0 deletions src/test/ui/macros/issue-84632-eager-expansion-recursion-limit.rs
Original file line number Diff line number Diff line change
@@ -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);
}
Original file line number Diff line number Diff line change
@@ -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