Skip to content

Commit 2d4ff2d

Browse files
committed
Rename new lints to iter_on_empty_collections and iter_on_single_items
1 parent 4a20e23 commit 2d4ff2d

11 files changed

+36
-34
lines changed

CHANGELOG.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3506,7 +3506,7 @@ Released 2018-09-13
35063506
[`debug_assert_with_mut_call`]: https://rust-lang.github.io/rust-clippy/master/index.html#debug_assert_with_mut_call
35073507
[`decimal_literal_representation`]: https://rust-lang.github.io/rust-clippy/master/index.html#decimal_literal_representation
35083508
[`declare_interior_mutable_const`]: https://rust-lang.github.io/rust-clippy/master/index.html#declare_interior_mutable_const
3509-
[`default_instead_of_iter_empty`]: https://rust-lang.github.io/rust-clippy/master/index.html#default_instead_of_iter_empty
3509+
[`default_instead_of_iter_on_empty_collections`]: https://rust-lang.github.io/rust-clippy/master/index.html#default_instead_of_iter_on_empty_collections
35103510
[`default_numeric_fallback`]: https://rust-lang.github.io/rust-clippy/master/index.html#default_numeric_fallback
35113511
[`default_trait_access`]: https://rust-lang.github.io/rust-clippy/master/index.html#default_trait_access
35123512
[`default_union_representation`]: https://rust-lang.github.io/rust-clippy/master/index.html#default_union_representation
@@ -3648,13 +3648,13 @@ Released 2018-09-13
36483648
[`items_after_statements`]: https://rust-lang.github.io/rust-clippy/master/index.html#items_after_statements
36493649
[`iter_cloned_collect`]: https://rust-lang.github.io/rust-clippy/master/index.html#iter_cloned_collect
36503650
[`iter_count`]: https://rust-lang.github.io/rust-clippy/master/index.html#iter_count
3651-
[`iter_empty`]: https://rust-lang.github.io/rust-clippy/master/index.html#iter_empty
3651+
[`iter_on_empty_collections`]: https://rust-lang.github.io/rust-clippy/master/index.html#iter_on_empty_collections
36523652
[`iter_next_loop`]: https://rust-lang.github.io/rust-clippy/master/index.html#iter_next_loop
36533653
[`iter_next_slice`]: https://rust-lang.github.io/rust-clippy/master/index.html#iter_next_slice
36543654
[`iter_not_returning_iterator`]: https://rust-lang.github.io/rust-clippy/master/index.html#iter_not_returning_iterator
36553655
[`iter_nth`]: https://rust-lang.github.io/rust-clippy/master/index.html#iter_nth
36563656
[`iter_nth_zero`]: https://rust-lang.github.io/rust-clippy/master/index.html#iter_nth_zero
3657-
[`iter_once`]: https://rust-lang.github.io/rust-clippy/master/index.html#iter_once
3657+
[`iter_on_single_items`]: https://rust-lang.github.io/rust-clippy/master/index.html#iter_on_single_items
36583658
[`iter_overeager_cloned`]: https://rust-lang.github.io/rust-clippy/master/index.html#iter_overeager_cloned
36593659
[`iter_skip_next`]: https://rust-lang.github.io/rust-clippy/master/index.html#iter_skip_next
36603660
[`iter_with_drain`]: https://rust-lang.github.io/rust-clippy/master/index.html#iter_with_drain

