perpetually increasing indentation in nested macro

Đang mở
#7,269 2 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
72/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
rust
Lĩnh vực
tooling

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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)
Ngôn ngữ chính
Rust
Star
7.1k
Fork
1.2k
Merge trung bình
1 ngày 4 giờ
Pull request đã merge (30 ngày)
20

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của rust-lang/rustfmt

Tất cả issue của rust-lang/rustfmt

Issue tương tự

Thêm issue về Rust

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.