Hey Zhao, On Thu, 11 Jul 2024 at 07:05, Zhao Liu <zhao1....@intel.com> wrote: > > Hi Manos and all, > > On Tue, Jun 11, 2024 at 01:33:32PM +0300, Manos Pitsidianakis wrote: > > diff --git a/rust/rustfmt.toml b/rust/rustfmt.toml > > new file mode 100644 > > index 0000000000..ebecb99fe0 > > --- /dev/null > > +++ b/rust/rustfmt.toml > > @@ -0,0 +1,7 @@ > > +edition = "2021" > > +format_generated_files = false > > +format_code_in_doc_comments = true > > +format_strings = true > > +imports_granularity = "Crate" > > +group_imports = "StdExternalCrate" > > +wrap_comments = true > > > > I find it's stiil necessary to strictly limit the width of the lines by > "error_on_line_overflow = true" [1]. > > Currently rustfmt defaults the width limitation with "max_width = 100", > but it has bugs and doesn't always work. For example, the line of > rust/qemu-api/src/device_class.rs:108 comes to 157 characters and is > ignored by rustfmt, which doesn't even fit in one line of my screen! > > Of course I think it's feasible to manually review and fix similar cases, > but it's definitely better to have readily available tool that can help > us rigorously formatted... > > [1]: > https://github.com/rust-lang/rustfmt/blob/master/Configurations.md#error_on_line_overflow > > -Zhao
Thank you for pointing that out, I hadn't noticed it! The problem is that macro definitions are also macros and macros aren't formatted because they have to be expanded, IIUC. I agree that a hard error on an overflow is necessary for readable code. By the way, my usual go-to workaround for this bug is to format the macro body outside the macro_rules! { } scope, (rustfmt works even if the code does not compile) and then put it back in. Manos