Adds the result_and_inner_method lint (suspicious, warn-by-default).#16879
Open
Souradip121 wants to merge 3 commits intorust-lang:masterfrom
Open
Adds the result_and_inner_method lint (suspicious, warn-by-default).#16879Souradip121 wants to merge 3 commits intorust-lang:masterfrom
result_and_inner_method lint (suspicious, warn-by-default).#16879Souradip121 wants to merge 3 commits intorust-lang:masterfrom
Conversation
Collaborator
|
rustbot has assigned @samueltardieu. Use Why was this reviewer chosen?The reviewer was selected based on:
|
Member
|
r? clippy |
Contributor
|
sorry, don't have the capacity right now r? clippy |
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.
Closes #16847
What the lint catches
Calling
.and()on aResult<T, E>when the inner typeThas an inherent method also namedand. This is a footgun:Result::anddiscards the firstOkvalue entirely, which is rarely the intent when the inner type has its ownandmethod.Conservative conditions (no false positives)
The lint is skipped when:
Result<T, E>Thas no inherent method namedand(e.g.Result<u8, E>does not lint)Result::and(a, b))Only inherent methods are checked, not trait methods, which keeps the scope tight and avoids surprising users who implement custom traits with an
andmethod on an unrelated type.changelog: [
result_and_inner_method]: new lint that warns whenResult::andis called and the innerOktype has an inherentandmethod, suggesting fully-qualified syntax to make the intent explicit.