-
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
new lint: unnecessary_reserve
#14114
base: master
Are you sure you want to change the base?
new lint: unnecessary_reserve
#14114
Conversation
unnecessary_reserve
@samueltardieu Samuel, really appreciate your review and points! |
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.
Could you include a test (maybe I've missed it) where extend()
happens before reserve()
, to make sure the lint doesn't trigger?
vec.reserve(array1.len()); | ||
vec.extend(array2); | ||
|
||
// do not lint |
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.
Why not? Or it can be done in a later PR.
vec.reserve(1); | ||
vec.extend([1]); | ||
|
||
//// do lint |
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.
You should use error markers to check that the lint is correctly emitted (a comment starting with //~
).
} | ||
|
||
fn msrv_1_62() { | ||
#![clippy::msrv = "1.61"] |
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.
It is unusual to:
- apply an attribute from the inside of a function
- name a function
msrv_1_62
and apply it aclippy::msrv = "1.61"
attribute
Maybe call the function insufficient_msrv
and apply the attribute to it.
let array2: &[usize] = &[3, 4]; | ||
|
||
// do not lint - different arrays | ||
; |
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 ";" should be removed as well. When you find the reserve()
, you might want to look for the parent statement to get the span.
resurrection of #10157
fixes #8982
changelog: [
unnecessary_reserve
]: add new lint unnecessary_reserve