-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Add unnecessary_reserve
lint
#10157
Add unnecessary_reserve
lint
#10157
Conversation
r? @Manishearth (rustbot has picked a reviewer for you, use r? to override) |
r? @flip1995 since you were reviewing the previous one |
☔ The latest upstream changes (presumably #10164) made this pull request unmergeable. Please resolve the merge conflicts. |
Ah, sorry,this is still WIP |
unnecessary_reserve
lintunnecessary_reserve
lint
unnecessary_reserve
lintunnecessary_reserve
lint
☔ The latest upstream changes (presumably #10206) made this pull request unmergeable. Please resolve the merge conflicts. |
14ca695
to
3f17aa4
Compare
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.
Mostly style issues and one test seems to be missing.
README.md
Outdated
@@ -5,7 +5,7 @@ | |||
|
|||
A collection of lints to catch common mistakes and improve your [Rust](https://github.com/rust-lang/rust) code. | |||
|
|||
[There are over 550 lints included in this crate!](https://rust-lang.github.io/rust-clippy/master/index.html) | |||
[There are over 600 lints included in this crate!](https://rust-lang.github.io/rust-clippy/master/index.html) |
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.
🎉 🎉 🎉 🎉 🎉
@@ -603,6 +603,7 @@ pub(crate) static LINTS: &[&crate::LintInfo] = &[ | |||
crate::unnamed_address::FN_ADDRESS_COMPARISONS_INFO, | |||
crate::unnamed_address::VTABLE_ADDRESS_COMPARISONS_INFO, | |||
crate::unnecessary_owned_empty_strings::UNNECESSARY_OWNED_EMPTY_STRINGS_INFO, | |||
crate::unnecessary_reserve::UNNECESSARY_RESERVE_INFO, |
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 this be
crate::unnecessary_reserve::UNNECESSARY_RESERVE_INFO, | |
crate::unnecessary_reserve::UNNECESSARY_RESERVE, |
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.
@flip1995 Thank you so much for your review. UNNECESSARY_RESERVE
is defined in clippy_lints/src/unnecessary_reserve.rs
as impl_lint_pass!(UnnecessaryReserve => [UNNECESSARY_RESERVE]);
which is a LintPass
and thought that need to declare as an another constants.
|
||
impl<'tcx> LateLintPass<'tcx> for UnnecessaryReserve { | ||
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &Expr<'tcx>) { | ||
if !self.msrv.meets(msrvs::CHECK_UNNECESSARY_RESERVE) { |
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.
Usually we name the MSRV constant after the feature. I don't know if this has a feature name. If not, I would call it EXTEND_IMPLICIT_RESERVE
or something along those lines.
{ | ||
read_found = true; | ||
} | ||
let _ = !read_found; |
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.
What does this do?
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.
Oh, trying to flip read_found
. I will refactor this
pub const VEC_RESERVE: [&str; 4] = ["alloc", "vec", "Vec", "reserve"]; | ||
pub const VEC_DEQUE_RESERVE: [&str; 5] = ["alloc", "collections", "vec_deque", "VecDeque", "reserve"]; |
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.
Those are a lot of paths added here. It may be worth opening a rust-lang/rust
PR adding diagnostic items for those.
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.
@flip1995 Thank you so much for your review and suggestion. I will fix these.
// do not lint | ||
vec.reserve(1); | ||
vec.extend([1]); |
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.
I think one test that is missing is something like
vec.reserve(array1.len());
vec.extend(array2);
This might be covered by this, but I'm not 100% sure.
This should not be linted. Doesn't make much sense to write something like this, but it should be an easy FP to avoid.
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.
Ok.
☔ The latest upstream changes (presumably #10028) made this pull request unmergeable. Please resolve the merge conflicts. |
☔ The latest upstream changes (presumably #10392) made this pull request unmergeable. Please resolve the merge conflicts. |
f8b338f
to
c8f604a
Compare
☔ The latest upstream changes (presumably #10415) made this pull request unmergeable. Please resolve the merge conflicts. |
Co-authored-by: Alex <[email protected]>
Co-authored-by: Alex <[email protected]>
Co-authored-by: Alex <[email protected]>
Co-authored-by: Alex <[email protected]>
Co-authored-by: Alex <[email protected]>
Co-authored-by: Alex <[email protected]>
☔ The latest upstream changes (presumably #10578) made this pull request unmergeable. Please resolve the merge conflicts. |
@chansuke I'm closing this for inactivity (don't worry, it isn't anyone's fault! Just that Philipp doesn't have time to review anymore ฅ^•ﻌ•^ฅ). Feel free to re-open this if you're still interested in developing in this branch. But I'd advice you to create a new branch and a new PR. If you are still interested in this and create another PR, write |
This PR has taken over from #9073.
Fixes #8982.
changelog: new lint: [
unnecessary_reserve
]#10157