rust-lang / rustfmt

Format Rust code
https://rust-lang.github.io/rustfmt/
Apache License 2.0
5.99k stars 882 forks source link

rustfmt 1.4.12 deployed with Rust 1.43.0 changed macro brace formatting #4538

Closed YaLTeR closed 3 years ago

YaLTeR commented 3 years ago

Describe the bug

Noticed today when I got a PR to vapoursynth-rs and the CI broke.

┌ (master) ~/s/r/vapoursynth-rs
└─ rustup run 1.42.0 cargo fmt -- --check
┌ (master) ~/s/r/vapoursynth-rs
└─ rustup run 1.43.0 cargo fmt -- --check
Diff in /home/yalter/source/rs/vapoursynth-rs/vapoursynth/src/api.rs at line 35:

 // Macros for implementing repetitive functions.
 macro_rules! prop_get_something {
-    ($name:ident, $func:ident, $rv:ty) => (
+    ($name:ident, $func:ident, $rv:ty) => {
         #[inline]
         pub(crate) unsafe fn $name(
             self,
Diff in /home/yalter/source/rs/vapoursynth-rs/vapoursynth/src/api.rs at line 46:
         ) -> $rv {
             (self.handle.as_ref().$func)(map, key, index, error)
         }
-    )
+    };
 }

 macro_rules! prop_set_something {
Diff in /home/yalter/source/rs/vapoursynth-rs/vapoursynth/src/api.rs at line 53:
-    ($name:ident, $func:ident, $type:ty) => (
+    ($name:ident, $func:ident, $type:ty) => {
         #[inline]
         pub(crate) unsafe fn $name(
             self,
Diff in /home/yalter/source/rs/vapoursynth-rs/vapoursynth/src/api.rs at line 61:
         ) -> i32 {
             (self.handle.as_ref().$func)(map, key, value, append as i32)
         }
-    )
+    };
 }

 /// ID of a unique, registered VapourSynth message handler.

The code: https://github.com/YaLTeR/vapoursynth-rs/blob/f05e4a3e10ccc4d9a21b27203e3fe5a4a907c2a9/vapoursynth/src/api.rs#L37-L65

Expected behavior

No change as this is still rustfmt 1, it fits within line length, it compiles, and no unstable options were used.

Meta

calebcartwright commented 3 years ago

rustfmt v1.4.11 was actually not formatting those macro defs whatsoever because it was failing to do so, so it was just leaving your original snippet in place. To see that a bit more obviously, you can try using this heavily misformatted representation of the provided macro and you'll see rustfmt v1.4.11 leaves it as-is.

macro_rules!                    

              prop_get_something                       

      {
($name:ident, $func:ident, $rv:ty) => (
        #[inline]
                        pub(crate) unsafe fn $name(
self,
                        map: &ffi::VSMap,
            key: *const c_char,
            index: i32,
            error: &mut i32,
        )       ->          $rv {
            (self.handle.as_ref().$func)(map, key, index, error)
        }
                                        )
}

The reason why you see the formatting change with v1.4.12 is because that's the first version of rustfmt that is able to successfully apply the formatting rules. There were a ton of upstream rustc changes and rustfmt improvements incorporated between 1.4.11 and 1.4.12, and one or more of those resolved an existing problem that existed in rustfmt v1.4.11 and earlier versions.

Closing this accordingly

YaLTeR commented 3 years ago

Ah, I see, thanks.