Skip to content

Commit 9aeed6b

Browse files
committed
Improve lint doc consistency
1 parent 3e52dee commit 9aeed6b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+621
-427
lines changed

clippy_lints/src/assertions_on_constants.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@ declare_clippy_lint! {
1414
/// Will be optimized out by the compiler or should probably be replaced by a
1515
/// `panic!()` or `unreachable!()`
1616
///
17-
/// ### Known problems
18-
/// None
19-
///
2017
/// ### Example
2118
/// ```rust,ignore
2219
/// assert!(false)

clippy_lints/src/async_yields_async.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ declare_clippy_lint! {
2424
/// };
2525
/// }
2626
/// ```
27+
///
2728
/// Use instead:
2829
/// ```rust
2930
/// async fn foo() {}

clippy_lints/src/await_holding_invalid.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,6 @@ declare_clippy_lint! {
140140
/// from a memory access perspective but will cause bugs at runtime if they
141141
/// are held in such a way.
142142
///
143-
/// ### Known problems
144-
///
145143
/// ### Example
146144
///
147145
/// ```toml

clippy_lints/src/bool_assert_comparison.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,12 @@ declare_clippy_lint! {
1717
///
1818
/// ### Example
1919
/// ```rust
20-
/// // Bad
2120
/// assert_eq!("a".is_empty(), false);
2221
/// assert_ne!("a".is_empty(), true);
22+
/// ```
2323
///
24-
/// // Good
24+
/// Use instead:
25+
/// ```rust
2526
/// assert!(!"a".is_empty());
2627
/// ```
2728
#[clippy::version = "1.53.0"]

clippy_lints/src/borrow_deref_ref.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ declare_clippy_lint! {
1818
/// Dereferencing and then borrowing a reference value has no effect in most cases.
1919
///
2020
/// ### Known problems
21-
/// false negative on such code:
21+
/// False negative on such code:
2222
/// ```
2323
/// let x = &12;
2424
/// let addr_x = &x as *const _ as usize;
@@ -29,17 +29,20 @@ declare_clippy_lint! {
2929
///
3030
/// ### Example
3131
/// ```rust
32+
/// fn foo(_x: &str) {}
33+
///
3234
/// let s = &String::new();
3335
///
34-
/// // Bad
3536
/// let a: &String = &* s;
3637
/// foo(&*s);
38+
/// ```
3739
///
38-
/// // Good
40+
/// Use instead:
41+
/// ```rust
42+
/// # fn foo(_x: &str) {}
43+
/// # let s = &String::new();
3944
/// let a: &String = s;
4045
/// foo(&**s);
41-
///
42-
/// fn foo(_: &str){ }
4346
/// ```
4447
#[clippy::version = "1.59.0"]
4548
pub BORROW_DEREF_REF,

clippy_lints/src/casts/mod.rs

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -219,13 +219,16 @@ declare_clippy_lint! {
219219
///
220220
/// ### Example
221221
/// ```rust
222-
/// // Bad
223222
/// fn fun() -> i32 { 1 }
224-
/// let a = fun as i64;
223+
/// # let _ =
224+
/// fun as i64;
225+
/// ```
225226
///
226-
/// // Good
227-
/// fn fun2() -> i32 { 1 }
228-
/// let a = fun2 as usize;
227+
/// Use instead:
228+
/// ```rust
229+
/// # fn fun() -> i32 { 1 }
230+
/// # let _ =
231+
/// fun as usize;
229232
/// ```
230233
#[clippy::version = "pre 1.29.0"]
231234
pub FN_TO_NUMERIC_CAST,
@@ -245,17 +248,20 @@ declare_clippy_lint! {
245248
///
246249
/// ### Example
247250
/// ```rust
248-
/// // Bad
249251
/// fn fn1() -> i16 {
250252
/// 1
251253
/// };
252-
/// let _ = fn1 as i32;
254+
/// # let _ =
255+
/// fn1 as i32;
256+
/// ```
253257
///
254-
/// // Better: Cast to usize first, then comment with the reason for the truncation
255-
/// fn fn2() -> i16 {
258+
/// Use instead:
259+
/// ```rust
260+
/// // Cast to usize first, then comment with the reason for the truncation
261+
/// fn fn1() -> i16 {
256262
/// 1
257263
/// };
258-
/// let fn_ptr = fn2 as usize;
264+
/// let fn_ptr = fn1 as usize;
259265
/// let fn_ptr_truncated = fn_ptr as i32;
260266
/// ```
261267
#[clippy::version = "pre 1.29.0"]
@@ -277,23 +283,31 @@ declare_clippy_lint! {
277283
///
278284
/// ### Example
279285
/// ```rust
280-
/// // Bad: fn1 is cast as `usize`
286+
/// // fn1 is cast as `usize`
281287
/// fn fn1() -> u16 {
282288
/// 1
283289
/// };
284-
/// let _ = fn1 as usize;
290+
/// # let _ =
291+
/// fn1 as usize;
292+
/// ```
285293
///
286-
/// // Good: maybe you intended to call the function?
294+
/// Use instead:
295+
/// ```rust
296+
/// // maybe you intended to call the function?
287297
/// fn fn2() -> u16 {
288298
/// 1
289299
/// };
290-
/// let _ = fn2() as usize;
300+
/// # let _ =
301+
/// fn2() as usize;
302+
///
303+
/// // or
291304
///
292-
/// // Good: maybe you intended to cast it to a function type?
305+
/// // maybe you intended to cast it to a function type?
293306
/// fn fn3() -> u16 {
294307
/// 1
295308
/// }
296-
/// let _ = fn3 as fn() -> u16;
309+
/// # let _ =
310+
/// fn3 as fn() -> u16;
297311
/// ```
298312
#[clippy::version = "1.58.0"]
299313
pub FN_TO_NUMERIC_CAST_ANY,

clippy_lints/src/comparison_chain.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ declare_clippy_lint! {
3535
/// ```
3636
///
3737
/// Use instead:
38-
///
3938
/// ```rust,ignore
4039
/// use std::cmp::Ordering;
4140
/// # fn a() {}

clippy_lints/src/dbg_macro.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,11 @@ declare_clippy_lint! {
1818
///
1919
/// ### Example
2020
/// ```rust,ignore
21-
/// // Bad
2221
/// dbg!(true)
22+
/// ```
2323
///
24-
/// // Good
24+
/// Use instead:
25+
/// ```rust,ignore
2526
/// true
2627
/// ```
2728
#[clippy::version = "1.34.0"]

clippy_lints/src/default.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,16 @@ declare_clippy_lint! {
1818
/// Checks for literal calls to `Default::default()`.
1919
///
2020
/// ### Why is this bad?
21-
/// It's more clear to the reader to use the name of the type whose default is
22-
/// being gotten than the generic `Default`.
21+
/// It's easier for the reader if the name of the type is used, rather than the
22+
/// generic `Default`.
2323
///
2424
/// ### Example
2525
/// ```rust
26-
/// // Bad
2726
/// let s: String = Default::default();
27+
/// ```
2828
///
29-
/// // Good
29+
/// Use instead:
30+
/// ```rust
3031
/// let s = String::default();
3132
/// ```
3233
#[clippy::version = "pre 1.29.0"]
@@ -47,13 +48,13 @@ declare_clippy_lint! {
4748
/// Assignments to patterns that are of tuple type are not linted.
4849
///
4950
/// ### Example
50-
/// Bad:
5151
/// ```
5252
/// # #[derive(Default)]
5353
/// # struct A { i: i32 }
5454
/// let mut a: A = Default::default();
5555
/// a.i = 42;
5656
/// ```
57+
///
5758
/// Use instead:
5859
/// ```
5960
/// # #[derive(Default)]

clippy_lints/src/dereference.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,14 @@ declare_clippy_lint! {
3030
/// let a: &mut String = &mut String::from("foo");
3131
/// let b: &str = a.deref();
3232
/// ```
33-
/// Could be written as:
33+
///
34+
/// Use instead:
3435
/// ```rust
3536
/// let a: &mut String = &mut String::from("foo");
3637
/// let b = &*a;
3738
/// ```
3839
///
39-
/// This lint excludes
40+
/// This lint excludes:
4041
/// ```rust,ignore
4142
/// let _ = d.unwrap().deref();
4243
/// ```
@@ -59,11 +60,13 @@ declare_clippy_lint! {
5960
/// ```rust
6061
/// fn fun(_a: &i32) {}
6162
///
62-
/// // Bad
6363
/// let x: &i32 = &&&&&&5;
6464
/// fun(&x);
65+
/// ```
6566
///
66-
/// // Good
67+
/// Use instead:
68+
/// ```rust
69+
/// # fn fun(_a: &i32) {}
6770
/// let x: &i32 = &5;
6871
/// fun(x);
6972
/// ```
@@ -82,13 +85,14 @@ declare_clippy_lint! {
8285
///
8386
/// ### Example
8487
/// ```rust
85-
/// // Bad
8688
/// let x = Some("");
8789
/// if let Some(ref x) = x {
8890
/// // use `x` here
8991
/// }
92+
/// ```
9093
///
91-
/// // Good
94+
/// Use instead:
95+
/// ```rust
9296
/// let x = Some("");
9397
/// if let Some(x) = x {
9498
/// // use `&x` here

clippy_lints/src/derivable_impls.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@ declare_clippy_lint! {
3030
/// }
3131
/// ```
3232
///
33-
/// Could be written as:
34-
///
33+
/// Use instead:
3534
/// ```rust
3635
/// #[derive(Default)]
3736
/// struct Foo {
@@ -45,7 +44,6 @@ declare_clippy_lint! {
4544
/// specialized than what derive will produce. This lint can't detect the manual `impl`
4645
/// has exactly equal bounds, and therefore this lint is disabled for types with
4746
/// generic parameters.
48-
///
4947
#[clippy::version = "1.57.0"]
5048
pub DERIVABLE_IMPLS,
5149
complexity,

clippy_lints/src/enum_variants.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ declare_clippy_lint! {
6060
/// struct BlackForestCake;
6161
/// }
6262
/// ```
63-
/// Could be written as:
63+
///
64+
/// Use instead:
6465
/// ```rust
6566
/// mod cake {
6667
/// struct BlackForest;

clippy_lints/src/eq_op.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,13 @@ declare_clippy_lint! {
5252
/// ### Why is this bad?
5353
/// It is more idiomatic to dereference the other argument.
5454
///
55-
/// ### Known problems
56-
/// None
57-
///
5855
/// ### Example
59-
/// ```ignore
60-
/// // Bad
56+
/// ```rust,ignore
6157
/// &x == y
58+
/// ```
6259
///
63-
/// // Good
60+
/// Use instead:
61+
/// ```rust,ignore
6462
/// x == *y
6563
/// ```
6664
#[clippy::version = "pre 1.29.0"]

clippy_lints/src/eta_reduction.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,14 @@ declare_clippy_lint! {
3434
///
3535
/// ### Example
3636
/// ```rust,ignore
37-
/// // Bad
3837
/// xs.map(|x| foo(x))
38+
/// ```
3939
///
40-
/// // Good
40+
/// Use instead:
41+
/// ```rust,ignore
42+
/// // where `foo(_)` is a plain function that takes the exact argument type of `x`.
4143
/// xs.map(foo)
4244
/// ```
43-
/// where `foo(_)` is a plain function that takes the exact argument type of
44-
/// `x`.
4545
#[clippy::version = "pre 1.29.0"]
4646
pub REDUNDANT_CLOSURE,
4747
style,

clippy_lints/src/excessive_bools.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,11 @@ declare_clippy_lint! {
5454
/// API easier to use.
5555
///
5656
/// ### Example
57-
/// Bad:
5857
/// ```rust,ignore
5958
/// fn f(is_round: bool, is_hot: bool) { ... }
6059
/// ```
6160
///
62-
/// Good:
61+
/// Use instead:
6362
/// ```rust,ignore
6463
/// enum Shape {
6564
/// Round,

clippy_lints/src/float_literal.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,11 @@ declare_clippy_lint! {
4545
///
4646
/// ### Example
4747
/// ```rust
48-
/// // Bad
4948
/// let _: f32 = 16_777_217.0; // 16_777_216.0
49+
/// ```
5050
///
51-
/// // Good
51+
/// Use instead:
52+
/// ```rust
5253
/// let _: f32 = 16_777_216.0;
5354
/// let _: f64 = 16_777_217.0;
5455
/// ```

clippy_lints/src/functions/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,13 @@ declare_clippy_lint! {
7676
///
7777
/// ### Example
7878
/// ```rust,ignore
79-
/// // Bad
8079
/// pub fn foo(x: *const u8) {
8180
/// println!("{}", unsafe { *x });
8281
/// }
82+
/// ```
8383
///
84-
/// // Good
84+
/// Use instead:
85+
/// ```rust,ignore
8586
/// pub unsafe fn foo(x: *const u8) {
8687
/// println!("{}", unsafe { *x });
8788
/// }

clippy_lints/src/get_first.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,12 @@ declare_clippy_lint! {
2020
///
2121
/// ### Example
2222
/// ```rust
23-
/// // Bad
2423
/// let x = vec![2, 3, 5];
2524
/// let first_element = x.get(0);
2625
/// ```
26+
///
2727
/// Use instead:
2828
/// ```rust
29-
/// // Good
3029
/// let x = vec![2, 3, 5];
3130
/// let first_element = x.first();
3231
/// ```

0 commit comments

Comments
 (0)