clippy_lints/src/lib.register_lints.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -310,11 +310,11 @@ store.register_lints(&[
310310
methods::ITERATOR_STEP_BY_ZERO,
311311
methods::ITER_CLONED_COLLECT,
312312
methods::ITER_COUNT,
313-
methods::ITER_EMPTY,
313+
methods::ITER_ON_EMPTY_COLLECTIONS,
314314
methods::ITER_NEXT_SLICE,
315315
methods::ITER_NTH,
316316
methods::ITER_NTH_ZERO,
317-
methods::ITER_ONCE,
317+
methods::ITER_ON_SINGLE_ITEMS,
318318
methods::ITER_OVEREAGER_CLONED,
319319
methods::ITER_SKIP_NEXT,
320320
methods::ITER_WITH_DRAIN,

clippy_lints/src/lib.register_nursery.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ store.register_group(true, "clippy::nursery", Some("clippy_nursery"), vec![
1313
LintId::of(future_not_send::FUTURE_NOT_SEND),
1414
LintId::of(index_refutable_slice::INDEX_REFUTABLE_SLICE),
1515
LintId::of(let_if_seq::USELESS_LET_IF_SEQ),
16-
LintId::of(methods::ITER_EMPTY),
17-
LintId::of(methods::ITER_ONCE),
16+
LintId::of(methods::ITER_ON_EMPTY_COLLECTIONS),
17+
LintId::of(methods::ITER_ON_SINGLE_ITEMS),
1818
LintId::of(methods::ITER_WITH_DRAIN),
1919
LintId::of(missing_const_for_fn::MISSING_CONST_FOR_FN),
2020
LintId::of(mutable_debug_assertion::DEBUG_ASSERT_WITH_MUT_CALL),

clippy_lints/src/methods/iter_once_empty.rs renamed to clippy_lints/src/methods/iter_on_single_or_empty_collections.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use rustc_hir::LangItem::{OptionNone, OptionSome};
77
use rustc_hir::{Expr, ExprKind, Node};
88
use rustc_lint::LateContext;
99

10-
use super::{ITER_EMPTY, ITER_ONCE};
10+
use super::{ITER_ON_EMPTY_COLLECTIONS, ITER_ON_SINGLE_ITEMS};
1111

1212
enum IterType {
1313
Iter,
@@ -82,7 +82,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'_>, method_name:
8282
);
8383
span_lint_and_sugg(
8484
cx,
85-
ITER_ONCE,
85+
ITER_ON_SINGLE_ITEMS,
8686
expr.span,
8787
&format!("`{method_name}` call on a collection with only one item"),
8888
"try",
@@ -92,7 +92,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'_>, method_name:
9292
} else {
9393
span_lint_and_sugg(
9494
cx,
95-
ITER_EMPTY,
95+
ITER_ON_EMPTY_COLLECTIONS,
9696
expr.span,
9797
&format!("`{method_name}` call on an empty collection"),
9898
"try",

clippy_lints/src/methods/mod.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ mod iter_count;
3333
mod iter_next_slice;
3434
mod iter_nth;
3535
mod iter_nth_zero;
36-
mod iter_once_empty;
36+
mod iter_on_single_or_empty_collections;
3737
mod iter_overeager_cloned;
3838
mod iter_skip_next;
3939
mod iter_with_drain;
@@ -2320,7 +2320,7 @@ declare_clippy_lint! {
23202320
///
23212321
/// The type of the resulting iterator might become incompatible with its usage
23222322
#[clippy::version = "1.64.0"]
2323-
pub ITER_ONCE,
2323+
pub ITER_ON_SINGLE_ITEMS,
23242324
nursery,
23252325
"Iterator for array of length 1"
23262326
}
@@ -2352,7 +2352,7 @@ declare_clippy_lint! {
23522352
///
23532353
/// The type of the resulting iterator might become incompatible with its usage
23542354
#[clippy::version = "1.64.0"]
2355-
pub ITER_EMPTY,
2355+
pub ITER_ON_EMPTY_COLLECTIONS,
23562356
nursery,
23572357
"Iterator for empty array"
23582358
}
@@ -2459,8 +2459,8 @@ impl_lint_pass!(Methods => [
24592459
NEEDLESS_OPTION_TAKE,
24602460
NO_EFFECT_REPLACE,
24612461
OBFUSCATED_IF_ELSE,
2462-
ITER_ONCE,
2463-
ITER_EMPTY
2462+
ITER_ON_SINGLE_ITEMS,
2463+
ITER_ON_EMPTY_COLLECTIONS
24642464
]);
24652465

24662466
/// Extracts a method call name, args, and `Span` of the method name.
@@ -2763,7 +2763,9 @@ impl Methods {
27632763
("is_digit", [radix]) => is_digit_ascii_radix::check(cx, expr, recv, radix, self.msrv),
27642764
("is_none", []) => check_is_some_is_none(cx, expr, recv, false),
27652765
("is_some", []) => check_is_some_is_none(cx, expr, recv, true),
2766-
("iter" | "iter_mut" | "into_iter", []) => iter_once_empty::check(cx, expr, name, recv),
2766+
("iter" | "iter_mut" | "into_iter", []) => {
2767+
iter_on_single_or_empty_collections::check(cx, expr, name, recv);
2768+
},
27672769
("join", [join_arg]) => {
27682770
if let Some(("collect", _, span)) = method_call(recv) {
27692771
unnecessary_join::check(cx, expr, recv, join_arg, span);

tests/ui/iter_empty.fixed renamed to tests/ui/iter_on_empty_collections.fixed

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// run-rustfix
2-
#![warn(clippy::iter_empty)]
2+
#![warn(clippy::iter_on_empty_collections)]
33
#![allow(clippy::iter_next_slice, clippy::redundant_clone)]
44

55
fn array() {

tests/ui/iter_empty.rs renamed to tests/ui/iter_on_empty_collections.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// run-rustfix
2-
#![warn(clippy::iter_empty)]
2+
#![warn(clippy::iter_on_empty_collections)]
33
#![allow(clippy::iter_next_slice, clippy::redundant_clone)]
44

55
fn array() {

tests/ui/iter_empty.stderr renamed to tests/ui/iter_on_empty_collections.stderr

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,37 @@
11
error: `into_iter` call on an empty collection
2-
--> $DIR/iter_empty.rs:6:16
2+
--> $DIR/iter_on_empty_collections.rs:6:16
33
|
44
LL | assert_eq!([].into_iter().next(), Option::<i32>::None);
55
| ^^^^^^^^^^^^^^ help: try: `std::iter::empty()`
66
|
7-
= note: `-D clippy::iter-empty` implied by `-D warnings`
7+
= note: `-D clippy::iter-on-empty-collections` implied by `-D warnings`
88

99
error: `iter_mut` call on an empty collection
10-
--> $DIR/iter_empty.rs:7:16
10+
--> $DIR/iter_on_empty_collections.rs:7:16
1111
|
1212
LL | assert_eq!([].iter_mut().next(), Option::<&mut i32>::None);
1313
| ^^^^^^^^^^^^^ help: try: `std::iter::empty()`
1414

1515
error: `iter` call on an empty collection
16-
--> $DIR/iter_empty.rs:8:16
16+
--> $DIR/iter_on_empty_collections.rs:8:16
1717
|
1818
LL | assert_eq!([].iter().next(), Option::<&i32>::None);
1919
| ^^^^^^^^^ help: try: `std::iter::empty()`
2020

2121
error: `into_iter` call on an empty collection
22-
--> $DIR/iter_empty.rs:9:16
22+
--> $DIR/iter_on_empty_collections.rs:9:16
2323
|
2424
LL | assert_eq!(None.into_iter().next(), Option::<i32>::None);
2525
| ^^^^^^^^^^^^^^^^ help: try: `std::iter::empty()`
2626

2727
error: `iter_mut` call on an empty collection
28-
--> $DIR/iter_empty.rs:10:16
28+
--> $DIR/iter_on_empty_collections.rs:10:16
2929
|
3030
LL | assert_eq!(None.iter_mut().next(), Option::<&mut i32>::None);
3131
| ^^^^^^^^^^^^^^^ help: try: `std::iter::empty()`
3232

3333
error: `iter` call on an empty collection
34-
--> $DIR/iter_empty.rs:11:16
34+
--> $DIR/iter_on_empty_collections.rs:11:16
3535
|
3636
LL | assert_eq!(None.iter().next(), Option::<&i32>::None);
3737
| ^^^^^^^^^^^ help: try: `std::iter::empty()`

tests/ui/iter_once.fixed renamed to tests/ui/iter_on_single_items.fixed

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// run-rustfix
2-
#![warn(clippy::iter_once)]
2+
#![warn(clippy::iter_on_single_items)]
33
#![allow(clippy::iter_next_slice, clippy::redundant_clone)]
44

55
fn array() {

tests/ui/iter_once.rs renamed to tests/ui/iter_on_single_items.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// run-rustfix
2-
#![warn(clippy::iter_once)]
2+
#![warn(clippy::iter_on_single_items)]
33
#![allow(clippy::iter_next_slice, clippy::redundant_clone)]
44

55
fn array() {

tests/ui/iter_once.stderr renamed to tests/ui/iter_on_single_items.stderr

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,37 @@
11
error: `into_iter` call on a collection with only one item
2-
--> $DIR/iter_once.rs:6:16
2+
--> $DIR/iter_on_single_items.rs:6:16
33
|
44
LL | assert_eq!([123].into_iter().next(), Some(123));
55
| ^^^^^^^^^^^^^^^^^ help: try: `std::iter::once(123)`
66
|
7-
= note: `-D clippy::iter-once` implied by `-D warnings`
7+
= note: `-D clippy::iter-on-single-items` implied by `-D warnings`
88

99
error: `iter_mut` call on a collection with only one item
10-
--> $DIR/iter_once.rs:7:16
10+
--> $DIR/iter_on_single_items.rs:7:16
1111
|
1212
LL | assert_eq!([123].iter_mut().next(), Some(&mut 123));
1313
| ^^^^^^^^^^^^^^^^ help: try: `std::iter::once(&mut 123)`
1414

1515
error: `iter` call on a collection with only one item
16-
--> $DIR/iter_once.rs:8:16
16+
--> $DIR/iter_on_single_items.rs:8:16
1717
|
1818
LL | assert_eq!([123].iter().next(), Some(&123));
1919
| ^^^^^^^^^^^^ help: try: `std::iter::once(&123)`
2020

2121
error: `into_iter` call on a collection with only one item
22-
--> $DIR/iter_once.rs:9:16
22+
--> $DIR/iter_on_single_items.rs:9:16
2323
|
2424
LL | assert_eq!(Some(123).into_iter().next(), Some(123));
2525
| ^^^^^^^^^^^^^^^^^^^^^ help: try: `std::iter::once(123)`
2626

2727
error: `iter_mut` call on a collection with only one item
28-
--> $DIR/iter_once.rs:10:16
28+
--> $DIR/iter_on_single_items.rs:10:16
2929
|
3030
LL | assert_eq!(Some(123).iter_mut().next(), Some(&mut 123));
3131
| ^^^^^^^^^^^^^^^^^^^^ help: try: `std::iter::once(&mut 123)`
3232

3333
error: `iter` call on a collection with only one item
34-
--> $DIR/iter_once.rs:11:16
34+
--> $DIR/iter_on_single_items.rs:11:16
3535
|
3636
LL | assert_eq!(Some(123).iter().next(), Some(&123));
3737
| ^^^^^^^^^^^^^^^^ help: try: `std::iter::once(&123)`

0 commit comments

Comments
 (0)