-
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
feat(lint): impl lint about use first() instead of get(0) #8882
Conversation
r? @llogiq (rust-highfive has picked a reviewer for you, use r? to override) |
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 already looking quite good. I only have one small suggestion.
clippy_lints/src/get_first.rs
Outdated
impl<'tcx> LateLintPass<'tcx> for GetFirst { | ||
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>) { | ||
if_chain! { | ||
if let hir::ExprKind::MethodCall(_, expr_args, _) = &expr.kind; |
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.
Using
if let hir::ExprKind::MethodCall(_, expr_args, _) = &expr.kind; | |
if let hir::ExprKind::MethodCall(_, [struct_calling_on, method_arg], _) = &expr.kind; |
would make the expr_args.len() == 2
check and the expr_args.get(_)
checks obsolete.
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.
Fixed in this commit.
Thanks!
☔ The latest upstream changes (presumably #8880) made this pull request unmergeable. Please resolve the merge conflicts. |
I rebased to the latest master and committed your suggestion :) |
Thank you! @bors r+ |
📌 Commit d0f93c1 has been approved by |
☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test |
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
close #8851
This PR adds new lint about considering replacing .get(0) with .first().
Thank you in advance.
changelog: adds new lint [
get_first
] to consider replacing .get(0) with .first()