Rename new lints to iter_on_empty_collections and iter_on_single_items

This commit is contained in:
Sosthène Guédon 2022-07-30 13:39:55 +02:00
parent b247594a39
commit af4885c0cd
11 changed files with 35 additions and 33 deletions

View file

@ -312,11 +312,11 @@ store.register_lints(&[
methods::ITERATOR_STEP_BY_ZERO,
methods::ITER_CLONED_COLLECT,
methods::ITER_COUNT,
methods::ITER_EMPTY,
methods::ITER_NEXT_SLICE,
methods::ITER_NTH,
methods::ITER_NTH_ZERO,
methods::ITER_ONCE,
methods::ITER_ON_EMPTY_COLLECTIONS,
methods::ITER_ON_SINGLE_ITEMS,
methods::ITER_OVEREAGER_CLONED,
methods::ITER_SKIP_NEXT,
methods::ITER_WITH_DRAIN,

View file

@ -14,8 +14,8 @@ store.register_group(true, "clippy::nursery", Some("clippy_nursery"), vec![
LintId::of(index_refutable_slice::INDEX_REFUTABLE_SLICE),
LintId::of(let_if_seq::USELESS_LET_IF_SEQ),
LintId::of(matches::SIGNIFICANT_DROP_IN_SCRUTINEE),
LintId::of(methods::ITER_EMPTY),
LintId::of(methods::ITER_ONCE),
LintId::of(methods::ITER_ON_EMPTY_COLLECTIONS),
LintId::of(methods::ITER_ON_SINGLE_ITEMS),
LintId::of(methods::ITER_WITH_DRAIN),
LintId::of(missing_const_for_fn::MISSING_CONST_FOR_FN),
LintId::of(mutable_debug_assertion::DEBUG_ASSERT_WITH_MUT_CALL),

View file

@ -7,7 +7,7 @@ use rustc_hir::LangItem::{OptionNone, OptionSome};
use rustc_hir::{Expr, ExprKind, Node};
use rustc_lint::LateContext;
use super::{ITER_EMPTY, ITER_ONCE};
use super::{ITER_ON_EMPTY_COLLECTIONS, ITER_ON_SINGLE_ITEMS};
enum IterType {
Iter,
@ -82,7 +82,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'_>, method_name:
);
span_lint_and_sugg(
cx,
ITER_ONCE,
ITER_ON_SINGLE_ITEMS,
expr.span,
&format!("`{method_name}` call on a collection with only one item"),
"try",
@ -92,7 +92,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'_>, method_name:
} else {
span_lint_and_sugg(
cx,
ITER_EMPTY,
ITER_ON_EMPTY_COLLECTIONS,
expr.span,
&format!("`{method_name}` call on an empty collection"),
"try",

View file

@ -33,7 +33,7 @@ mod iter_count;
mod iter_next_slice;
mod iter_nth;
mod iter_nth_zero;
mod iter_once_empty;
mod iter_on_single_or_empty_collections;
mod iter_overeager_cloned;
mod iter_skip_next;
mod iter_with_drain;
@ -2331,7 +2331,7 @@ declare_clippy_lint! {
///
/// The type of the resulting iterator might become incompatible with its usage
#[clippy::version = "1.64.0"]
pub ITER_ONCE,
pub ITER_ON_SINGLE_ITEMS,
nursery,
"Iterator for array of length 1"
}
@ -2363,7 +2363,7 @@ declare_clippy_lint! {
///
/// The type of the resulting iterator might become incompatible with its usage
#[clippy::version = "1.64.0"]
pub ITER_EMPTY,
pub ITER_ON_EMPTY_COLLECTIONS,
nursery,
"Iterator for empty array"
}
@ -2470,8 +2470,8 @@ impl_lint_pass!(Methods => [
NEEDLESS_OPTION_TAKE,
NO_EFFECT_REPLACE,
OBFUSCATED_IF_ELSE,
ITER_ONCE,
ITER_EMPTY
ITER_ON_SINGLE_ITEMS,
ITER_ON_EMPTY_COLLECTIONS
]);
/// Extracts a method call name, args, and `Span` of the method name.
@ -2774,7 +2774,9 @@ impl Methods {
("is_digit", [radix]) => is_digit_ascii_radix::check(cx, expr, recv, radix, self.msrv),
("is_none", []) => check_is_some_is_none(cx, expr, recv, false),
("is_some", []) => check_is_some_is_none(cx, expr, recv, true),
("iter" | "iter_mut" | "into_iter", []) => iter_once_empty::check(cx, expr, name, recv),
("iter" | "iter_mut" | "into_iter", []) => {
iter_on_single_or_empty_collections::check(cx, expr, name, recv);
},
("join", [join_arg]) => {
if let Some(("collect", _, span)) = method_call(recv) {
unnecessary_join::check(cx, expr, recv, join_arg, span);