Skip to content

Commit 2229a08

Browse files
nahuakangY-Nak
authored andcommitted
Clean up: Rename some files to be consistent with lint names; import lints to each file
1 parent ecebfe0 commit 2229a08

11 files changed

+35
-26
lines changed

clippy_lints/src/loops/explicit_counter_loop.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
use super::{get_span_of_entire_for_loop, make_iterator_snippet, IncrementVisitor, InitializeVisitor};
1+
use super::{
2+
get_span_of_entire_for_loop, make_iterator_snippet, IncrementVisitor, InitializeVisitor, EXPLICIT_COUNTER_LOOP,
3+
};
24
use crate::utils::{get_enclosing_block, is_integer_const, snippet_with_applicability, span_lint_and_sugg};
35
use if_chain::if_chain;
46
use rustc_errors::Applicability;
@@ -37,7 +39,7 @@ pub(super) fn check_for_loop_explicit_counter<'tcx>(
3739

3840
span_lint_and_sugg(
3941
cx,
40-
super::EXPLICIT_COUNTER_LOOP,
42+
EXPLICIT_COUNTER_LOOP,
4143
for_span.with_hi(arg.span.hi()),
4244
&format!("the variable `{}` is used as a loop counter", name),
4345
"consider using",

clippy_lints/src/loops/for_loop_over_map_kv.rs renamed to clippy_lints/src/loops/for_kv_map.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use super::FOR_KV_MAP;
12
use crate::utils::visitors::LocalUsedVisitor;
23
use crate::utils::{is_type_diagnostic_item, match_type, multispan_sugg, paths, snippet, span_lint_and_then, sugg};
34
use rustc_hir::{BorrowKind, Expr, ExprKind, Mutability, Pat, PatKind};
@@ -37,7 +38,7 @@ pub(super) fn check_for_loop_over_map_kv<'tcx>(
3738
if is_type_diagnostic_item(cx, ty, sym!(hashmap_type)) || match_type(cx, ty, &paths::BTREEMAP) {
3839
span_lint_and_then(
3940
cx,
40-
super::FOR_KV_MAP,
41+
FOR_KV_MAP,
4142
expr.span,
4243
&format!("you seem to want to iterate on a map's {}s", kind),
4344
|diag| {

clippy_lints/src/loops/manual_flatten.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use super::utils::make_iterator_snippet;
2+
use super::MANUAL_FLATTEN;
23
use crate::utils::{is_ok_ctor, is_some_ctor, path_to_local_id, span_lint_and_then};
34
use if_chain::if_chain;
45
use rustc_errors::Applicability;
@@ -55,7 +56,7 @@ pub(super) fn check_manual_flatten<'tcx>(
5556

5657
span_lint_and_then(
5758
cx,
58-
super::MANUAL_FLATTEN,
59+
MANUAL_FLATTEN,
5960
span,
6061
&msg,
6162
|diag| {

clippy_lints/src/loops/manual_memcpy.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use super::{get_span_of_entire_for_loop, IncrementVisitor, InitializeVisitor};
1+
use super::{get_span_of_entire_for_loop, IncrementVisitor, InitializeVisitor, MANUAL_MEMCPY};
22
use crate::utils::sugg::Sugg;
33
use crate::utils::{
44
get_enclosing_block, higher, is_type_diagnostic_item, path_to_local, snippet, span_lint_and_sugg, sugg,
@@ -84,7 +84,7 @@ pub(super) fn detect_manual_memcpy<'tcx>(
8484
if let Some(big_sugg) = big_sugg {
8585
span_lint_and_sugg(
8686
cx,
87-
super::MANUAL_MEMCPY,
87+
MANUAL_MEMCPY,
8888
get_span_of_entire_for_loop(expr),
8989
"it looks like you're manually copying between slices",
9090
"try replacing the loop by",

clippy_lints/src/loops/mod.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,19 @@ mod empty_loop;
22
mod explicit_counter_loop;
33
mod explicit_into_iter_loop;
44
mod explicit_iter_loop;
5-
mod for_loop_over_map_kv;
6-
mod for_loop_range;
5+
mod for_kv_map;
76
mod for_loops_over_fallibles;
8-
mod for_mut_range_bound;
9-
mod for_single_element_loop;
10-
mod infinite_loop;
117
mod iter_next_loop;
128
mod manual_flatten;
139
mod manual_memcpy;
10+
mod mut_range_bound;
1411
mod needless_collect;
12+
mod needless_range_loop;
1513
mod never_loop;
1614
mod same_item_push;
15+
mod single_element_loop;
1716
mod utils;
17+
mod while_immutable_condition;
1818
mod while_let_loop;
1919
mod while_let_on_iterator;
2020

@@ -573,7 +573,7 @@ impl<'tcx> LateLintPass<'tcx> for Loops {
573573
while_let_on_iterator::check_while_let_on_iterator(cx, expr);
574574

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

579579
needless_collect::check_needless_collect(expr, cx);
@@ -590,13 +590,13 @@ fn check_for_loop<'tcx>(
590590
) {
591591
let is_manual_memcpy_triggered = manual_memcpy::detect_manual_memcpy(cx, pat, arg, body, expr);
592592
if !is_manual_memcpy_triggered {
593-
for_loop_range::check_for_loop_range(cx, pat, arg, body, expr);
593+
needless_range_loop::check_for_loop_range(cx, pat, arg, body, expr);
594594
explicit_counter_loop::check_for_loop_explicit_counter(cx, pat, arg, body, expr);
595595
}
596596
check_for_loop_arg(cx, pat, arg, expr);
597-
for_loop_over_map_kv::check_for_loop_over_map_kv(cx, pat, arg, body, expr);
598-
for_mut_range_bound::check_for_mut_range_bound(cx, arg, body);
599-
for_single_element_loop::check_for_single_element_loop(cx, pat, arg, body, 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);
600600
same_item_push::detect_same_item_push(cx, pat, arg, body, expr);
601601
manual_flatten::check_manual_flatten(cx, pat, arg, body, span);
602602
}

clippy_lints/src/loops/for_mut_range_bound.rs renamed to clippy_lints/src/loops/mut_range_bound.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use super::MUT_RANGE_BOUND;
12
use crate::utils::{higher, path_to_local, span_lint};
23
use if_chain::if_chain;
34
use rustc_hir::{BindingAnnotation, Expr, HirId, Node, PatKind};
@@ -27,7 +28,7 @@ fn mut_warn_with_span(cx: &LateContext<'_>, span: Option<Span>) {
2728
if let Some(sp) = span {
2829
span_lint(
2930
cx,
30-
super::MUT_RANGE_BOUND,
31+
MUT_RANGE_BOUND,
3132
sp,
3233
"attempt to mutate range bound within loop; note that the range of the loop is unchanged",
3334
);

clippy_lints/src/loops/needless_collect.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use super::NEEDLESS_COLLECT;
12
use crate::utils::sugg::Sugg;
23
use crate::utils::{
34
is_type_diagnostic_item, match_trait_method, match_type, path_to_local_id, paths, snippet, span_lint_and_sugg,
@@ -35,7 +36,7 @@ fn check_needless_collect_direct_usage<'tcx>(expr: &'tcx Expr<'_>, cx: &LateCont
3536
let span = shorten_needless_collect_span(expr);
3637
span_lint_and_sugg(
3738
cx,
38-
super::NEEDLESS_COLLECT,
39+
NEEDLESS_COLLECT,
3940
span,
4041
NEEDLESS_COLLECT_MSG,
4142
"replace with",
@@ -47,7 +48,7 @@ fn check_needless_collect_direct_usage<'tcx>(expr: &'tcx Expr<'_>, cx: &LateCont
4748
let span = shorten_needless_collect_span(expr);
4849
span_lint_and_sugg(
4950
cx,
50-
super::NEEDLESS_COLLECT,
51+
NEEDLESS_COLLECT,
5152
span,
5253
NEEDLESS_COLLECT_MSG,
5354
"replace with",
@@ -60,7 +61,7 @@ fn check_needless_collect_direct_usage<'tcx>(expr: &'tcx Expr<'_>, cx: &LateCont
6061
let span = shorten_needless_collect_span(expr);
6162
span_lint_and_then(
6263
cx,
63-
super::NEEDLESS_COLLECT,
64+
NEEDLESS_COLLECT,
6465
span,
6566
NEEDLESS_COLLECT_MSG,
6667
|diag| {

clippy_lints/src/loops/for_loop_range.rs renamed to clippy_lints/src/loops/needless_range_loop.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use super::NEEDLESS_RANGE_LOOP;
12
use crate::utils::visitors::LocalUsedVisitor;
23
use crate::utils::{
34
contains_name, has_iter_method, higher, is_integer_const, match_trait_method, multispan_sugg, path_to_local_id,
@@ -142,7 +143,7 @@ pub(super) fn check_for_loop_range<'tcx>(
142143
if visitor.nonindex {
143144
span_lint_and_then(
144145
cx,
145-
super::NEEDLESS_RANGE_LOOP,
146+
NEEDLESS_RANGE_LOOP,
146147
expr.span,
147148
&format!("the loop variable `{}` is used to index `{}`", ident.name, indexed),
148149
|diag| {
@@ -168,7 +169,7 @@ pub(super) fn check_for_loop_range<'tcx>(
168169

169170
span_lint_and_then(
170171
cx,
171-
super::NEEDLESS_RANGE_LOOP,
172+
NEEDLESS_RANGE_LOOP,
172173
expr.span,
173174
&format!("the loop variable `{}` is only used to index `{}`", ident.name, indexed),
174175
|diag| {

clippy_lints/src/loops/same_item_push.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use super::SAME_ITEM_PUSH;
12
use crate::utils::{implements_trait, is_type_diagnostic_item, snippet_with_macro_callsite, span_lint_and_help};
23
use if_chain::if_chain;
34
use rustc_hir::def::{DefKind, Res};
@@ -22,7 +23,7 @@ pub(super) fn detect_same_item_push<'tcx>(
2223

2324
span_lint_and_help(
2425
cx,
25-
super::SAME_ITEM_PUSH,
26+
SAME_ITEM_PUSH,
2627
vec.span,
2728
"it looks like the same item is being pushed into this Vec",
2829
None,

clippy_lints/src/loops/for_single_element_loop.rs renamed to clippy_lints/src/loops/single_element_loop.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use super::get_span_of_entire_for_loop;
1+
use super::{get_span_of_entire_for_loop, SINGLE_ELEMENT_LOOP};
22
use crate::utils::{indent_of, single_segment_path, snippet, span_lint_and_sugg};
33
use if_chain::if_chain;
44
use rustc_errors::Applicability;
@@ -30,7 +30,7 @@ pub(super) fn check_for_single_element_loop<'tcx>(
3030

3131
span_lint_and_sugg(
3232
cx,
33-
super::SINGLE_ELEMENT_LOOP,
33+
SINGLE_ELEMENT_LOOP,
3434
for_span,
3535
"for loop over a single element",
3636
"try",

clippy_lints/src/loops/infinite_loop.rs renamed to clippy_lints/src/loops/while_immutable_condition.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use super::WHILE_IMMUTABLE_CONDITION;
12
use crate::consts::constant;
23
use crate::utils::span_lint_and_then;
34
use crate::utils::usage::mutated_variables;
@@ -43,7 +44,7 @@ pub(super) fn check_infinite_loop<'tcx>(cx: &LateContext<'tcx>, cond: &'tcx Expr
4344
if no_cond_variable_mutated && !mutable_static_in_cond {
4445
span_lint_and_then(
4546
cx,
46-
super::WHILE_IMMUTABLE_CONDITION,
47+
WHILE_IMMUTABLE_CONDITION,
4748
cond.span,
4849
"variables in the condition are not mutated in the loop body",
4950
|diag| {

0 commit comments

Comments
 (0)