@@ -218,7 +218,12 @@ declare_clippy_lint! {
218218 /// **Example:**
219219 /// ```rust
220220 /// # 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?");
222227 /// ```
223228 pub OK_EXPECT ,
224229 style,
@@ -273,8 +278,12 @@ declare_clippy_lint! {
273278 /// **Example:**
274279 /// ```rust
275280 /// # 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));
278287 /// ```
279288 pub OPTION_MAP_OR_NONE ,
280289 style,
@@ -390,14 +399,19 @@ declare_clippy_lint! {
390399 /// **What it does:** Checks for usage of `_.map(_).flatten(_)`,
391400 ///
392401 /// **Why is this bad?** Readability, this can be written more concisely as a
393- /// single method call.
402+ /// single method call using `_.flat_map(_)`
394403 ///
395404 /// **Known problems:**
396405 ///
397406 /// **Example:**
398407 /// ```rust
399408 /// let vec = vec![vec![1]];
409+ ///
410+ /// // Bad
400411 /// vec.iter().map(|x| x.iter()).flatten();
412+ ///
413+ /// // Good
414+ /// vec.iter().flat_map(|x| x.iter());
401415 /// ```
402416 pub MAP_FLATTEN ,
403417 pedantic,
@@ -417,7 +431,12 @@ declare_clippy_lint! {
417431 /// **Example:**
418432 /// ```rust
419433 /// let vec = vec![1];
434+ ///
435+ /// // Bad
420436 /// vec.iter().filter(|x| **x == 0).map(|x| *x * 2);
437+ ///
438+ /// // Good
439+ /// vec.iter().filter_map(|x| Some(*x * 2));
421440 /// ```
422441 pub FILTER_MAP ,
423442 pedantic,
@@ -634,7 +653,12 @@ declare_clippy_lint! {
634653 /// ```rust
635654 /// # use std::rc::Rc;
636655 /// let x = Rc::new(1);
656+ ///
657+ /// // Bad
637658 /// x.clone();
659+ ///
660+ /// // Good
661+ /// Rc::clone(&x);
638662 /// ```
639663 pub CLONE_ON_REF_PTR ,
640664 restriction,
@@ -741,7 +765,12 @@ declare_clippy_lint! {
741765 /// **Known problems:** Does not catch multi-byte unicode characters.
742766 ///
743767 /// **Example:**
744- /// `_.split("x")` could be `_.split('x')`
768+ /// ```rust,ignore
769+ /// // Bad
770+ /// _.split("x");
771+ ///
772+ /// // Good
773+ /// _.split('x');
745774 pub SINGLE_CHAR_PATTERN ,
746775 perf,
747776 "using a single-character str where a char could be used, e.g., `_.split(\" x\" )`"
@@ -964,8 +993,8 @@ declare_clippy_lint! {
964993}
965994
966995declare_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.
969998 ///
970999 /// **Why is this bad?** Readability, this can be written more concisely as
9711000 /// `_.ends_with(_)`.
@@ -975,8 +1004,12 @@ declare_clippy_lint! {
9751004 /// **Example:**
9761005 /// ```rust
9771006 /// # 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('-');
9801013 /// ```
9811014 pub CHARS_LAST_CMP ,
9821015 style,
@@ -1044,17 +1077,15 @@ declare_clippy_lint! {
10441077 /// **Example:**
10451078 /// ```rust
10461079 /// 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:
10501082 /// let _ = (0..3).filter(|&x| x > 2);
10511083 /// ```
10521084 ///
10531085 /// ```rust
10541086 /// 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:
10581089 /// let _ = (0..4).map(|x| x + 1);
10591090 /// ```
10601091 pub UNNECESSARY_FILTER_MAP ,
@@ -1075,7 +1106,11 @@ declare_clippy_lint! {
10751106 /// **Example:**
10761107 ///
10771108 /// ```rust
1109+ /// // Bad
10781110 /// let _ = (&vec![3, 4, 5]).into_iter();
1111+ ///
1112+ /// // Good
1113+ /// let _ = (&vec![3, 4, 5]).iter();
10791114 /// ```
10801115 pub INTO_ITER_ON_REF ,
10811116 style,
0 commit comments