Fix duration_suboptimal_units for small literals#16922
Conversation
|
r? @llogiq rustbot has assigned @llogiq. Use Why was this reviewer chosen?The reviewer was selected based on:
|
There was a problem hiding this comment.
Pull request overview
Updates duration_suboptimal_units to avoid linting on small integer literal values where the promoted (larger-unit) value would be <= 10, addressing the false positive described in #16532.
Changes:
- Adjusts lint logic to suppress suggestions for small integer literals while still linting expressions.
- Updates lint documentation/examples to avoid the new suppression edge cases.
- Expands UI tests (including
duration_constructorscoverage) to validate the new behavior and expected suggestions.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
clippy_lints/src/duration_suboptimal_units.rs |
Implements the <= 10 suppression rule for integer literals and updates lint docs/examples. |
tests/ui/duration_suboptimal_units.rs |
Adds UI coverage for small literals vs expressions and updates expected lint sites. |
tests/ui/duration_suboptimal_units.fixed |
Updates fixed-output expectations to match the new lint behavior. |
tests/ui/duration_suboptimal_units.stderr |
Updates stderr expectations for the new/shifted diagnostics. |
tests/ui/duration_suboptimal_units_days_weeks.rs |
Adds non-linting literal + linting expression cases under duration_constructors. |
tests/ui/duration_suboptimal_units_days_weeks.fixed |
Updates fixed-output expectations for the days/weeks test. |
tests/ui/duration_suboptimal_units_days_weeks.stderr |
Updates stderr expectations for the days/weeks test. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Reminder, once the PR becomes ready for a review, use |
|
@rustbot ready |
|
Could you please squash down the commits? I think it would also be nice to add @Hectonight and @veeceey as co-authors to the commit |
3c536bd to
a1ffdf3
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. |
Absolutely! It's squashed with all 3 of us on the commit now |
7112278 to
0f1bb4e
Compare
| @@ -1,13 +1,14 @@ | |||
| //@aux-build:proc_macros.rs | |||
| #![warn(clippy::duration_suboptimal_units)] | |||
| #![feature(duration_constructors)] | |||
There was a problem hiding this comment.
Ideally this file wouldn't contain any tests that require this feature. Could you please move all of those into the duration_suboptimal_units_days_weeks.rs instead?
0f1bb4e to
1668b6c
Compare
|
r? @ada4a Changed the changelog entry to fit the format a bit better. For posterity, here's how it used to look:
|
Co-authored-by: Hectonight <joshuaoring@yahoo.com> Co-authored-by: veeceey <varun_6april@hotmail.com>
1668b6c to
2a7ac1f
Compare
View all comments
fixes #16532
changelog: [
duration_suboptimal_units]: fix false positive for small integer literals whose promoted value would be at most 10.Combined #16565 and #16596