rustfmt icon indicating copy to clipboard operation
rustfmt copied to clipboard

Comment affects whether `return expr` fmts to `return expr;`

Open workingjubilee opened this issue 1 year ago • 2 comments

adding a comment here caused an unrelated diff in a semicolon formatting:

                     ArgValue::Lit(other) => {
+                        // FIXME: add a ui test for this
                         return Err(syn::Error::new(
                             other.span(),
                             "expected boolean, path, or string literal",
-                        ))
+                        ));
                     }

at least it doesn't depend much on the exact position of the comment, just whether it sees one?

             e => {
                 return Err(syn::Error::new(
+                    // FIXME: add a UI test for this
                     input.span(),
                     format!("Invalid option `{e}` inside `{ident} {input}`"),
-                ))
+                ));
            }

This sort of thing should not matter.

workingjubilee avatar Apr 19 '24 20:04 workingjubilee

@workingjubilee If you could take this diff and create a snippet that someone can direclty run rustfmt on to reproduce the issue that would be very helpful. Also, what version of rustfmt are you using, and are you using any configurations?

ytmimi avatar Apr 19 '24 21:04 ytmimi

https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=1b08120b0a4c44013840a6cbd24e9fa2

fn main() {
match x {
                         ArgValue::Lit(other) => {
                        // FIXME: add a ui test for this
                         return Err(syn::Error::new(
                             other.span(),
                             "expected boolean, path, or string literal",
                        ))
                     }
                     }
}

the presence/absence of the comma in the initial input influences the output. I believe there's something intentional here but I don't recall the specifics

calebcartwright avatar May 04 '24 23:05 calebcartwright