-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New lint: mem_replace_option_with_some
#14197
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
Conversation
6de91d5
to
8af4abd
Compare
Hits from lintcheck are legitimate. |
clippy_lints/src/mem_replace.rs
Outdated
@@ -238,6 +283,13 @@ impl<'tcx> LateLintPass<'tcx> for MemReplace { | |||
} else if self.msrv.meets(msrvs::MEM_TAKE) && is_expr_used_or_unified(cx.tcx, expr) { | |||
check_replace_with_default(cx, src, dest, expr.span); | |||
} | |||
// Check that second argument is `Option::Some` |
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.
Shouldn't that be part of the check method? To me as a reviewer, this splits the code and if I look at the check method in isolation, it's not clear what actually is checked.
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.
Totally. I have also reorganized the other checks so that they are more self-contained, in the first commit.
clippy_lints/src/mem_replace.rs
Outdated
/// | ||
/// ### Example | ||
/// ```no_run | ||
/// use std::mem; |
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 is only used once, so we can inline the std::
and remove the import to shorten the example.
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.
Done.
Make each lint be more self-contained, and trigger only the next lint when the previous one didn't already rewrite the expression.
538b71d
to
86796f2
Compare
86796f2
to
8daf0db
Compare
`mem::replace(opt, Some(v))` can be replaced by `opt.replace(v)`.
8daf0db
to
342ac8e
Compare
Needs a |
Resubmitted with reformatted comment as the only change. |
mem::replace(opt, Some(v))
can be replaced byopt.replace(v)
.Close #14195
changelog: [
mem_replace_option_with_some
]: new lint