Skip to content

feat(lint): impl lint about use first() instead of get(0) #8882

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

Merged
merged 4 commits into from
May 25, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
refactor: get the required variables with MethodCall
  • Loading branch information
kyoto7250 committed May 25, 2022
commit d0f93c12a2a6f0d693507ff6325fed62720e616b
7 changes: 2 additions & 5 deletions clippy_lints/src/get_first.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,11 @@ declare_lint_pass!(GetFirst => [GET_FIRST]);
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;
if let hir::ExprKind::MethodCall(_, [struct_calling_on, method_arg], _) = &expr.kind;
if let Some(expr_def_id) = cx.typeck_results().type_dependent_def_id(expr.hir_id);
if match_def_path(cx, expr_def_id, &paths::SLICE_GET) && expr_args.len() == 2;
if match_def_path(cx, expr_def_id, &paths::SLICE_GET);

if let Some(struct_calling_on) = expr_args.get(0);
if let Some(_) = is_slice_of_primitives(cx, struct_calling_on);

if let Some(method_arg) = expr_args.get(1);
if let hir::ExprKind::Lit(Spanned { node: LitKind::Int(0, _), .. }) = method_arg.kind;

then {
Expand Down