Skip to content

Commit 1ca43d4

Browse files
authored
Rollup merge of #105419 - YC:issue-41731, r=petrochenkov
Add tests for #41731 Closes #41731
2 parents d0dc9ef + cf312ae commit 1ca43d4

4 files changed

+106
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// compile-flags: -Z trace-macros
2+
3+
#![recursion_limit = "5"]
4+
5+
fn main() {
6+
macro_rules! stack {
7+
($overflow:expr) => {
8+
print!(stack!($overflow));
9+
//~^ ERROR recursion limit reached while expanding
10+
//~| ERROR format argument must be a string literal
11+
};
12+
}
13+
14+
stack!("overflow");
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
error: recursion limit reached while expanding `$crate::format_args!`
2+
--> $DIR/issue-41731-infinite-macro-print.rs:14:5
3+
|
4+
LL | stack!("overflow");
5+
| ^^^^^^^^^^^^^^^^^^
6+
|
7+
= help: consider increasing the recursion limit by adding a `#![recursion_limit = "10"]` attribute to your crate (`issue_41731_infinite_macro_print`)
8+
= note: this error originates in the macro `print` which comes from the expansion of the macro `stack` (in Nightly builds, run with -Z macro-backtrace for more info)
9+
10+
note: trace_macro
11+
--> $DIR/issue-41731-infinite-macro-print.rs:14:5
12+
|
13+
LL | stack!("overflow");
14+
| ^^^^^^^^^^^^^^^^^^
15+
|
16+
= note: expanding `stack! { "overflow" }`
17+
= note: to `print! (stack! ("overflow")) ;`
18+
= note: expanding `print! { stack! ("overflow") }`
19+
= note: to `{ $crate :: io :: _print($crate :: format_args! (stack! ("overflow"))) ; }`
20+
= note: expanding `stack! { "overflow" }`
21+
= note: to `print! (stack! ("overflow")) ;`
22+
= note: expanding `print! { stack! ("overflow") }`
23+
= note: to `{ $crate :: io :: _print($crate :: format_args! (stack! ("overflow"))) ; }`
24+
25+
error: format argument must be a string literal
26+
--> $DIR/issue-41731-infinite-macro-print.rs:14:5
27+
|
28+
LL | stack!("overflow");
29+
| ^^^^^^^^^^^^^^^^^^
30+
|
31+
= note: this error originates in the macro `print` which comes from the expansion of the macro `stack` (in Nightly builds, run with -Z macro-backtrace for more info)
32+
help: you might be missing a string literal to format with
33+
|
34+
LL | print!("{}", stack!($overflow));
35+
| +++++
36+
37+
error: aborting due to 2 previous errors
38+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// compile-flags: -Z trace-macros
2+
3+
#![recursion_limit = "5"]
4+
5+
fn main() {
6+
macro_rules! stack {
7+
($overflow:expr) => {
8+
println!(stack!($overflow));
9+
//~^ ERROR recursion limit reached while expanding
10+
//~| ERROR format argument must be a string literal
11+
};
12+
}
13+
14+
stack!("overflow");
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
error: recursion limit reached while expanding `$crate::format_args_nl!`
2+
--> $DIR/issue-41731-infinite-macro-println.rs:14:5
3+
|
4+
LL | stack!("overflow");
5+
| ^^^^^^^^^^^^^^^^^^
6+
|
7+
= help: consider increasing the recursion limit by adding a `#![recursion_limit = "10"]` attribute to your crate (`issue_41731_infinite_macro_println`)
8+
= note: this error originates in the macro `println` which comes from the expansion of the macro `stack` (in Nightly builds, run with -Z macro-backtrace for more info)
9+
10+
note: trace_macro
11+
--> $DIR/issue-41731-infinite-macro-println.rs:14:5
12+
|
13+
LL | stack!("overflow");
14+
| ^^^^^^^^^^^^^^^^^^
15+
|
16+
= note: expanding `stack! { "overflow" }`
17+
= note: to `println! (stack! ("overflow")) ;`
18+
= note: expanding `println! { stack! ("overflow") }`
19+
= note: to `{ $crate :: io :: _print($crate :: format_args_nl! (stack! ("overflow"))) ; }`
20+
= note: expanding `stack! { "overflow" }`
21+
= note: to `println! (stack! ("overflow")) ;`
22+
= note: expanding `println! { stack! ("overflow") }`
23+
= note: to `{ $crate :: io :: _print($crate :: format_args_nl! (stack! ("overflow"))) ; }`
24+
25+
error: format argument must be a string literal
26+
--> $DIR/issue-41731-infinite-macro-println.rs:14:5
27+
|
28+
LL | stack!("overflow");
29+
| ^^^^^^^^^^^^^^^^^^
30+
|
31+
= note: this error originates in the macro `println` which comes from the expansion of the macro `stack` (in Nightly builds, run with -Z macro-backtrace for more info)
32+
help: you might be missing a string literal to format with
33+
|
34+
LL | println!("{}", stack!($overflow));
35+
| +++++
36+
37+
error: aborting due to 2 previous errors
38+

0 commit comments

Comments
 (0)