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.
New lint [
manual_try_fold
] #11012New 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
New lint [
manual_try_fold
] #11012Changes from all commits
354172a
24039ca
04b0857
fbb3f75
cb5d7e3
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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.
IDK, if
perf
is too strict, if the lint already has a know problem. Or do you mean withdoesn't take into account whether a function
the implementation ofTry
?If not, I think we should do some tests on more creates or start in pedantic first
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.
The "known problem" isn't really an issue, imo. The known problem is referring to something like
(pseudocode)
This code is not really possible with
try_fold
.But something like
(pseudocode again)
Can be changed to
try_fold
just fine, as it does nothing in theNone
case.There are very few cases where that's the desired behavior, as it doesn't change the outcome at all. You can short-circuit there and it changes nothing. Unless the programmer explicitly handles the
None
case, doing something with it, it's just a performance gainThere 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.
I also agree that, if this behaviour is well-documented (as I think it is, as it appears in the
std
documentation and in the lint's documentation) it doesn't really represent an issue.Also, I don't think I've ever seen a
fold
that handles aNone
case, but I'll make a Github regex search to confirm how many times does this happenThere 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.
Yeah, I'm just a more cautious when it comes to warn-by-default lints. I would really like nightly lints at some point, but first I finally want to stabilize lint reasons.
I believe it should be fine :)
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.
@Centri3
In that specific case, sure. But sometimes
fold
is used for things that are fallible, but you don't want it to short-circuit.Example:
This code initializes with an error of "KeyNotFoundError", and replaces it with an error of "VerificationError" after a subkey has been tried unsuccessfully, but still tries all of the subkeys before returning an error. If there's a successful result it short-circuits, but in the
Ok
case rather than the error case. So the suggestion to usetry_fold
would never work.This might be rare enough to not be worth worrying about - I'm not suggesting that the lint should be reverted necessarily. But the
try_fold
suggestion was misleading, and I'm going to need to mark the lint ignored or rewrite the code.