Skip to content

Commit eaf63d6

Browse files
committed
Unify names of lint entry functions in loops to 'check'
1 parent 845a3a0 commit eaf63d6

19 files changed

+37
-37
lines changed

clippy_lints/src/loops/empty_loop.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::utils::{is_in_panic_handler, is_no_std_crate, span_lint_and_help};
44
use rustc_hir::{Block, Expr};
55
use rustc_lint::LateContext;
66

7-
pub(super) fn check_empty_loop(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, loop_block: &'tcx Block<'_>) {
7+
pub(super) fn check(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, loop_block: &'tcx Block<'_>) {
88
if loop_block.stmts.is_empty() && loop_block.expr.is_none() && !is_in_panic_handler(cx, expr) {
99
let msg = "empty `loop {}` wastes CPU cycles";
1010
let help = if is_no_std_crate(cx.tcx.hir().krate()) {

clippy_lints/src/loops/explicit_counter_loop.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use rustc_lint::LateContext;
1111
// To trigger the EXPLICIT_COUNTER_LOOP lint, a variable must be
1212
// incremented exactly once in the loop body, and initialized to zero
1313
// at the start of the loop.
14-
pub(super) fn check_for_loop_explicit_counter<'tcx>(
14+
pub(super) fn check<'tcx>(
1515
cx: &LateContext<'tcx>,
1616
pat: &'tcx Pat<'_>,
1717
arg: &'tcx Expr<'_>,

clippy_lints/src/loops/explicit_into_iter_loop.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use rustc_errors::Applicability;
44
use rustc_hir::Expr;
55
use rustc_lint::LateContext;
66

7-
pub(super) fn check_explicit_into_iter_loop(cx: &LateContext<'_>, method_args: &'hir [Expr<'hir>], arg: &Expr<'_>) {
7+
pub(super) fn check(cx: &LateContext<'_>, method_args: &'hir [Expr<'hir>], arg: &Expr<'_>) {
88
let mut applicability = Applicability::MachineApplicable;
99
let object = snippet_with_applicability(cx, method_args[0].span, "_", &mut applicability);
1010
span_lint_and_sugg(

clippy_lints/src/loops/explicit_iter_loop.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use rustc_errors::Applicability;
44
use rustc_hir::Expr;
55
use rustc_lint::LateContext;
66

7-
pub(super) fn lint_iter_method(cx: &LateContext<'_>, args: &[Expr<'_>], arg: &Expr<'_>, method_name: &str) {
7+
pub(super) fn check(cx: &LateContext<'_>, args: &[Expr<'_>], arg: &Expr<'_>, method_name: &str) {
88
let mut applicability = Applicability::MachineApplicable;
99
let object = snippet_with_applicability(cx, args[0].span, "_", &mut applicability);
1010
let muta = if method_name == "iter_mut" { "mut " } else { "" };

clippy_lints/src/loops/for_kv_map.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use rustc_lint::LateContext;
66
use rustc_middle::ty;
77

88
/// Checks for the `FOR_KV_MAP` lint.
9-
pub(super) fn check_for_loop_over_map_kv<'tcx>(
9+
pub(super) fn check<'tcx>(
1010
cx: &LateContext<'tcx>,
1111
pat: &'tcx Pat<'_>,
1212
arg: &'tcx Expr<'_>,

clippy_lints/src/loops/for_loops_over_fallibles.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use rustc_lint::LateContext;
55
use rustc_span::symbol::sym;
66

77
/// Checks for `for` loops over `Option`s and `Result`s.
8-
pub(super) fn check_arg_type(cx: &LateContext<'_>, pat: &Pat<'_>, arg: &Expr<'_>) {
8+
pub(super) fn check(cx: &LateContext<'_>, pat: &Pat<'_>, arg: &Expr<'_>) {
99
let ty = cx.typeck_results().expr_ty(arg);
1010
if is_type_diagnostic_item(cx, ty, sym::option_type) {
1111
span_lint_and_help(

clippy_lints/src/loops/iter_next_loop.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use crate::utils::span_lint;
33
use rustc_hir::Expr;
44
use rustc_lint::LateContext;
55

6-
pub(super) fn lint(cx: &LateContext<'_>, expr: &Expr<'_>) {
6+
pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>) {
77
span_lint(
88
cx,
99
ITER_NEXT_LOOP,

clippy_lints/src/loops/manual_flatten.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use rustc_span::source_map::Span;
99

1010
/// Check for unnecessary `if let` usage in a for loop where only the `Some` or `Ok` variant of the
1111
/// iterator element is used.
12-
pub(super) fn check_manual_flatten<'tcx>(
12+
pub(super) fn check<'tcx>(
1313
cx: &LateContext<'tcx>,
1414
pat: &'tcx Pat<'_>,
1515
arg: &'tcx Expr<'_>,

clippy_lints/src/loops/manual_memcpy.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use std::iter::Iterator;
1515

1616
/// Checks for for loops that sequentially copy items from one slice-like
1717
/// object to another.
18-
pub(super) fn detect_manual_memcpy<'tcx>(
18+
pub(super) fn check<'tcx>(
1919
cx: &LateContext<'tcx>,
2020
pat: &'tcx Pat<'_>,
2121
arg: &'tcx Expr<'_>,

clippy_lints/src/loops/mod.rs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -559,24 +559,24 @@ impl<'tcx> LateLintPass<'tcx> for Loops {
559559
}
560560

561561
// check for never_loop
562-
never_loop::check_never_loop(cx, expr);
562+
never_loop::check(cx, expr);
563563

564564
// check for `loop { if let {} else break }` that could be `while let`
565565
// (also matches an explicit "match" instead of "if let")
566566
// (even if the "match" or "if let" is used for declaration)
567567
if let ExprKind::Loop(ref block, _, LoopSource::Loop, _) = expr.kind {
568568
// also check for empty `loop {}` statements, skipping those in #[panic_handler]
569-
empty_loop::check_empty_loop(cx, expr, block);
570-
while_let_loop::check_while_let_loop(cx, expr, block);
569+
empty_loop::check(cx, expr, block);
570+
while_let_loop::check(cx, expr, block);
571571
}
572572

573-
while_let_on_iterator::check_while_let_on_iterator(cx, expr);
573+
while_let_on_iterator::check(cx, expr);
574574

575575
if let Some((cond, body)) = higher::while_loop(&expr) {
576-
while_immutable_condition::check_infinite_loop(cx, cond, body);
576+
while_immutable_condition::check(cx, cond, body);
577577
}
578578

579-
needless_collect::check_needless_collect(expr, cx);
579+
needless_collect::check(expr, cx);
580580
}
581581
}
582582

@@ -588,17 +588,17 @@ fn check_for_loop<'tcx>(
588588
expr: &'tcx Expr<'_>,
589589
span: Span,
590590
) {
591-
let is_manual_memcpy_triggered = manual_memcpy::detect_manual_memcpy(cx, pat, arg, body, expr);
591+
let is_manual_memcpy_triggered = manual_memcpy::check(cx, pat, arg, body, expr);
592592
if !is_manual_memcpy_triggered {
593-
needless_range_loop::check_for_loop_range(cx, pat, arg, body, expr);
594-
explicit_counter_loop::check_for_loop_explicit_counter(cx, pat, arg, body, expr);
593+
needless_range_loop::check(cx, pat, arg, body, expr);
594+
explicit_counter_loop::check(cx, pat, arg, body, expr);
595595
}
596596
check_for_loop_arg(cx, pat, arg, expr);
597-
for_kv_map::check_for_loop_over_map_kv(cx, pat, arg, body, expr);
598-
mut_range_bound::check_for_mut_range_bound(cx, arg, body);
599-
single_element_loop::check_for_single_element_loop(cx, pat, arg, body, expr);
600-
same_item_push::detect_same_item_push(cx, pat, arg, body, expr);
601-
manual_flatten::check_manual_flatten(cx, pat, arg, body, span);
597+
for_kv_map::check(cx, pat, arg, body, expr);
598+
mut_range_bound::check(cx, arg, body);
599+
single_element_loop::check(cx, pat, arg, body, expr);
600+
same_item_push::check(cx, pat, arg, body, expr);
601+
manual_flatten::check(cx, pat, arg, body, span);
602602
}
603603

604604
fn check_for_loop_arg(cx: &LateContext<'_>, pat: &Pat<'_>, arg: &Expr<'_>, expr: &Expr<'_>) {
@@ -610,13 +610,13 @@ fn check_for_loop_arg(cx: &LateContext<'_>, pat: &Pat<'_>, arg: &Expr<'_>, expr:
610610
// check for looping over x.iter() or x.iter_mut(), could use &x or &mut x
611611
if method_name == "iter" || method_name == "iter_mut" {
612612
if is_ref_iterable_type(cx, &args[0]) {
613-
explicit_iter_loop::lint_iter_method(cx, args, arg, method_name);
613+
explicit_iter_loop::check(cx, args, arg, method_name);
614614
}
615615
} else if method_name == "into_iter" && match_trait_method(cx, arg, &paths::INTO_ITERATOR) {
616616
let receiver_ty = cx.typeck_results().expr_ty(&args[0]);
617617
let receiver_ty_adjusted = cx.typeck_results().expr_ty_adjusted(&args[0]);
618618
if TyS::same_type(receiver_ty, receiver_ty_adjusted) {
619-
explicit_into_iter_loop::check_explicit_into_iter_loop(cx, args, arg);
619+
explicit_into_iter_loop::check(cx, args, arg);
620620
} else {
621621
let ref_receiver_ty = cx.tcx.mk_ref(
622622
cx.tcx.lifetimes.re_erased,
@@ -626,17 +626,17 @@ fn check_for_loop_arg(cx: &LateContext<'_>, pat: &Pat<'_>, arg: &Expr<'_>, expr:
626626
},
627627
);
628628
if TyS::same_type(receiver_ty_adjusted, ref_receiver_ty) {
629-
explicit_iter_loop::lint_iter_method(cx, args, arg, method_name)
629+
explicit_iter_loop::check(cx, args, arg, method_name)
630630
}
631631
}
632632
} else if method_name == "next" && match_trait_method(cx, arg, &paths::ITERATOR) {
633-
iter_next_loop::lint(cx, expr);
633+
iter_next_loop::check(cx, expr);
634634
next_loop_linted = true;
635635
}
636636
}
637637
}
638638
if !next_loop_linted {
639-
for_loops_over_fallibles::check_arg_type(cx, pat, arg);
639+
for_loops_over_fallibles::check(cx, pat, arg);
640640
}
641641
}
642642

clippy_lints/src/loops/mut_range_bound.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use rustc_middle::ty;
88
use rustc_span::source_map::Span;
99
use rustc_typeck::expr_use_visitor::{ConsumeMode, Delegate, ExprUseVisitor, PlaceBase, PlaceWithHirId};
1010

11-
pub(super) fn check_for_mut_range_bound(cx: &LateContext<'_>, arg: &Expr<'_>, body: &Expr<'_>) {
11+
pub(super) fn check(cx: &LateContext<'_>, arg: &Expr<'_>, body: &Expr<'_>) {
1212
if let Some(higher::Range {
1313
start: Some(start),
1414
end: Some(end),

clippy_lints/src/loops/needless_collect.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use rustc_span::symbol::{sym, Ident};
1515

1616
const NEEDLESS_COLLECT_MSG: &str = "avoid using `collect()` when not needed";
1717

18-
pub(super) fn check_needless_collect<'tcx>(expr: &'tcx Expr<'_>, cx: &LateContext<'tcx>) {
18+
pub(super) fn check<'tcx>(expr: &'tcx Expr<'_>, cx: &LateContext<'tcx>) {
1919
check_needless_collect_direct_usage(expr, cx);
2020
check_needless_collect_indirect_usage(expr, cx);
2121
}

clippy_lints/src/loops/needless_range_loop.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use std::mem;
2121
/// Checks for looping over a range and then indexing a sequence with it.
2222
/// The iteratee must be a range literal.
2323
#[allow(clippy::too_many_lines)]
24-
pub(super) fn check_for_loop_range<'tcx>(
24+
pub(super) fn check<'tcx>(
2525
cx: &LateContext<'tcx>,
2626
pat: &'tcx Pat<'_>,
2727
arg: &'tcx Expr<'_>,

clippy_lints/src/loops/never_loop.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use rustc_hir::{Block, Expr, ExprKind, HirId, InlineAsmOperand, Stmt, StmtKind};
44
use rustc_lint::LateContext;
55
use std::iter::{once, Iterator};
66

7-
pub(super) fn check_never_loop(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
7+
pub(super) fn check(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
88
if let ExprKind::Loop(ref block, _, _, _) = expr.kind {
99
match never_loop_block(block, expr.hir_id) {
1010
NeverLoopResult::AlwaysBreak => span_lint(cx, NEVER_LOOP, expr.span, "this loop never actually loops"),

clippy_lints/src/loops/same_item_push.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use rustc_span::symbol::sym;
1010
use std::iter::Iterator;
1111

1212
/// Detects for loop pushing the same item into a Vec
13-
pub(super) fn detect_same_item_push<'tcx>(
13+
pub(super) fn check<'tcx>(
1414
cx: &LateContext<'tcx>,
1515
pat: &'tcx Pat<'_>,
1616
_: &'tcx Expr<'_>,

clippy_lints/src/loops/single_element_loop.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use rustc_errors::Applicability;
55
use rustc_hir::{BorrowKind, Expr, ExprKind, Pat, PatKind};
66
use rustc_lint::LateContext;
77

8-
pub(super) fn check_for_single_element_loop<'tcx>(
8+
pub(super) fn check<'tcx>(
99
cx: &LateContext<'tcx>,
1010
pat: &'tcx Pat<'_>,
1111
arg: &'tcx Expr<'_>,

clippy_lints/src/loops/while_immutable_condition.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use rustc_lint::LateContext;
1111
use rustc_middle::hir::map::Map;
1212
use std::iter::Iterator;
1313

14-
pub(super) fn check_infinite_loop<'tcx>(cx: &LateContext<'tcx>, cond: &'tcx Expr<'_>, expr: &'tcx Expr<'_>) {
14+
pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, cond: &'tcx Expr<'_>, expr: &'tcx Expr<'_>) {
1515
if constant(cx, cx.typeck_results(), cond).is_some() {
1616
// A pure constant condition (e.g., `while false`) is not linted.
1717
return;

clippy_lints/src/loops/while_let_loop.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use rustc_hir::{Block, Expr, ExprKind, MatchSource, StmtKind};
55
use rustc_lint::{LateContext, LintContext};
66
use rustc_middle::lint::in_external_macro;
77

8-
pub(super) fn check_while_let_loop(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, loop_block: &'tcx Block<'_>) {
8+
pub(super) fn check(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, loop_block: &'tcx Block<'_>) {
99
// extract the expression from the first statement (if any) in a block
1010
let inner_stmt_expr = extract_expr_from_first_stmt(loop_block);
1111
// or extract the first expression (if any) from the block

clippy_lints/src/loops/while_let_on_iterator.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use rustc_middle::hir::map::Map;
1414

1515
use rustc_span::symbol::sym;
1616

17-
pub(super) fn check_while_let_on_iterator(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
17+
pub(super) fn check(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
1818
if let ExprKind::Match(ref match_expr, ref arms, MatchSource::WhileLetDesugar) = expr.kind {
1919
let pat = &arms[0].pat.kind;
2020
if let (

0 commit comments

Comments
 (0)