Skip to content

Commit 262c9dc

Browse files
committed
Fix more code examples
1 parent 61587c9 commit 262c9dc

File tree

8 files changed

+51
-21
lines changed

8 files changed

+51
-21
lines changed

clippy_lints/src/fallible_impl_from.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,24 @@ declare_clippy_lint! {
1818
/// **Known problems:** None.
1919
///
2020
/// **Example:**
21-
/// ```rust
21+
/// ```rust,ignore
2222
/// struct Foo(i32);
23+
///
24+
/// // Bad
2325
/// impl From<String> for Foo {
2426
/// fn from(s: String) -> Self {
2527
/// Foo(s.parse().unwrap())
2628
/// }
2729
/// }
30+
///
31+
/// // Good
32+
/// use std::convert::TryFrom;
33+
/// impl TryFrom<String> for Foo {
34+
/// type Error = ();
35+
/// fn try_from(s: String) -> Result<Self, Self::Error> {
36+
/// s.parse()
37+
/// }
38+
/// }
2839
/// ```
2940
pub FALLIBLE_IMPL_FROM,
3041
nursery,
@@ -120,7 +131,7 @@ fn lint_impl_body<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, impl_span: Span, impl_it
120131
move |diag| {
121132
diag.help(
122133
"`From` is intended for infallible conversions only. \
123-
Use `TryFrom` if there's a possibility for the conversion to fail.");
134+
Use `TryFrom` if there's a possibility for the conversion to fail.");
124135
diag.span_note(fpu.result, "potential failure(s)");
125136
});
126137
}

clippy_lints/src/floating_point_arithmetic.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ declare_clippy_lint! {
2828
/// **Example:**
2929
///
3030
/// ```rust
31-
///
3231
/// let a = 3f32;
3332
/// let _ = a.powf(1.0 / 3.0);
3433
/// let _ = (1.0 + a).ln();
@@ -38,7 +37,6 @@ declare_clippy_lint! {
3837
/// is better expressed as
3938
///
4039
/// ```rust
41-
///
4240
/// let a = 3f32;
4341
/// let _ = a.cbrt();
4442
/// let _ = a.ln_1p();

clippy_lints/src/format.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,13 @@ declare_clippy_lint! {
2525
///
2626
/// **Examples:**
2727
/// ```rust
28+
///
29+
/// // Bad
2830
/// # let foo = "foo";
29-
/// format!("foo");
3031
/// format!("{}", foo);
32+
///
33+
/// // Good
34+
/// format!("foo");
3135
/// ```
3236
pub USELESS_FORMAT,
3337
complexity,

clippy_lints/src/functions.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,11 @@ declare_clippy_lint! {
4949
/// **Known problems:** None.
5050
///
5151
/// **Example:**
52-
/// ``` rust
52+
/// ```rust
5353
/// fn im_too_long() {
54-
/// println!("");
54+
/// println!("");
5555
/// // ... 100 more LoC
56-
/// println!("");
56+
/// println!("");
5757
/// }
5858
/// ```
5959
pub TOO_MANY_LINES,
@@ -79,10 +79,16 @@ declare_clippy_lint! {
7979
/// `some_argument.get_raw_ptr()`).
8080
///
8181
/// **Example:**
82-
/// ```rust
82+
/// ```rust,ignore
83+
/// // Bad
8384
/// pub fn foo(x: *const u8) {
8485
/// println!("{}", unsafe { *x });
8586
/// }
87+
///
88+
/// // Good
89+
/// pub unsafe fn foo(x: *const u8) {
90+
/// println!("{}", unsafe { *x });
91+
/// }
8692
/// ```
8793
pub NOT_UNSAFE_PTR_ARG_DEREF,
8894
correctness,

clippy_lints/src/implicit_saturating_sub.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,6 @@ declare_clippy_lint! {
2525
/// if i != 0 {
2626
/// i -= 1;
2727
/// }
28-
/// ```
29-
/// Use instead:
30-
/// ```rust
31-
/// let end: u32 = 10;
32-
/// let start: u32 = 5;
33-
///
34-
/// let mut i: u32 = end - start;
3528
///
3629
/// // Good
3730
/// i = i.saturating_sub(1);

clippy_lints/src/int_plus_one.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ use crate::utils::{snippet_opt, span_lint_and_sugg};
1010
declare_clippy_lint! {
1111
/// **What it does:** Checks for usage of `x >= y + 1` or `x - 1 >= y` (and `<=`) in a block
1212
///
13-
///
1413
/// **Why is this bad?** Readability -- better to use `> y` instead of `>= y + 1`.
1514
///
1615
/// **Known problems:** None.

clippy_lints/src/integer_division.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,13 @@ declare_clippy_lint! {
1515
///
1616
/// **Example:**
1717
/// ```rust
18-
/// fn main() {
19-
/// let x = 3 / 2;
20-
/// println!("{}", x);
21-
/// }
18+
/// // Bad
19+
/// let x = 3 / 2;
20+
/// println!("{}", x);
21+
///
22+
/// // Good
23+
/// let x = 3f32 / 2f32;
24+
/// println!("{}", x);
2225
/// ```
2326
pub INTEGER_DIVISION,
2427
restriction,

clippy_lints/src/items_after_statements.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ declare_clippy_lint! {
1616
///
1717
/// **Example:**
1818
/// ```rust
19+
/// // Bad
1920
/// fn foo() {
2021
/// println!("cake");
2122
/// }
@@ -28,6 +29,21 @@ declare_clippy_lint! {
2829
/// foo(); // prints "foo"
2930
/// }
3031
/// ```
32+
///
33+
/// ```rust
34+
/// // Good
35+
/// fn foo() {
36+
/// println!("cake");
37+
/// }
38+
///
39+
/// fn main() {
40+
/// fn foo() {
41+
/// println!("foo");
42+
/// }
43+
/// foo(); // prints "foo"
44+
/// foo(); // prints "foo"
45+
/// }
46+
/// ```
3147
pub ITEMS_AFTER_STATEMENTS,
3248
pedantic,
3349
"blocks where an item comes after a statement"

0 commit comments

Comments
 (0)