NOT token (!) inside a macro call inside `macro_rules!` erroneously de-indented (non-idempotency)
Open
Nobody has claimed this yet.
A-macros
C-bug
- Dominant language
- Rust
- Stars
- 7k
- Forks
- 1.1k
- Avg merge
- 2d 13h
- Merged PRs (30d)
- 24
Description
Minimal reproducer:
mod ok {
mod ok {
const _: &'static str = stringify!(Foo: !Bar);
}
}
macro_rules! ok_2 {
() => {
const _: i32 = !1;
};
}
ok_2!();
macro_rules! fail_dedented {
() => {
const _: &'static str = stringify!(Foo: !Bar);
};
}
fail_dedented!();
macro_rules! fail_dedented_nonidempotent {
() => {
const _: () = assert!(stringify!(Foo: !Bar).len() > 0, concat!(stringify!(Foo: !Bar), "Lorem ipsum dolor sit amet, consectetur adipiscing elit"));
};
}
fail_dedented_nonidempotent!();
macro_rules! fail_dedented_nonidempotent_2 {
() => {
const _: () = assert!(stringify!(Foo: !Bar).len() > 0, concat!(stringify!(Foo: !Bar), "Lorem ipsum dolor sit amet, consectetur adipiscing elit"));
};
}
fail_dedented_nonidempotent_2!();
formats to
mod ok {
mod ok {
const _: &'static str = stringify!(Foo: !Bar);
}
}
macro_rules! ok_2 {
() => {
const _: i32 = !1;
};
}
ok_2!();
macro_rules! fail_dedented {
() => {
const _: &'static str = stringify!(Foo: !Bar);
};
}
fail_dedented!();
macro_rules! fail_dedented_nonidempotent {
() => {
const _: () = assert!(
stringify!(Foo: !Bar).len() > 0,
concat!(
stringify!(Foo: !Bar),
"Lorem ipsum dolor sit amet, consectetur adipiscing elit"
)
);
};
}
fail_dedented_nonidempotent!();
macro_rules! fail_dedented_nonidempotent_2 {
() => {
const _: () = assert!(
stringify!(Foo: !Bar).len() > 0,
concat!(
stringify!(Foo: !Bar),
"Lorem ipsum dolor sit amet, consectetur adipiscing elit"
)
);
};
}
fail_dedented_nonidempotent_2!();
formats to
mod ok {
mod ok {
const _: &'static str = stringify!(Foo: !Bar);
}
}
macro_rules! ok_2 {
() => {
const _: i32 = !1;
};
}
ok_2!();
macro_rules! fail_dedented {
() => {
const _: &'static str = stringify!(Foo: !Bar);
};
}
fail_dedented!();
macro_rules! fail_dedented_nonidempotent {
() => {
const _: () = assert!(
stringify!(Foo: !Bar).len() > 0,
concat!(
stringify!(Foo: !Bar),
"Lorem ipsum dolor sit amet, consectetur adipiscing elit"
)
);
};
}
fail_dedented_nonidempotent!();
macro_rules! fail_dedented_nonidempotent_2 {
() => {
const _: () = assert!(
stringify!(Foo: !Bar).len() > 0,
concat!(
stringify!(Foo: !Bar),
"Lorem ipsum dolor sit amet, consectetur adipiscing elit"
)
);
};
}
fail_dedented_nonidempotent_2!();
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by running rustfmt on the minimal reproducer in the issue and compare the first and second formatting passes. The fix is done when the macro body is not incorrectly de-indented and formatting the result again produces identical output.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100