Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rustfmt incompatibility: possibly missing a comma here #3244

Closed
Dushistov opened this issue Sep 30, 2018 · 3 comments
Closed

rustfmt incompatibility: possibly missing a comma here #3244

Dushistov opened this issue Sep 30, 2018 · 3 comments

Comments

@Dushistov
Copy link

pub fn f(a: i16, b: f64) -> [f64; 3] {
    const C: f64 = 100.;
    [
        b,
        -b,
        match a {
            0x17 => 1.,
            0x18 => 2.,
            _ => 3.,
        } * C
            / 60.,
    ]
}

for such code clippy (from rustup/stable | 0.0.212) clippy show error:

error: possibly missing a comma here
  --> src/lib.rs:10:14
   |
10 |         } * C
   |              ^
   |

the problem that this is default coding style from rustfmt that comes with rustup/stable compiler,
it is possible to fix if reformat code like this * C / 60. , but rustfmt doesn't allow such coding style by default.

Not sure is this rustfmt issue or clippy, but clippy and rustfmt runs on CI,
and clippy fails.

@mcarton
Copy link
Member

mcarton commented Sep 30, 2018

I would say rustfmt is the one that's wrong on this one. The style it proposes it really ugly.
Alternatively, I'd suggest you use a variable for the match, as I don't think using match as an expression like this will ever look really nice.

@topecongiro
Copy link
Contributor

I think that there is an error on both clippy and rustfmt. rustfmt should either put * C on its own line or put * C / 60., on a single line, and clippy should not error on this.

bors bot added a commit that referenced this issue Nov 7, 2018
3407: Fix `possible_missing_comma` false positives r=oli-obk a=mikerite

`possible_missing_comma` should only trigger when the binary operator has
unary equivalent. Otherwise, it's not possible to insert a comma without
breaking compilation. The operators identified were `+`, `&`, `*` and `-`.

This fixes the specific examples given in issues #3244 and #3396
but doesn't address the conflict this lint has with the style of starting
a line with a binary operator.

Co-authored-by: Michael Wright <[email protected]>
@basil-cow
Copy link
Contributor

Fixed by this pr, can be closed @flip1995

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants