perpetually increasing indentation in nested macro

Aperta
#7,269 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
72/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
rust
Ambito
tooling

Direzione di ricerca

Start by reproducing the issue with the nested macro_rules! example in the issue body, using the supplied hard_tabs = true configuration; the report says it also occurs without that setting. Compare the output across repeated runs and trace how rustfmt formats nested declarative macros. Done means formatting the example repeatedly no longer increases indentation and preserves the expected layout.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

A-macros C-bug I-non-idempotency

Summary

Multiple executions keep adding more and more levels of indentation in a nested declarative macro.

I tried to format this code:

macro_rules! exclude {
	($x:ident, [$($y:ident),* $(,)?] $(,)?) => {
		macro_rules! exclude_inner {
			($x) => {};
			($z:ident) => { $z , };
		}
	};
}
Expected behavior

I expected to see this happen: the code is left as-is, since it's already formatted properly.

Actual behavior

Instead, this happened: the nested macro gets another level of indentation every time the formatter is ran.

First execution:

macro_rules! exclude {
	($x:ident, [$($y:ident),* $(,)?] $(,)?) => {
		macro_rules! exclude_inner {
					($x) => {};
					($z:ident) => { $z , };
				}
	};
}

Second execution:

macro_rules! exclude {
	($x:ident, [$($y:ident),* $(,)?] $(,)?) => {
		macro_rules! exclude_inner {
							($x) => {};
							($z:ident) => { $z , };
						}
	};
}

third:

macro_rules! exclude {
	($x:ident, [$($y:ident),* $(,)?] $(,)?) => {
		macro_rules! exclude_inner {
									($x) => {};
									($z:ident) => { $z , };
								}
	};
}

After many tries, this seems to be the maximum it'll go.

macro_rules! exclude {
	($x:ident, [$($y:ident),* $(,)?] $(,)?) => {
		macro_rules! exclude_inner {
																																																																							($x) => {};
																																																																							($z:ident) => { $z , };
																																																																						}
	};
}

Configuration

rustfmt configuration file (e.g. rustfmt.toml, if applicable):

hard_tabs = true

(but the bug happens without that too).

Reproduction Steps

No additional steps beyond running the formatter on the code provided earlier.

Meta

rustfmt --version:

rustfmt 1.9.0-stable (ac68faa20c 2026-05-25)

and

rustfmt --version:

rustfmt 1.10.0-nightly (67eda617e6 2026-09-10)
Lingua principale
Rust
Stelle
7.1k
Fork
1.2k
Merge medio
1g 4h
PR unite (30g)
20

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di rust-lang/rustfmt

Tutte le issue di rust-lang/rustfmt

Issue simili

Altre issue su Rust

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.