Hello,
I am a maintainer of apollo-rs, and we encountered a panic in the nightly formatter when a macro_rules definition has a space before the ! character. This does not panic on the latest stable version. I have attached the full ICE report from that repository at the bottom of this issue.
Code
macro_rules ! say_hello {
() => {
println!("Hello!")
};
}
fn main() {
say_hello!()
}
Configuration
rustfmt cli options used (if applicable):
$ cargo +nightly fmt -- --check
rustfmt configuration file (e.g. rustfmt.toml, if applicable):
None
Reproduction Steps
- Author a macro, but put a space between
macro_rules and the following !
- Format with the nightly formatter
Meta
rustfmt --version:
rustfmt 1.10.0-nightly (dc3f85158a 2026-07-26)
Error output
thread 'main' panicked at src/tools/rustfmt/src/source_map.rs:31:13:
bad span: `macro_rules!`: `macro_rules ! say_hello {
() => {
println!("Hello!")
};
}`
Backtrace
stack backtrace:
0: 0x10b4343c0 - <std[ee75d77504d5cc2c]::backtrace::Backtrace>::create
1: 0x1092edc6c - std[ee75d77504d5cc2c]::panicking::update_hook::<alloc[45a93d76fd929ce]::boxed::Box<rustc_driver_impl[58d2776b959ed623]::install_ice_hook::{closure#1}>>::{closure#0}
2: 0x10b448600 - std[ee75d77504d5cc2c]::panicking::panic_with_hook
3: 0x10b429998 - std[ee75d77504d5cc2c]::panicking::panic_handler::{closure#0}
4: 0x10b421818 - std[ee75d77504d5cc2c]::sys::backtrace::__rust_end_short_backtrace::<std[ee75d77504d5cc2c]::panicking::panic_handler::{closure#0}, !>
5: 0x10b42aec0 - __rustc[fc4642eee87af86]::rust_begin_unwind
6: 0x10b513154 - core[72355cdabd4545b3]::panicking::panic_fmt
7: 0x103019a9c - <rustfmt_nightly[c40fde2e22d7a0d5]::visitor::SnippetProvider as rustfmt_nightly[c40fde2e22d7a0d5]::source_map::SpanUtils>::span_after::{closure#0}
8: 0x102f7d0a0 - rustfmt_nightly[c40fde2e22d7a0d5]::macros::rewrite_macro_def
9: 0x102f177b4 - <rustfmt_nightly[c40fde2e22d7a0d5]::visitor::FmtVisitor>::visit_item
10: 0x102f50f14 - <rustfmt_nightly[c40fde2e22d7a0d5]::visitor::FmtVisitor>::visit_items_with_reordering
11: 0x102f1b840 - <rustfmt_nightly[c40fde2e22d7a0d5]::visitor::FmtVisitor>::walk_mod_items
12: 0x102ea7980 - <scoped_tls[c95850a21232a508]::ScopedKey<rustc_span[c94f91a8dd5c03e2]::SessionGlobals>>::with::<<rustfmt_nightly[c40fde2e22d7a0d5]::Session<std[ee75d77504d5cc2c]::io::stdio::Stdout>>::format_input_inner::{closure#0}, core[72355cdabd4545b3]::result::Result<rustfmt_nightly[c40fde2e22d7a0d5]::FormatReport, rustfmt_nightly[c40fde2e22d7a0d5]::ErrorKind>>
13: 0x102ea3db0 - rustfmt[a53a59d609b04279]::format_and_emit_report::<std[ee75d77504d5cc2c]::io::stdio::Stdout>
14: 0x102eb4e58 - rustfmt[a53a59d609b04279]::execute
15: 0x102eb1380 - rustfmt[a53a59d609b04279]::main
16: 0x102eafba4 - std[ee75d77504d5cc2c]::sys::backtrace::__rust_begin_short_backtrace::<fn(), ()>
17: 0x102eb01fc - std[ee75d77504d5cc2c]::rt::lang_start::<()>::{closure#0}
18: 0x10b446af8 - std[ee75d77504d5cc2c]::rt::lang_start_internal
19: 0x102ebd1e8 - _main
rustc-ice-2026-07-27T13_57_27-23413.txt
Hello,
I am a maintainer of apollo-rs, and we encountered a panic in the nightly formatter when a
macro_rulesdefinition has a space before the!character. This does not panic on the latest stable version. I have attached the full ICE report from that repository at the bottom of this issue.Code
Configuration
rustfmtcli options used (if applicable):rustfmtconfiguration file (e.g.rustfmt.toml, if applicable):None
Reproduction Steps
macro_rulesand the following!Meta
rustfmt --version:Error output
Backtrace
rustc-ice-2026-07-27T13_57_27-23413.txt