rust/tests/target/issue_5730.rs
tdanniels b944a32e5c
Prevent ICE when formatting an empty-ish macro arm (#5833)
Fixes 5730

Previously rustfmt was attempting to slice a string with an invalid
range (`start > end`), leading to the ICE.

When formatting a macro transcriber snippet consisting of a lone
semicolon, the snippet was being formatted into the empty string,
leading the enclosing `fn main() {\n}` added by `format_code_block` to
be formatted into `fn main() {}`. However, rustfmt was assuming that the
enclosing function string's length had been left unchanged. This was
leading to an invalid range being constructed when attempting to trim
off the enclosing function.

The fix is to just clamp the range's start to be less than or equal
to the range's end, since if `end < start` there's nothing to iterate
over anyway.
2023-07-18 20:48:57 -05:00

4 lines
41 B
Rust

macro_rules! statement {
() => {};
}