-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
rustfmt emits non-compiling code by removing tokens from function-like macro invocations #7021
Copy link
Copy link
Closed
rust-lang/rust
#160937Labels
A-macrosArea: macros (procedural macros, macro_rules! macros, etc.)Area: macros (procedural macros, macro_rules! macros, etc.)A-parserArea: parserArea: parserC-bugCategory: this is a bug; use also I-* labels for specific bug kinds, e.g. I-non-idempotency or I-ICECategory: this is a bug; use also I-* labels for specific bug kinds, e.g. I-non-idempotency or I-ICEP-highHigh priorityHigh priorityS-has-bisectionStatus: a bisection has been found for this issueStatus: a bisection has been found for this issueregression-from-stable-to-nightlyRegression from stable to nightly.Regression from stable to nightly.
Description
Activity
Metadata
Metadata
Assignees
Labels
A-macrosArea: macros (procedural macros, macro_rules! macros, etc.)Area: macros (procedural macros, macro_rules! macros, etc.)A-parserArea: parserArea: parserC-bugCategory: this is a bug; use also I-* labels for specific bug kinds, e.g. I-non-idempotency or I-ICECategory: this is a bug; use also I-* labels for specific bug kinds, e.g. I-non-idempotency or I-ICEP-highHigh priorityHigh priorityS-has-bisectionStatus: a bisection has been found for this issueStatus: a bisection has been found for this issueregression-from-stable-to-nightlyRegression from stable to nightly.Regression from stable to nightly.
Summary
Rustfmt strips the parameter names out of macro invocations whose arguments happen to look like function calls. The resulting code does not compile despite
rustfmtreturning 0.I tried to format this code:
Expected behavior
I expected to see this happen: the invocations are left as written.
Actual behavior
Instead, this happened: the parameter name is dropped (
cargo +nightly fmtdoes this, whilecargo fmtdoes not).The result does not compile, since the token stream no longer matches the macro's matcher:
No additional configuration is required to reproduce this. Both
rustfmt +nightly --edition 2024 src/main.rsandcargo +nightly fmtresult in this change.Meta
Version it worked on
It most recently worked on the following versions:
rustfmt 1.9.0-stable (8bab26f4f6 2026-07-14)rustfmt 1.10.0-nightly (771916f902 2026-08-08)Version with regression
rustfmt +nightly --version:rustc +nightly --version --verbose:@rustbot modify labels: +regression-from-stable-to-nightly -regression-untriaged