Skip to content

Commit ece5f6b

Browse files
committed
Rename new lints to iter_on_empty_collections and iter_on_single_items
1 parent a9e3e1a commit ece5f6b

11 files changed

+35
-33
lines changed

CHANGELOG.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3651,13 +3651,13 @@ Released 2018-09-13
36513651
[`items_after_statements`]: https://rust-lang.github.io/rust-clippy/master/index.html#items_after_statements
36523652
[`iter_cloned_collect`]: https://rust-lang.github.io/rust-clippy/master/index.html#iter_cloned_collect
36533653
[`iter_count`]: https://rust-lang.github.io/rust-clippy/master/index.html#iter_count
3654-
[`iter_empty`]: https://rust-lang.github.io/rust-clippy/master/index.html#iter_empty
36553654
[`iter_next_loop`]: https://rust-lang.github.io/rust-clippy/master/index.html#iter_next_loop
36563655
[`iter_next_slice`]: https://rust-lang.github.io/rust-clippy/master/index.html#iter_next_slice
36573656
[`iter_not_returning_iterator`]: https://rust-lang.github.io/rust-clippy/master/index.html#iter_not_returning_iterator
36583657
[`iter_nth`]: https://rust-lang.github.io/rust-clippy/master/index.html#iter_nth
36593658
[`iter_nth_zero`]: https://rust-lang.github.io/rust-clippy/master/index.html#iter_nth_zero
3660-
[`iter_once`]: https://rust-lang.github.io/rust-clippy/master/index.html#iter_once
3659+
[`iter_on_empty_collections`]: https://rust-lang.github.io/rust-clippy/master/index.html#iter_on_empty_collections
3660+
[`iter_on_single_items`]: https://rust-lang.github.io/rust-clippy/master/index.html#iter_on_single_items
36613661
[`iter_overeager_cloned`]: https://rust-lang.github.io/rust-clippy/master/index.html#iter_overeager_cloned
36623662
[`iter_skip_next`]: https://rust-lang.github.io/rust-clippy/master/index.html#iter_skip_next
36633663
[`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
@@ -312,11 +312,11 @@ store.register_lints(&[
312312
methods::ITERATOR_STEP_BY_ZERO,
313313
methods::ITER_CLONED_COLLECT,
314314
methods::ITER_COUNT,
315-
methods::ITER_EMPTY,
316315
methods::ITER_NEXT_SLICE,
317316
methods::ITER_NTH,
318317
methods::ITER_NTH_ZERO,
319-
methods::ITER_ONCE,
318+
methods::ITER_ON_EMPTY_COLLECTIONS,
319+
methods::ITER_ON_SINGLE_ITEMS,
320320
methods::ITER_OVEREAGER_CLONED,
321321
methods::ITER_SKIP_NEXT,
322322
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;
@@ -2331,7 +2331,7 @@ declare_clippy_lint! {
23312331
///
23322332
/// The type of the resulting iterator might become incompatible with its usage
23332333
#[clippy::version = "1.64.0"]
2334-
pub ITER_ONCE,
2334+
pub ITER_ON_SINGLE_ITEMS,
23352335
nursery,
23362336
"Iterator for array of length 1"
23372337
}
@@ -2363,7 +2363,7 @@ declare_clippy_lint! {
23632363
///
23642364
/// The type of the resulting iterator might become incompatible with its usage
23652365
#[clippy::version = "1.64.0"]
2366-
pub ITER_EMPTY,
2366+
pub ITER_ON_EMPTY_COLLECTIONS,
23672367
nursery,
23682368
"Iterator for empty array"
23692369
}
@@ -2470,8 +2470,8 @@ impl_lint_pass!(Methods => [
24702470
NEEDLESS_OPTION_TAKE,
24712471
NO_EFFECT_REPLACE,
24722472
OBFUSCATED_IF_ELSE,
2473-
ITER_ONCE,
2474-
ITER_EMPTY
2473+
ITER_ON_SINGLE_ITEMS,
2474+
ITER_ON_EMPTY_COLLECTIONS
24752475
]);
24762476

24772477
/// Extracts a method call name, args, and `Span` of the method name.
@@ -2774,7 +2774,9 @@ impl Methods {
27742774
("is_digit", [radix]) => is_digit_ascii_radix::check(cx, expr, recv, radix, self.msrv),
27752775
("is_none", []) => check_is_some_is_none(cx, expr, recv, false),
27762776
("is_some", []) => check_is_some_is_none(cx, expr, recv, true),
2777-
("iter" | "iter_mut" | "into_iter", []) => iter_once_empty::check(cx, expr, name, recv),
2777+
("iter" | "iter_mut" | "into_iter", []) => {
2778+
iter_on_single_or_empty_collections::check(cx, expr, name, recv);
2779+
},
27782780
("join", [join_arg]) => {
27792781
if let Some(("collect", _, span)) = method_call(recv) {
27802782
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)