Skip to content

Commit 53bf773

Browse files
tnineslingytmimi
andauthored
fix: prevent panic when whitespace separates macro_rules and ! (6990)
Co-authored-by: Yacin Tmimi <yacintmimi@gmail.com>
1 parent 8ddb21c commit 53bf773

3 files changed

Lines changed: 42 additions & 1 deletion

File tree

‎src/macros.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ pub(crate) fn rewrite_macro_def(
431431
};
432432

433433
let mut header = if def.macro_rules {
434-
let pos = context.snippet_provider.span_after(span, "macro_rules!");
434+
let pos = context.snippet_provider.span_after(span, "!");
435435
vec![HeaderPart::new("macro_rules!", span.with_hi(pos))]
436436
} else {
437437
let macro_lo = context.snippet_provider.span_before(span, "macro");

‎tests/source/issue-6985.rs‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
macro_rules ! say_hello {
2+
() => {
3+
println!("Hello!")
4+
};
5+
}
6+
7+
macro_rules /* comment */ ! say_goodbye {
8+
() => {
9+
println!("Goodbye!")
10+
};
11+
}
12+
13+
macro_rules // comment
14+
! do_nothing {
15+
() => {};
16+
}
17+
18+
fn main() {
19+
say_hello!();
20+
say_goodbye!()
21+
}

‎tests/target/issue-6985.rs‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
macro_rules! say_hello {
2+
() => {
3+
println!("Hello!")
4+
};
5+
}
6+
7+
macro_rules! say_goodbye {
8+
() => {
9+
println!("Goodbye!")
10+
};
11+
}
12+
13+
macro_rules! do_nothing {
14+
() => {};
15+
}
16+
17+
fn main() {
18+
say_hello!();
19+
say_goodbye!()
20+
}

0 commit comments

Comments
 (0)