Clean up: Rename some files to be consistent with lint names; import lints to each file

This commit is contained in:
nahuakang 2021-02-21 18:25:50 +01:00 committed by Yoshitomo Nakanishi
parent ecebfe0c9c
commit 2229a0839e
11 changed files with 35 additions and 26 deletions

View file

@ -1,4 +1,6 @@
use super::{get_span_of_entire_for_loop, make_iterator_snippet, IncrementVisitor, InitializeVisitor};
use super::{
get_span_of_entire_for_loop, make_iterator_snippet, IncrementVisitor, InitializeVisitor, EXPLICIT_COUNTER_LOOP,
};
use crate::utils::{get_enclosing_block, is_integer_const, snippet_with_applicability, span_lint_and_sugg};
use if_chain::if_chain;
use rustc_errors::Applicability;
@ -37,7 +39,7 @@ pub(super) fn check_for_loop_explicit_counter<'tcx>(
span_lint_and_sugg(
cx,
super::EXPLICIT_COUNTER_LOOP,
EXPLICIT_COUNTER_LOOP,
for_span.with_hi(arg.span.hi()),
&format!("the variable `{}` is used as a loop counter", name),
"consider using",

View file

@ -1,3 +1,4 @@
use super::FOR_KV_MAP;
use crate::utils::visitors::LocalUsedVisitor;
use crate::utils::{is_type_diagnostic_item, match_type, multispan_sugg, paths, snippet, span_lint_and_then, sugg};
use rustc_hir::{BorrowKind, Expr, ExprKind, Mutability, Pat, PatKind};
@ -37,7 +38,7 @@ pub(super) fn check_for_loop_over_map_kv<'tcx>(
if is_type_diagnostic_item(cx, ty, sym!(hashmap_type)) || match_type(cx, ty, &paths::BTREEMAP) {
span_lint_and_then(
cx,
super::FOR_KV_MAP,
FOR_KV_MAP,
expr.span,
&format!("you seem to want to iterate on a map's {}s", kind),
|diag| {

View file

@ -1,4 +1,5 @@
use super::utils::make_iterator_snippet;
use super::MANUAL_FLATTEN;
use crate::utils::{is_ok_ctor, is_some_ctor, path_to_local_id, span_lint_and_then};
use if_chain::if_chain;
use rustc_errors::Applicability;
@ -55,7 +56,7 @@ pub(super) fn check_manual_flatten<'tcx>(
span_lint_and_then(
cx,
super::MANUAL_FLATTEN,
MANUAL_FLATTEN,
span,
&msg,
|diag| {

View file

@ -1,4 +1,4 @@
use super::{get_span_of_entire_for_loop, IncrementVisitor, InitializeVisitor};
use super::{get_span_of_entire_for_loop, IncrementVisitor, InitializeVisitor, MANUAL_MEMCPY};
use crate::utils::sugg::Sugg;
use crate::utils::{
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>(
if let Some(big_sugg) = big_sugg {
span_lint_and_sugg(
cx,
super::MANUAL_MEMCPY,
MANUAL_MEMCPY,
get_span_of_entire_for_loop(expr),
"it looks like you're manually copying between slices",
"try replacing the loop by",

View file

@ -2,19 +2,19 @@ mod empty_loop;
mod explicit_counter_loop;
mod explicit_into_iter_loop;
mod explicit_iter_loop;
mod for_loop_over_map_kv;
mod for_loop_range;
mod for_kv_map;
mod for_loops_over_fallibles;
mod for_mut_range_bound;
mod for_single_element_loop;
mod infinite_loop;
mod iter_next_loop;
mod manual_flatten;
mod manual_memcpy;
mod mut_range_bound;
mod needless_collect;
mod needless_range_loop;
mod never_loop;
mod same_item_push;
mod single_element_loop;
mod utils;
mod while_immutable_condition;
mod while_let_loop;
mod while_let_on_iterator;
@ -573,7 +573,7 @@ impl<'tcx> LateLintPass<'tcx> for Loops {
while_let_on_iterator::check_while_let_on_iterator(cx, expr);
if let Some((cond, body)) = higher::while_loop(&expr) {
infinite_loop::check_infinite_loop(cx, cond, body);
while_immutable_condition::check_infinite_loop(cx, cond, body);
}
needless_collect::check_needless_collect(expr, cx);
@ -590,13 +590,13 @@ fn check_for_loop<'tcx>(
) {
let is_manual_memcpy_triggered = manual_memcpy::detect_manual_memcpy(cx, pat, arg, body, expr);
if !is_manual_memcpy_triggered {
for_loop_range::check_for_loop_range(cx, pat, arg, body, expr);
needless_range_loop::check_for_loop_range(cx, pat, arg, body, expr);
explicit_counter_loop::check_for_loop_explicit_counter(cx, pat, arg, body, expr);
}
check_for_loop_arg(cx, pat, arg, expr);
for_loop_over_map_kv::check_for_loop_over_map_kv(cx, pat, arg, body, expr);
for_mut_range_bound::check_for_mut_range_bound(cx, arg, body);
for_single_element_loop::check_for_single_element_loop(cx, pat, arg, body, expr);
for_kv_map::check_for_loop_over_map_kv(cx, pat, arg, body, expr);
mut_range_bound::check_for_mut_range_bound(cx, arg, body);
single_element_loop::check_for_single_element_loop(cx, pat, arg, body, expr);
same_item_push::detect_same_item_push(cx, pat, arg, body, expr);
manual_flatten::check_manual_flatten(cx, pat, arg, body, span);
}

View file

@ -1,3 +1,4 @@
use super::MUT_RANGE_BOUND;
use crate::utils::{higher, path_to_local, span_lint};
use if_chain::if_chain;
use rustc_hir::{BindingAnnotation, Expr, HirId, Node, PatKind};
@ -27,7 +28,7 @@ fn mut_warn_with_span(cx: &LateContext<'_>, span: Option<Span>) {
if let Some(sp) = span {
span_lint(
cx,
super::MUT_RANGE_BOUND,
MUT_RANGE_BOUND,
sp,
"attempt to mutate range bound within loop; note that the range of the loop is unchanged",
);

View file

@ -1,3 +1,4 @@
use super::NEEDLESS_COLLECT;
use crate::utils::sugg::Sugg;
use crate::utils::{
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
let span = shorten_needless_collect_span(expr);
span_lint_and_sugg(
cx,
super::NEEDLESS_COLLECT,
NEEDLESS_COLLECT,
span,
NEEDLESS_COLLECT_MSG,
"replace with",
@ -47,7 +48,7 @@ fn check_needless_collect_direct_usage<'tcx>(expr: &'tcx Expr<'_>, cx: &LateCont
let span = shorten_needless_collect_span(expr);
span_lint_and_sugg(
cx,
super::NEEDLESS_COLLECT,
NEEDLESS_COLLECT,
span,
NEEDLESS_COLLECT_MSG,
"replace with",
@ -60,7 +61,7 @@ fn check_needless_collect_direct_usage<'tcx>(expr: &'tcx Expr<'_>, cx: &LateCont
let span = shorten_needless_collect_span(expr);
span_lint_and_then(
cx,
super::NEEDLESS_COLLECT,
NEEDLESS_COLLECT,
span,
NEEDLESS_COLLECT_MSG,
|diag| {

View file

@ -1,3 +1,4 @@
use super::NEEDLESS_RANGE_LOOP;
use crate::utils::visitors::LocalUsedVisitor;
use crate::utils::{
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>(
if visitor.nonindex {
span_lint_and_then(
cx,
super::NEEDLESS_RANGE_LOOP,
NEEDLESS_RANGE_LOOP,
expr.span,
&format!("the loop variable `{}` is used to index `{}`", ident.name, indexed),
|diag| {
@ -168,7 +169,7 @@ pub(super) fn check_for_loop_range<'tcx>(
span_lint_and_then(
cx,
super::NEEDLESS_RANGE_LOOP,
NEEDLESS_RANGE_LOOP,
expr.span,
&format!("the loop variable `{}` is only used to index `{}`", ident.name, indexed),
|diag| {

View file

@ -1,3 +1,4 @@
use super::SAME_ITEM_PUSH;
use crate::utils::{implements_trait, is_type_diagnostic_item, snippet_with_macro_callsite, span_lint_and_help};
use if_chain::if_chain;
use rustc_hir::def::{DefKind, Res};
@ -22,7 +23,7 @@ pub(super) fn detect_same_item_push<'tcx>(
span_lint_and_help(
cx,
super::SAME_ITEM_PUSH,
SAME_ITEM_PUSH,
vec.span,
"it looks like the same item is being pushed into this Vec",
None,

View file

@ -1,4 +1,4 @@
use super::get_span_of_entire_for_loop;
use super::{get_span_of_entire_for_loop, SINGLE_ELEMENT_LOOP};
use crate::utils::{indent_of, single_segment_path, snippet, span_lint_and_sugg};
use if_chain::if_chain;
use rustc_errors::Applicability;
@ -30,7 +30,7 @@ pub(super) fn check_for_single_element_loop<'tcx>(
span_lint_and_sugg(
cx,
super::SINGLE_ELEMENT_LOOP,
SINGLE_ELEMENT_LOOP,
for_span,
"for loop over a single element",
"try",

View file

@ -1,3 +1,4 @@
use super::WHILE_IMMUTABLE_CONDITION;
use crate::consts::constant;
use crate::utils::span_lint_and_then;
use crate::utils::usage::mutated_variables;
@ -43,7 +44,7 @@ pub(super) fn check_infinite_loop<'tcx>(cx: &LateContext<'tcx>, cond: &'tcx Expr
if no_cond_variable_mutated && !mutable_static_in_cond {
span_lint_and_then(
cx,
super::WHILE_IMMUTABLE_CONDITION,
WHILE_IMMUTABLE_CONDITION,
cond.span,
"variables in the condition are not mutated in the loop body",
|diag| {