rustfmt result are not reproducable with `indent_style = "Visual"`

Created on 1 Mar 2018  Â·  4Comments  Â·  Source: rust-lang/rustfmt

We want to start using rustfmt on the code base of librsvg. I've stumbled on a bug though where if you run rustfmt once it will change the files, but if run again it will reset them to the previous state. This seem to happen no matter which of those 2 states the code base sits. I am not sure how to describe it better.

This is sort of a blocker since the CI rustfmt test will always fail :(

Using rustfmt 0.3.8

➜ rustfmt -Vv 
0.3.8-nightly ( )

I've made a separate branch to test this.

Steps to reproduce:

  • git clone https://gitlab.gnome.org/alatiera/librsvg.git --branch rustfmt-visual-bug
  • Run cargo fmt --all
  • watch the diff
  • Run cargo fmt --all again
  • Files should be reverted to the same state as in the repo
  • Repeat endlessly
bug only-with-option

Most helpful comment

Nevermind it's still happening, I hadn't drunk coffee yet sorry!

All 4 comments

Fixed as of version 0.7.

Nevermind it's still happening, I hadn't drunk coffee yet sorry!

This is still happening on rustfmt 0.99.2-nightly (5c9a2b6 2018-08-07). We've updated the branch to account for rustfmt differences from when the issue was reported. The instructions are the same.

@alatiera also added a CI job that runs cargo fmt --check and cargo fmt twice to showcase the issue. Note, for example, this last diff:

Diff in /builds/alatiera/librsvg/rsvg_internals/src/structure.rs at line 238:
                 Attribute::X => self.x.set(parse("x", value, LengthDir::Horizontal, None)?),
                 Attribute::Y => self.y.set(parse("y", value, LengthDir::Vertical, None)?),

-                Attribute::Width => {
-                    self.w.set(parse("width",
-                                     value,
-                                     LengthDir::Horizontal,
-                                     Some(RsvgLength::check_nonnegative)).map(Some)?)
-                }
-                Attribute::Height => {
-                    self.h.set(parse("height",
-                                     value,
-                                     LengthDir::Vertical,
-                                     Some(RsvgLength::check_nonnegative)).map(Some)?)
-                }
+                Attribute::Width => self.w
+                                        .set(parse("width",
+                                               value,
+                                               LengthDir::Horizontal,
+                                               Some(RsvgLength::check_nonnegative)).map(Some)?),
+                Attribute::Height => self.h
+                                         .set(parse("height",
+                                                value,
+                                                LengthDir::Vertical,
+                                                Some(RsvgLength::check_nonnegative)).map(Some)?),

                 _ => (),
             }

which in the second run gets reverted back:

Diff in /builds/alatiera/librsvg/rsvg_internals/src/structure.rs at line 242:
                 Attribute::X => self.x.set(parse("x", value, LengthDir::Horizontal, None)?),
                 Attribute::Y => self.y.set(parse("y", value, LengthDir::Vertical, None)?),

-                Attribute::Width => self.w
-                                        .set(parse("width",
-                                               value,
-                                               LengthDir::Horizontal,
-                                               Some(RsvgLength::check_nonnegative)).map(Some)?),
-                Attribute::Height => self.h
-                                         .set(parse("height",
-                                                value,
-                                                LengthDir::Vertical,
-                                                Some(RsvgLength::check_nonnegative)).map(Some)?),
+                Attribute::Width => {
+                    self.w.set(parse("width",
+                                     value,
+                                     LengthDir::Horizontal,
+                                     Some(RsvgLength::check_nonnegative)).map(Some)?)
+                }
+                Attribute::Height => {
+                    self.h.set(parse("height",
+                                     value,
+                                     LengthDir::Vertical,
+                                     Some(RsvgLength::check_nonnegative)).map(Some)?)
+                }

                 _ => (),
             }

Found a short example: a cycle between

fn main() {
    match option {
        None => some_function(first_reasonably_long_argument,
                              second_reasonably_long_argument),
    }
}

and

fn main() {
    match option {
        None => {
            some_function(first_reasonably_long_argument,
                          second_reasonably_long_argument)
        }
    }
}
Was this page helpful?
0 / 5 - 0 ratings

Related issues

0x7CFE picture 0x7CFE  Â·  5Comments

thomaseizinger picture thomaseizinger  Â·  3Comments

tkilbourn picture tkilbourn  Â·  5Comments

fulara picture fulara  Â·  4Comments

BartMassey picture BartMassey  Â·  4Comments