File tree 4 files changed +41
-1
lines changed
4 files changed +41
-1
lines changed Original file line number Diff line number Diff line change @@ -312,6 +312,14 @@ declare_clippy_lint! {
312
312
/// for i in 0..v.len() { foo(v[i]); }
313
313
/// for i in 0..v.len() { bar(i, v[i]); }
314
314
/// ```
315
+ /// Could be written as
316
+ /// ```rust
317
+ /// # let v = vec![1];
318
+ /// # fn foo(bar: usize) {}
319
+ /// # fn bar(bar: usize, baz: usize) {}
320
+ /// for item in &v { foo(*item); }
321
+ /// for (i, item) in v.iter().enumerate() { bar(i, *item); }
322
+ /// ```
315
323
pub EXPLICIT_COUNTER_LOOP ,
316
324
complexity,
317
325
"for-looping with an explicit counter when `_.enumerate()` would do"
Original file line number Diff line number Diff line change @@ -302,6 +302,11 @@ declare_clippy_lint! {
302
302
/// # let vec = vec![1];
303
303
/// vec.iter().filter(|x| **x == 0).next();
304
304
/// ```
305
+ /// Could be written as
306
+ /// ```rust
307
+ /// # let vec = vec![1];
308
+ /// vec.iter().find(|x| **x == 0);
309
+ /// ```
305
310
pub FILTER_NEXT ,
306
311
complexity,
307
312
"using `filter(p).next()`, which is more succinctly expressed as `.find(p)`"
@@ -425,6 +430,11 @@ declare_clippy_lint! {
425
430
/// # let vec = vec![1];
426
431
/// vec.iter().find(|x| **x == 0).is_some();
427
432
/// ```
433
+ /// Could be written as
434
+ /// ```rust
435
+ /// # let vec = vec![1];
436
+ /// vec.iter().any(|x| **x == 0);
437
+ /// ```
428
438
pub SEARCH_IS_SOME ,
429
439
complexity,
430
440
"using an iterator search followed by `is_some()`, which is more succinctly expressed as a call to `any()`"
@@ -442,7 +452,12 @@ declare_clippy_lint! {
442
452
/// **Example:**
443
453
/// ```rust
444
454
/// let name = "foo";
445
- /// name.chars().next() == Some('_');
455
+ /// if name.chars().next() == Some('_') {};
456
+ /// ```
457
+ /// Could be written as
458
+ /// ```rust
459
+ /// let name = "foo";
460
+ /// if name.starts_with('_') {};
446
461
/// ```
447
462
pub CHARS_NEXT_CMP ,
448
463
complexity,
Original file line number Diff line number Diff line change @@ -31,6 +31,10 @@ declare_clippy_lint! {
31
31
/// true
32
32
/// }
33
33
/// ```
34
+ /// Could be written as
35
+ /// ```rust,ignore
36
+ /// !x
37
+ /// ```
34
38
pub NEEDLESS_BOOL ,
35
39
complexity,
36
40
"if-statements with plain booleans in the then- and else-clause, e.g., `if p { true } else { false }`"
Original file line number Diff line number Diff line change @@ -43,6 +43,11 @@ declare_clippy_lint! {
43
43
/// # let x = vec![1];
44
44
/// x.iter().zip(0..x.len());
45
45
/// ```
46
+ /// Could be written as
47
+ /// ```rust
48
+ /// # let x = vec![1];
49
+ /// x.iter().enumerate();
50
+ /// ```
46
51
pub RANGE_ZIP_WITH_LEN ,
47
52
complexity,
48
53
"zipping iterator with a range when `enumerate()` would do"
@@ -64,6 +69,10 @@ declare_clippy_lint! {
64
69
/// ```rust,ignore
65
70
/// for x..(y+1) { .. }
66
71
/// ```
72
+ /// Could be written as
73
+ /// ```rust,ignore
74
+ /// for x..=y { .. }
75
+ /// ```
67
76
pub RANGE_PLUS_ONE ,
68
77
complexity,
69
78
"`x..(y+1)` reads better as `x..=y`"
@@ -82,6 +91,10 @@ declare_clippy_lint! {
82
91
/// ```rust,ignore
83
92
/// for x..=(y-1) { .. }
84
93
/// ```
94
+ /// Could be written as
95
+ /// ```rust,ignore
96
+ /// for x..y { .. }
97
+ /// ```
85
98
pub RANGE_MINUS_ONE ,
86
99
complexity,
87
100
"`x..=(y-1)` reads better as `x..y`"
You can’t perform that action at this time.
0 commit comments