Skip to content

[ICE]: rustfmt panic on "macro_rules !" span on nightly #6985

Closed

Description

@tninesling

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

  1. Author a macro, but put a space between macro_rules and the following !
  2. 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

Activity

  1. added
    C-bugCategory: this is a bug; use also I-* labels for specific bug kinds, e.g. I-non-idempotency or I-ICE
    I-ICEIssue: Internal Compiler Error (ICE) reported by rustfmt
    on Jul 27, 2026
  2. added
    needs-triageThis issue or PR needs triaging to determine its status. Remove label once sufficiently triaged.
    on Jul 27, 2026
  3. added
    A-macrosArea: macros (procedural macros, macro_rules! macros, etc.)
    S-has-mcveStatus: a Minimal Complete and Verifiable Example has been found for this issue
    on Jul 27, 2026
  4. removed
    needs-triageThis issue or PR needs triaging to determine its status. Remove label once sufficiently triaged.
    on Jul 28, 2026
  5. marked "Bad span" compiler panic #6997 as a duplicate of this issue on Jul 29, 2026
  6. royb3 commented on Aug 3, 2026

    @royb3

    @ytmimi since the fix was merged a while ago. Shouldn't it work again on the nightly builds?

  7. ytmimi commented on Aug 3, 2026

    @ytmimi
    Contributor

    We need to sync rust-lang/rustfmt with rust-lang/rust before the change goes out on nightly

  8. robertbastian commented on Aug 10, 2026

    @robertbastian

    The bug seems to have been released in the Aug 7 nightly, but the fix wasn't. How come the fix didn't make it in?

  9. ytmimi commented on Aug 10, 2026

    @ytmimi
    Contributor

    @robertbastian see my last comment. We haven't synced rust-lang/rustfmt back up with rust-lang/rust yet. That needs to happen before this fix goes out on nightly.

  10. robertbastian commented on Aug 17, 2026

    @robertbastian

    Is there a timeline for when this will happen?

  11. royb3 commented on Aug 17, 2026

    @royb3

    Is there a timeline for when this will happen?

    Seems to have happened 8h ago. https://github.com/rust-lang/rust/tree/main/src/tools/rustfmt

  12. robertbastian commented on Aug 19, 2026

    @robertbastian

    The failure still happens on nightly, and seems to have made it into beta now.

  13. Manishearth commented on Aug 19, 2026

    @Manishearth
    Member

    @rust-lang/release This fix should be backported into beta ASAP.

    Seems to have happened 8h ago. https://github.com/rust-lang/rust/tree/main/src/tools/rustfmt

    I don't think that's a sync.

  14. Manishearth commented on Aug 19, 2026

    @Manishearth
    Member

    Manual sync of just one PR: rust-lang/rust#161370

  15. Mark-Simulacrum commented on Aug 19, 2026

    @Mark-Simulacrum
    Member

    This fix should be backported into beta ASAP.

    From local testing, it looks like this bug is in Rust 1.99+ today, so the backport needs to land on rust-lang/rust beta in the next ~5 weeks.

  16. added 4 commits that reference this issue on Aug 20, 2026
  17. added a commit that references this issue on Aug 21, 2026
  18. added a commit that references this issue on Aug 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-macrosArea: macros (procedural macros, macro_rules! macros, etc.)C-bugCategory: this is a bug; use also I-* labels for specific bug kinds, e.g. I-non-idempotency or I-ICEI-ICEIssue: Internal Compiler Error (ICE) reported by rustfmtS-has-mcveStatus: a Minimal Complete and Verifiable Example has been found for this issue

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions