-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Add unnecessary_trailing_comma lint #16530
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
base: master
Are you sure you want to change the base?
Conversation
|
r? @Jarcho rustbot has assigned @Jarcho. Use Why was this reviewer chosen?The reviewer was selected based on:
|
This comment has been minimized.
This comment has been minimized.
46ad29b to
0f7b216
Compare
This comment has been minimized.
This comment has been minimized.
0f7b216 to
f3f0517
Compare
|
Lintcheck changes for d6d1b45
This comment will be updated if you push new changes |
f3f0517 to
f180a19
Compare
|
Some changes occurred in clippy_lints/src/doc cc @notriddle |
clippy_lints/src/format_args.rs
Outdated
| let sm = self.cx.sess().source_map(); | ||
| let span = self.macro_call.span.source_callsite(); | ||
| if !sm.is_multiline(span) | ||
| && let span = sm.span_extend_to_prev_char_before(span.shrink_to_hi(), ')', false) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This means println!["hi",], which is allowed, won't lint.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thx, great catch, totally forgot!!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thx @notriddle , fixed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This still doesn't work right in all cases. This test case gives an incorrect "correction":
println!["Foo(,)", ]; //~ unnecessary_trailing_commaThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@notriddle thx for catching all the edge cases! It took me a bit longer than anticipated. Seem to work now with all the new test cases
f180a19 to
c8541cc
Compare
This comment has been minimized.
This comment has been minimized.
|
The |
|
@samueltardieu this lint is essentially the missing piece for a single line macro calls that |
…g#16533) This noop PR makes the new comma-removing lint PR less noisy, allowing it focus only on the new functionality See rust-lang#16530 changelog: none
ccd5535 to
1f35186
Compare
This comment has been minimized.
This comment has been minimized.
…n, r=mati865 style: remove unneeded trailing commas Make format-like macro calls look similar to what `cargo fmt` does automatically - remove trailing commas. When removing a comma, I also inlined some variables for consistency and clarity. I'm working on a [clippy lint](rust-lang/rust-clippy#16530) to make this process automatic.
…n, r=mati865 style: remove unneeded trailing commas Make format-like macro calls look similar to what `cargo fmt` does automatically - remove trailing commas. When removing a comma, I also inlined some variables for consistency and clarity. I'm working on a [clippy lint](rust-lang/rust-clippy#16530) to make this process automatic.
…n, r=mati865 style: remove unneeded trailing commas Make format-like macro calls look similar to what `cargo fmt` does automatically - remove trailing commas. When removing a comma, I also inlined some variables for consistency and clarity. I'm working on a [clippy lint](rust-lang/rust-clippy#16530) to make this process automatic.
…n, r=mati865 style: remove unneeded trailing commas Make format-like macro calls look similar to what `cargo fmt` does automatically - remove trailing commas. When removing a comma, I also inlined some variables for consistency and clarity. I'm working on a [clippy lint](rust-lang/rust-clippy#16530) to make this process automatic.
…n, r=mati865 style: remove unneeded trailing commas Make format-like macro calls look similar to what `cargo fmt` does automatically - remove trailing commas. When removing a comma, I also inlined some variables for consistency and clarity. I'm working on a [clippy lint](rust-lang/rust-clippy#16530) to make this process automatic.
…n, r=mati865 style: remove unneeded trailing commas Make format-like macro calls look similar to what `cargo fmt` does automatically - remove trailing commas. When removing a comma, I also inlined some variables for consistency and clarity. I'm working on a [clippy lint](rust-lang/rust-clippy#16530) to make this process automatic.
…n, r=mati865 style: remove unneeded trailing commas Make format-like macro calls look similar to what `cargo fmt` does automatically - remove trailing commas. When removing a comma, I also inlined some variables for consistency and clarity. I'm working on a [clippy lint](rust-lang/rust-clippy#16530) to make this process automatic.
Suggest removing an unnecessary trailing comma before the closing parenthesis in single-line format-like macro invocations (e.g. println!, format!, write!). The lint currently only runs on format-like macros because it relies on format-argument parsing; arbitrary user macros are not supported to avoid incorrect suggestions. - Lint is in the `style` group (allow-by-default) - Single-line only: multi-line macro invocations are not linted - Machine-applicable fix: removes the trailing comma
1f35186 to
d6d1b45
Compare
|
This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
Rollup merge of #152372 - nyurik:clippy-rustc_trait_selection, r=mati865 style: remove unneeded trailing commas Make format-like macro calls look similar to what `cargo fmt` does automatically - remove trailing commas. When removing a comma, I also inlined some variables for consistency and clarity. I'm working on a [clippy lint](rust-lang/rust-clippy#16530) to make this process automatic.
This matches
cargo fmtbehavior but forformat!(...)-style macro calls.To make this PR easier to review, it moves all linting of the clippy code to #16533
Suggest removing an unnecessary trailing comma before the closing parenthesis in single-line format-like macro invocations (e.g. println!, format!, write!). The lint currently only runs on format-like macros because it relies on format-argument parsing; arbitrary user macros are not supported to avoid incorrect suggestions.
stylegroup (allow-by-default)Closes #13965
changelog: [
unnecessary_trailing_comma]: new lint to remove trailing commas in a single-line format macro usage