@@ -218,7 +218,12 @@ declare_clippy_lint! {
218
218
/// **Example:**
219
219
/// ```rust
220
220
/// # let x = Ok::<_, ()>(());
221
- /// x.ok().expect("why did I do this again?")
221
+ ///
222
+ /// // Bad
223
+ /// x.ok().expect("why did I do this again?");
224
+ ///
225
+ /// // Good
226
+ /// x.expect("why did I do this again?");
222
227
/// ```
223
228
pub OK_EXPECT ,
224
229
style,
@@ -273,8 +278,12 @@ declare_clippy_lint! {
273
278
/// **Example:**
274
279
/// ```rust
275
280
/// # let opt = Some(1);
276
- /// opt.map_or(None, |a| Some(a + 1))
277
- /// # ;
281
+ ///
282
+ /// // Bad
283
+ /// opt.map_or(None, |a| Some(a + 1));
284
+ ///
285
+ /// // Good
286
+ /// opt.and_then(|a| Some(a + 1));
278
287
/// ```
279
288
pub OPTION_MAP_OR_NONE ,
280
289
style,
@@ -390,14 +399,19 @@ declare_clippy_lint! {
390
399
/// **What it does:** Checks for usage of `_.map(_).flatten(_)`,
391
400
///
392
401
/// **Why is this bad?** Readability, this can be written more concisely as a
393
- /// single method call.
402
+ /// single method call using `_.flat_map(_)`
394
403
///
395
404
/// **Known problems:**
396
405
///
397
406
/// **Example:**
398
407
/// ```rust
399
408
/// let vec = vec![vec![1]];
409
+ ///
410
+ /// // Bad
400
411
/// vec.iter().map(|x| x.iter()).flatten();
412
+ ///
413
+ /// // Good
414
+ /// vec.iter().flat_map(|x| x.iter());
401
415
/// ```
402
416
pub MAP_FLATTEN ,
403
417
pedantic,
@@ -417,7 +431,12 @@ declare_clippy_lint! {
417
431
/// **Example:**
418
432
/// ```rust
419
433
/// let vec = vec![1];
434
+ ///
435
+ /// // Bad
420
436
/// vec.iter().filter(|x| **x == 0).map(|x| *x * 2);
437
+ ///
438
+ /// // Good
439
+ /// vec.iter().filter_map(|x| Some(*x * 2));
421
440
/// ```
422
441
pub FILTER_MAP ,
423
442
pedantic,
@@ -634,7 +653,12 @@ declare_clippy_lint! {
634
653
/// ```rust
635
654
/// # use std::rc::Rc;
636
655
/// let x = Rc::new(1);
656
+ ///
657
+ /// // Bad
637
658
/// x.clone();
659
+ ///
660
+ /// // Good
661
+ /// Rc::clone(&x);
638
662
/// ```
639
663
pub CLONE_ON_REF_PTR ,
640
664
restriction,
@@ -741,7 +765,12 @@ declare_clippy_lint! {
741
765
/// **Known problems:** Does not catch multi-byte unicode characters.
742
766
///
743
767
/// **Example:**
744
- /// `_.split("x")` could be `_.split('x')`
768
+ /// ```rust,ignore
769
+ /// // Bad
770
+ /// _.split("x");
771
+ ///
772
+ /// // Good
773
+ /// _.split('x');
745
774
pub SINGLE_CHAR_PATTERN ,
746
775
perf,
747
776
"using a single-character str where a char could be used, e.g., `_.split(\" x\" )`"
@@ -964,8 +993,8 @@ declare_clippy_lint! {
964
993
}
965
994
966
995
declare_clippy_lint ! {
967
- /// **What it does:** Checks for usage of `.chars().last()` or
968
- /// `.chars().next_back()` on a `str` to check if it ends with a given char.
996
+ /// **What it does:** Checks for usage of `_ .chars().last()` or
997
+ /// `_ .chars().next_back()` on a `str` to check if it ends with a given char.
969
998
///
970
999
/// **Why is this bad?** Readability, this can be written more concisely as
971
1000
/// `_.ends_with(_)`.
@@ -975,8 +1004,12 @@ declare_clippy_lint! {
975
1004
/// **Example:**
976
1005
/// ```rust
977
1006
/// # let name = "_";
978
- /// name.chars().last() == Some('_') || name.chars().next_back() == Some('-')
979
- /// # ;
1007
+ ///
1008
+ /// // Bad
1009
+ /// name.chars().last() == Some('_') || name.chars().next_back() == Some('-');
1010
+ ///
1011
+ /// // Good
1012
+ /// name.ends_with('_') || name.ends_with('-');
980
1013
/// ```
981
1014
pub CHARS_LAST_CMP ,
982
1015
style,
@@ -1044,17 +1077,15 @@ declare_clippy_lint! {
1044
1077
/// **Example:**
1045
1078
/// ```rust
1046
1079
/// let _ = (0..3).filter_map(|x| if x > 2 { Some(x) } else { None });
1047
- /// ```
1048
- /// As there is no transformation of the argument this could be written as:
1049
- /// ```rust
1080
+ ///
1081
+ /// // As there is no transformation of the argument this could be written as:
1050
1082
/// let _ = (0..3).filter(|&x| x > 2);
1051
1083
/// ```
1052
1084
///
1053
1085
/// ```rust
1054
1086
/// let _ = (0..4).filter_map(|x| Some(x + 1));
1055
- /// ```
1056
- /// As there is no conditional check on the argument this could be written as:
1057
- /// ```rust
1087
+ ///
1088
+ /// // As there is no conditional check on the argument this could be written as:
1058
1089
/// let _ = (0..4).map(|x| x + 1);
1059
1090
/// ```
1060
1091
pub UNNECESSARY_FILTER_MAP ,
@@ -1075,7 +1106,11 @@ declare_clippy_lint! {
1075
1106
/// **Example:**
1076
1107
///
1077
1108
/// ```rust
1109
+ /// // Bad
1078
1110
/// let _ = (&vec![3, 4, 5]).into_iter();
1111
+ ///
1112
+ /// // Good
1113
+ /// let _ = (&vec![3, 4, 5]).iter();
1079
1114
/// ```
1080
1115
pub INTO_ITER_ON_REF ,
1081
1116
style,
0 commit comments