feat: add manual_max and manual_min lints#17206
Open
sylvestre wants to merge 1 commit into
Open
Conversation
Collaborator
|
r? @llogiq rustbot has assigned @llogiq. Use Why was this reviewer chosen?The reviewer was selected based on:
|
This comment has been minimized.
This comment has been minimized.
|
Lintcheck changes for 1dd053a
This comment will be updated if you push new changes |
72b7356 to
a39a158
Compare
This comment has been minimized.
This comment has been minimized.
|
|
This comment has been minimized.
This comment has been minimized.
Member
|
You'll have to guard this with a MSRV check (1.21). |
a39a158 to
38ea87c
Compare
Collaborator
|
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. |
This comment has been minimized.
This comment has been minimized.
Add two `complexity` lints that detect a single-sided clamp written as an
`if`/`else` (or a guarding `if`) and suggest `Ord::max` / `Ord::min`:
let _ = if a < b { b } else { a }; // -> a.max(b)
if cores < b { cores = b; } // -> cores = cores.max(b);
This is the sound, generalizable form of the manual clamp simplified by
hand in uutils/coreutils#12753 (`nproc`). Unlike `manual_clamp`, which
only fires when both a lower and an upper bound are applied, these catch
the common single-bound floor/ceiling case.
Restricted to `Ord` types so float `NaN` semantics are not changed, and
emitted as `MaybeIncorrect` since the branching form re-evaluates the
selected operand.
38ea87c to
1dd053a
Compare
Collaborator
|
Contributor
Author
|
@samueltardieu done, merci! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add two
complexitylints that detect a single-sided clamp written as anif/else(or a guardingif) and suggestOrd::max/Ord::min:This is the sound, generalizable form of the manual clamp simplified by hand in uutils/coreutils#12753 (
nproc). Unlikemanual_clamp, which only fires when both a lower and an upper bound are applied, these catch the common single-bound floor/ceiling case.Restricted to
Ordtypes so floatNaNsemantics are not changed, and emitted asMaybeIncorrectsince the branching form re-evaluates the selected operand.changelog: add
manual_maxandmanual_minlints