-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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: vec_resize_to_zero #5637
Conversation
☔ The latest upstream changes (presumably #5651) made this pull request unmergeable. Please resolve the merge conflicts. |
This looks good btw, just needs to be rebased and have a CI run that doesn't fall over. cc @flip1995 |
if let ExprKind::Lit(Spanned { node: LitKind::Int(0, _), .. }) = args[1].kind; | ||
if let ExprKind::Lit(Spanned { node: LitKind::Int(..), .. }) = args[2].kind; | ||
then { | ||
span_lint(cx, VEC_RESIZE_TO_ZERO, expr.span, "this empties the vector. It could be an argument inversion mistake. If not, call `clear()` instead."); |
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 would suggest to split up the message and suggestion:
span_lint(cx, VEC_RESIZE_TO_ZERO, expr.span, "this empties the vector. It could be an argument inversion mistake. If not, call `clear()` instead."); | |
span_lint_and_then( | |
cx, | |
VEC_RESIZE_TO_ZERO, | |
expr.span, | |
"emptying a vector with `resize`", | |
|db| { | |
db.help("the arguments may be inverted..."); | |
db.span_suggestion( | |
resize_span, | |
"...or you can use `clear` to empty the vector", | |
"clear()", | |
Applicability::MaybeIncorrect, | |
); | |
}, | |
); |
Note, that you also have to get the span of the method call as resize_span
for the suggestion to work.
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.
Suggestion added
fb6e6db
to
5faab87
Compare
Should this lint move to the |
I think having this in its own module is fine. The methods module is more about methods (chaining) in general, while this is more about arguments to a specific method. |
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.
Waiting on rustup
@bors r=yaahc,flip1995 |
📌 Commit 5faab87 has been approved by |
…ip1995 new lint: vec_resize_to_zero implements #5444 changelog: new lint vec_resize_to_zero
@bors retry (yeeting to rollup) |
Remove `dead_code` paths The following paths are `dead_code` and can be removed: ### `clippy_utils::paths::VEC_RESIZE` * Introduced when `vec_resize_to_zero` lint added in PR #5637 * No longer used after commit 8acc4d2 ### `clippy_utils::paths::SLICE_GET` * Introduced when `get_first` lint added in PR #8882 * No longer used after commit a8d80d5 ### `clippy_utils::paths::STR_BYTES` * Introduced when `bytes_count_to_len` lint added in PR #8711 * No longer used after commit ba6a459 When the lints were moved into the `Methods` lint pass, they switched from using paths to diagnostic items. However, the paths were never removed. This occurred in PR #8957. This relates to issue #5393 changelog: none
implements #5444
changelog: new lint vec_resize_to_zero