From 2d4ff2daaf10f4d9815ecfe0a28d0db4b9c79743 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sosth=C3=A8ne=20Gu=C3=A9don?= Date: Sat, 30 Jul 2022 13:39:55 +0200 Subject: [PATCH] Rename new lints to iter_on_empty_collections and iter_on_single_items --- CHANGELOG.md | 6 +++--- clippy_lints/src/lib.register_lints.rs | 4 ++-- clippy_lints/src/lib.register_nursery.rs | 4 ++-- ...y.rs => iter_on_single_or_empty_collections.rs} | 6 +++--- clippy_lints/src/methods/mod.rs | 14 ++++++++------ ...empty.fixed => iter_on_empty_collections.fixed} | 2 +- ...{iter_empty.rs => iter_on_empty_collections.rs} | 2 +- ...pty.stderr => iter_on_empty_collections.stderr} | 14 +++++++------- ...{iter_once.fixed => iter_on_single_items.fixed} | 2 +- tests/ui/{iter_once.rs => iter_on_single_items.rs} | 2 +- ...ter_once.stderr => iter_on_single_items.stderr} | 14 +++++++------- 11 files changed, 36 insertions(+), 34 deletions(-) rename clippy_lints/src/methods/{iter_once_empty.rs => iter_on_single_or_empty_collections.rs} (95%) rename tests/ui/{iter_empty.fixed => iter_on_empty_collections.fixed} (97%) rename tests/ui/{iter_empty.rs => iter_on_empty_collections.rs} (97%) rename tests/ui/{iter_empty.stderr => iter_on_empty_collections.stderr} (76%) rename tests/ui/{iter_once.fixed => iter_on_single_items.fixed} (97%) rename tests/ui/{iter_once.rs => iter_on_single_items.rs} (97%) rename tests/ui/{iter_once.stderr => iter_on_single_items.stderr} (79%) diff --git a/CHANGELOG.md b/CHANGELOG.md index 03b270fad731..5ab3cbefa24a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3506,7 +3506,7 @@ Released 2018-09-13 [`debug_assert_with_mut_call`]: https://rust-lang.github.io/rust-clippy/master/index.html#debug_assert_with_mut_call [`decimal_literal_representation`]: https://rust-lang.github.io/rust-clippy/master/index.html#decimal_literal_representation [`declare_interior_mutable_const`]: https://rust-lang.github.io/rust-clippy/master/index.html#declare_interior_mutable_const -[`default_instead_of_iter_empty`]: https://rust-lang.github.io/rust-clippy/master/index.html#default_instead_of_iter_empty +[`default_instead_of_iter_on_empty_collections`]: https://rust-lang.github.io/rust-clippy/master/index.html#default_instead_of_iter_on_empty_collections [`default_numeric_fallback`]: https://rust-lang.github.io/rust-clippy/master/index.html#default_numeric_fallback [`default_trait_access`]: https://rust-lang.github.io/rust-clippy/master/index.html#default_trait_access [`default_union_representation`]: https://rust-lang.github.io/rust-clippy/master/index.html#default_union_representation @@ -3648,13 +3648,13 @@ Released 2018-09-13 [`items_after_statements`]: https://rust-lang.github.io/rust-clippy/master/index.html#items_after_statements [`iter_cloned_collect`]: https://rust-lang.github.io/rust-clippy/master/index.html#iter_cloned_collect [`iter_count`]: https://rust-lang.github.io/rust-clippy/master/index.html#iter_count -[`iter_empty`]: https://rust-lang.github.io/rust-clippy/master/index.html#iter_empty +[`iter_on_empty_collections`]: https://rust-lang.github.io/rust-clippy/master/index.html#iter_on_empty_collections [`iter_next_loop`]: https://rust-lang.github.io/rust-clippy/master/index.html#iter_next_loop [`iter_next_slice`]: https://rust-lang.github.io/rust-clippy/master/index.html#iter_next_slice [`iter_not_returning_iterator`]: https://rust-lang.github.io/rust-clippy/master/index.html#iter_not_returning_iterator [`iter_nth`]: https://rust-lang.github.io/rust-clippy/master/index.html#iter_nth [`iter_nth_zero`]: https://rust-lang.github.io/rust-clippy/master/index.html#iter_nth_zero -[`iter_once`]: https://rust-lang.github.io/rust-clippy/master/index.html#iter_once +[`iter_on_single_items`]: https://rust-lang.github.io/rust-clippy/master/index.html#iter_on_single_items [`iter_overeager_cloned`]: https://rust-lang.github.io/rust-clippy/master/index.html#iter_overeager_cloned [`iter_skip_next`]: https://rust-lang.github.io/rust-clippy/master/index.html#iter_skip_next [`iter_with_drain`]: https://rust-lang.github.io/rust-clippy/master/index.html#iter_with_drain diff --git a/clippy_lints/src/lib.register_lints.rs b/clippy_lints/src/lib.register_lints.rs index 6b7608b0420f..d4b86f932043 100644 --- a/clippy_lints/src/lib.register_lints.rs +++ b/clippy_lints/src/lib.register_lints.rs @@ -310,11 +310,11 @@ store.register_lints(&[ methods::ITERATOR_STEP_BY_ZERO, methods::ITER_CLONED_COLLECT, methods::ITER_COUNT, - methods::ITER_EMPTY, + methods::ITER_ON_EMPTY_COLLECTIONS, methods::ITER_NEXT_SLICE, methods::ITER_NTH, methods::ITER_NTH_ZERO, - methods::ITER_ONCE, + methods::ITER_ON_SINGLE_ITEMS, methods::ITER_OVEREAGER_CLONED, methods::ITER_SKIP_NEXT, methods::ITER_WITH_DRAIN, diff --git a/clippy_lints/src/lib.register_nursery.rs b/clippy_lints/src/lib.register_nursery.rs index ea7d65c15568..b9394e681e96 100644 --- a/clippy_lints/src/lib.register_nursery.rs +++ b/clippy_lints/src/lib.register_nursery.rs @@ -13,8 +13,8 @@ store.register_group(true, "clippy::nursery", Some("clippy_nursery"), vec![ LintId::of(future_not_send::FUTURE_NOT_SEND), LintId::of(index_refutable_slice::INDEX_REFUTABLE_SLICE), LintId::of(let_if_seq::USELESS_LET_IF_SEQ), - 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), diff --git a/clippy_lints/src/methods/iter_once_empty.rs b/clippy_lints/src/methods/iter_on_single_or_empty_collections.rs similarity index 95% rename from clippy_lints/src/methods/iter_once_empty.rs rename to clippy_lints/src/methods/iter_on_single_or_empty_collections.rs index 96b1484528c7..cea7b0d82ff3 100644 --- a/clippy_lints/src/methods/iter_once_empty.rs +++ b/clippy_lints/src/methods/iter_on_single_or_empty_collections.rs @@ -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", diff --git a/clippy_lints/src/methods/mod.rs b/clippy_lints/src/methods/mod.rs index 7612400eeb33..0d42cf256b6d 100644 --- a/clippy_lints/src/methods/mod.rs +++ b/clippy_lints/src/methods/mod.rs @@ -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; @@ -2320,7 +2320,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" } @@ -2352,7 +2352,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" } @@ -2459,8 +2459,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. @@ -2763,7 +2763,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); diff --git a/tests/ui/iter_empty.fixed b/tests/ui/iter_on_empty_collections.fixed similarity index 97% rename from tests/ui/iter_empty.fixed rename to tests/ui/iter_on_empty_collections.fixed index ad1e106d2b1c..bd9b07aefbfb 100644 --- a/tests/ui/iter_empty.fixed +++ b/tests/ui/iter_on_empty_collections.fixed @@ -1,5 +1,5 @@ // run-rustfix -#![warn(clippy::iter_empty)] +#![warn(clippy::iter_on_empty_collections)] #![allow(clippy::iter_next_slice, clippy::redundant_clone)] fn array() { diff --git a/tests/ui/iter_empty.rs b/tests/ui/iter_on_empty_collections.rs similarity index 97% rename from tests/ui/iter_empty.rs rename to tests/ui/iter_on_empty_collections.rs index 625149b5da51..e15ba94bd465 100644 --- a/tests/ui/iter_empty.rs +++ b/tests/ui/iter_on_empty_collections.rs @@ -1,5 +1,5 @@ // run-rustfix -#![warn(clippy::iter_empty)] +#![warn(clippy::iter_on_empty_collections)] #![allow(clippy::iter_next_slice, clippy::redundant_clone)] fn array() { diff --git a/tests/ui/iter_empty.stderr b/tests/ui/iter_on_empty_collections.stderr similarity index 76% rename from tests/ui/iter_empty.stderr rename to tests/ui/iter_on_empty_collections.stderr index 40c08e6f82bd..cbd611769569 100644 --- a/tests/ui/iter_empty.stderr +++ b/tests/ui/iter_on_empty_collections.stderr @@ -1,37 +1,37 @@ error: `into_iter` call on an empty collection - --> $DIR/iter_empty.rs:6:16 + --> $DIR/iter_on_empty_collections.rs:6:16 | LL | assert_eq!([].into_iter().next(), Option::::None); | ^^^^^^^^^^^^^^ help: try: `std::iter::empty()` | - = note: `-D clippy::iter-empty` implied by `-D warnings` + = note: `-D clippy::iter-on-empty-collections` implied by `-D warnings` error: `iter_mut` call on an empty collection - --> $DIR/iter_empty.rs:7:16 + --> $DIR/iter_on_empty_collections.rs:7:16 | LL | assert_eq!([].iter_mut().next(), Option::<&mut i32>::None); | ^^^^^^^^^^^^^ help: try: `std::iter::empty()` error: `iter` call on an empty collection - --> $DIR/iter_empty.rs:8:16 + --> $DIR/iter_on_empty_collections.rs:8:16 | LL | assert_eq!([].iter().next(), Option::<&i32>::None); | ^^^^^^^^^ help: try: `std::iter::empty()` error: `into_iter` call on an empty collection - --> $DIR/iter_empty.rs:9:16 + --> $DIR/iter_on_empty_collections.rs:9:16 | LL | assert_eq!(None.into_iter().next(), Option::::None); | ^^^^^^^^^^^^^^^^ help: try: `std::iter::empty()` error: `iter_mut` call on an empty collection - --> $DIR/iter_empty.rs:10:16 + --> $DIR/iter_on_empty_collections.rs:10:16 | LL | assert_eq!(None.iter_mut().next(), Option::<&mut i32>::None); | ^^^^^^^^^^^^^^^ help: try: `std::iter::empty()` error: `iter` call on an empty collection - --> $DIR/iter_empty.rs:11:16 + --> $DIR/iter_on_empty_collections.rs:11:16 | LL | assert_eq!(None.iter().next(), Option::<&i32>::None); | ^^^^^^^^^^^ help: try: `std::iter::empty()` diff --git a/tests/ui/iter_once.fixed b/tests/ui/iter_on_single_items.fixed similarity index 97% rename from tests/ui/iter_once.fixed rename to tests/ui/iter_on_single_items.fixed index 0495bc47e4b2..1fa4b03641bc 100644 --- a/tests/ui/iter_once.fixed +++ b/tests/ui/iter_on_single_items.fixed @@ -1,5 +1,5 @@ // run-rustfix -#![warn(clippy::iter_once)] +#![warn(clippy::iter_on_single_items)] #![allow(clippy::iter_next_slice, clippy::redundant_clone)] fn array() { diff --git a/tests/ui/iter_once.rs b/tests/ui/iter_on_single_items.rs similarity index 97% rename from tests/ui/iter_once.rs rename to tests/ui/iter_on_single_items.rs index 96641109bb98..ea96d8066c56 100644 --- a/tests/ui/iter_once.rs +++ b/tests/ui/iter_on_single_items.rs @@ -1,5 +1,5 @@ // run-rustfix -#![warn(clippy::iter_once)] +#![warn(clippy::iter_on_single_items)] #![allow(clippy::iter_next_slice, clippy::redundant_clone)] fn array() { diff --git a/tests/ui/iter_once.stderr b/tests/ui/iter_on_single_items.stderr similarity index 79% rename from tests/ui/iter_once.stderr rename to tests/ui/iter_on_single_items.stderr index b22c8a99f10b..d6c547116363 100644 --- a/tests/ui/iter_once.stderr +++ b/tests/ui/iter_on_single_items.stderr @@ -1,37 +1,37 @@ error: `into_iter` call on a collection with only one item - --> $DIR/iter_once.rs:6:16 + --> $DIR/iter_on_single_items.rs:6:16 | LL | assert_eq!([123].into_iter().next(), Some(123)); | ^^^^^^^^^^^^^^^^^ help: try: `std::iter::once(123)` | - = note: `-D clippy::iter-once` implied by `-D warnings` + = note: `-D clippy::iter-on-single-items` implied by `-D warnings` error: `iter_mut` call on a collection with only one item - --> $DIR/iter_once.rs:7:16 + --> $DIR/iter_on_single_items.rs:7:16 | LL | assert_eq!([123].iter_mut().next(), Some(&mut 123)); | ^^^^^^^^^^^^^^^^ help: try: `std::iter::once(&mut 123)` error: `iter` call on a collection with only one item - --> $DIR/iter_once.rs:8:16 + --> $DIR/iter_on_single_items.rs:8:16 | LL | assert_eq!([123].iter().next(), Some(&123)); | ^^^^^^^^^^^^ help: try: `std::iter::once(&123)` error: `into_iter` call on a collection with only one item - --> $DIR/iter_once.rs:9:16 + --> $DIR/iter_on_single_items.rs:9:16 | LL | assert_eq!(Some(123).into_iter().next(), Some(123)); | ^^^^^^^^^^^^^^^^^^^^^ help: try: `std::iter::once(123)` error: `iter_mut` call on a collection with only one item - --> $DIR/iter_once.rs:10:16 + --> $DIR/iter_on_single_items.rs:10:16 | LL | assert_eq!(Some(123).iter_mut().next(), Some(&mut 123)); | ^^^^^^^^^^^^^^^^^^^^ help: try: `std::iter::once(&mut 123)` error: `iter` call on a collection with only one item - --> $DIR/iter_once.rs:11:16 + --> $DIR/iter_on_single_items.rs:11:16 | LL | assert_eq!(Some(123).iter().next(), Some(&123)); | ^^^^^^^^^^^^^^^^ help: try: `std::iter::once(&123)`