Skip to content

Commit cfd0f55

Browse files
committed
Make docs more consistent
1 parent 5920fa3 commit cfd0f55

29 files changed

+109
-68
lines changed

clippy_lints/src/approx_const.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ declare_clippy_lint! {
2828
/// let x = 3.14;
2929
/// let y = 1_f64 / x;
3030
/// ```
31-
/// Use predefined constants instead:
31+
/// Use instead:
3232
/// ```rust
3333
/// let x = std::f32::consts::PI;
3434
/// let y = std::f64::consts::FRAC_1_PI;

clippy_lints/src/as_conversions.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ declare_clippy_lint! {
2929
/// f(a as u16);
3030
/// ```
3131
///
32-
/// Usually better represents the semantics you expect:
32+
/// Use instead:
3333
/// ```rust,ignore
3434
/// f(a.try_into()?);
3535
/// ```

clippy_lints/src/assign_ops.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,16 @@ declare_clippy_lint! {
2727
/// let mut a = 5;
2828
/// let b = 0;
2929
/// // ...
30-
/// // Bad
30+
///
3131
/// a = a + b;
32+
/// ```
33+
///
34+
/// Use instead:
35+
/// ```rust
36+
/// let mut a = 5;
37+
/// let b = 0;
38+
/// // ...
3239
///
33-
/// // Good
3440
/// a += b;
3541
/// ```
3642
#[clippy::version = "pre 1.29.0"]

clippy_lints/src/attrs.rs

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,14 @@ declare_clippy_lint! {
8989
///
9090
/// ### Example
9191
/// ```ignore
92-
/// // Bad
9392
/// #[deny(dead_code)]
9493
/// extern crate foo;
9594
/// #[forbid(dead_code)]
9695
/// use foo::bar;
96+
/// ```
9797
///
98-
/// // Ok
98+
/// Use instead:
99+
/// ```rust,ignore
99100
/// #[allow(unused_imports)]
100101
/// use foo::baz;
101102
/// #[allow(unused_imports)]
@@ -146,15 +147,19 @@ declare_clippy_lint! {
146147
///
147148
/// ### Example
148149
/// ```rust
150+
/// #[allow(dead_code)]
151+
///
152+
/// fn not_quite_good_code() { }
153+
/// ```
154+
///
155+
/// Use instead:
156+
/// ```rust
149157
/// // Good (as inner attribute)
150158
/// #![allow(dead_code)]
151159
///
152160
/// fn this_is_fine() { }
153161
///
154-
/// // Bad
155-
/// #[allow(dead_code)]
156-
///
157-
/// fn not_quite_good_code() { }
162+
/// // or
158163
///
159164
/// // Good (as outer attribute)
160165
/// #[allow(dead_code)]
@@ -175,12 +180,11 @@ declare_clippy_lint! {
175180
/// These lints should only be enabled on a lint-by-lint basis and with careful consideration.
176181
///
177182
/// ### Example
178-
/// Bad:
179183
/// ```rust
180184
/// #![deny(clippy::restriction)]
181185
/// ```
182186
///
183-
/// Good:
187+
/// Use instead:
184188
/// ```rust
185189
/// #![deny(clippy::as_conversions)]
186190
/// ```
@@ -205,13 +209,12 @@ declare_clippy_lint! {
205209
/// [#3123](https://github.com/rust-lang/rust-clippy/pull/3123#issuecomment-422321765)
206210
///
207211
/// ### Example
208-
/// Bad:
209212
/// ```rust
210213
/// #[cfg_attr(rustfmt, rustfmt_skip)]
211214
/// fn main() { }
212215
/// ```
213216
///
214-
/// Good:
217+
/// Use instead:
215218
/// ```rust
216219
/// #[rustfmt::skip]
217220
/// fn main() { }
@@ -231,19 +234,19 @@ declare_clippy_lint! {
231234
/// by the conditional compilation engine.
232235
///
233236
/// ### Example
234-
/// Bad:
235237
/// ```rust
236238
/// #[cfg(linux)]
237239
/// fn conditional() { }
238240
/// ```
239241
///
240-
/// Good:
242+
/// Use instead:
241243
/// ```rust
242244
/// #[cfg(target_os = "linux")]
243245
/// fn conditional() { }
244246
/// ```
245247
///
246-
/// Or:
248+
/// or
249+
///
247250
/// ```rust
248251
/// #[cfg(unix)]
249252
/// fn conditional() { }
@@ -266,14 +269,13 @@ declare_clippy_lint! {
266269
/// ensure that others understand the reasoning
267270
///
268271
/// ### Example
269-
/// Bad:
270272
/// ```rust
271273
/// #![feature(lint_reasons)]
272274
///
273275
/// #![allow(clippy::some_lint)]
274276
/// ```
275277
///
276-
/// Good:
278+
/// Use instead:
277279
/// ```rust
278280
/// #![feature(lint_reasons)]
279281
///

clippy_lints/src/blocks_in_if_conditions.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ declare_clippy_lint! {
2929
/// if true { /* ... */ }
3030
/// ```
3131
///
32-
/// // or
32+
/// or
3333
///
3434
/// ```rust
3535
/// # fn somefunc() -> bool { true };

clippy_lints/src/booleans.rs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,14 @@ declare_clippy_lint! {
2727
///
2828
/// ### Example
2929
/// ```ignore
30-
/// if a && true // should be: if a
31-
/// if !(a == b) // should be: if a != b
30+
/// if a && true {}
31+
/// if !(a == b) {}
32+
/// ```
33+
///
34+
/// Use instead:
35+
/// ```rust,ignore
36+
/// if a {}
37+
/// if a != b {}
3238
/// ```
3339
#[clippy::version = "pre 1.29.0"]
3440
pub NONMINIMAL_BOOL,
@@ -48,10 +54,15 @@ declare_clippy_lint! {
4854
/// Ignores short circuiting behavior.
4955
///
5056
/// ### Example
51-
/// ```ignore
57+
/// ```rust,ignore
58+
/// // The `b` is unnecessary, the expression is equivalent to `if a`.
5259
/// if a && b || a { ... }
5360
/// ```
54-
/// The `b` is unnecessary, the expression is equivalent to `if a`.
61+
///
62+
/// Use instead:
63+
/// ```rust,ignore
64+
/// if a {}
65+
/// ```
5566
#[clippy::version = "pre 1.29.0"]
5667
pub LOGIC_BUG,
5768
correctness,

clippy_lints/src/bytecount.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,13 @@ declare_clippy_lint! {
2828
/// ### Example
2929
/// ```rust
3030
/// # let vec = vec![1_u8];
31-
/// &vec.iter().filter(|x| **x == 0u8).count(); // use bytecount::count instead
31+
/// let count = vec.iter().filter(|x| **x == 0u8).count();
32+
/// ```
33+
///
34+
/// Use instead:
35+
/// ```rust,ignore
36+
/// # let vec = vec![1_u8];
37+
/// let count = bytecount::count(&vec, 0u8);
3238
/// ```
3339
#[clippy::version = "pre 1.29.0"]
3440
pub NAIVE_BYTECOUNT,

clippy_lints/src/cognitive_complexity.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ declare_clippy_lint! {
2525
/// complexity.
2626
///
2727
/// ### Example
28-
/// No. You'll see it when you get the warning.
28+
/// You'll see it when you get the warning.
2929
#[clippy::version = "1.35.0"]
3030
pub COGNITIVE_COMPLEXITY,
3131
nursery,

clippy_lints/src/collapsible_if.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ declare_clippy_lint! {
4141
///
4242
/// ```
4343
///
44-
/// Should be written:
44+
/// Use instead:
4545
///
4646
/// ```rust,ignore
4747
/// if x && y {

clippy_lints/src/comparison_chain.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ declare_clippy_lint! {
3434
/// }
3535
/// ```
3636
///
37-
/// Could be written:
37+
/// Use instead:
3838
///
3939
/// ```rust,ignore
4040
/// use std::cmp::Ordering;

clippy_lints/src/copies.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ declare_clippy_lint! {
141141
/// };
142142
/// ```
143143
///
144-
/// Could be written as:
144+
/// Use instead:
145145
/// ```ignore
146146
/// println!("Hello World");
147147
/// let foo = if … {

clippy_lints/src/derivable_impls.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ declare_clippy_lint! {
2121
/// bar: bool
2222
/// }
2323
///
24-
/// impl std::default::Default for Foo {
24+
/// impl Default for Foo {
2525
/// fn default() -> Self {
2626
/// Self {
2727
/// bar: false

clippy_lints/src/double_comparison.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ declare_clippy_lint! {
2424
/// if x == y || x < y {}
2525
/// ```
2626
///
27-
/// Could be written as:
27+
/// Use instead:
2828
///
2929
/// ```rust
3030
/// # let x = 1;

clippy_lints/src/duration_subsec.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,17 @@ declare_clippy_lint! {
2222
/// ### Example
2323
/// ```rust
2424
/// # use std::time::Duration;
25-
/// let dur = Duration::new(5, 0);
26-
///
27-
/// // Bad
28-
/// let _micros = dur.subsec_nanos() / 1_000;
29-
/// let _millis = dur.subsec_nanos() / 1_000_000;
25+
/// # let duration = Duration::new(5, 0);
26+
/// let micros = duration.subsec_nanos() / 1_000;
27+
/// let millis = duration.subsec_nanos() / 1_000_000;
28+
/// ```
3029
///
31-
/// // Good
32-
/// let _micros = dur.subsec_micros();
33-
/// let _millis = dur.subsec_millis();
30+
/// Use instead:
31+
/// ```rust
32+
/// # use std::time::Duration;
33+
/// # let duration = Duration::new(5, 0);
34+
/// let micros = duration.subsec_micros();
35+
/// let millis = duration.subsec_millis();
3436
/// ```
3537
#[clippy::version = "pre 1.29.0"]
3638
pub DURATION_SUBSEC,

clippy_lints/src/else_if_without_else.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ declare_clippy_lint! {
2626
/// }
2727
/// ```
2828
///
29-
/// Could be written:
29+
/// Use instead:
3030
///
3131
/// ```rust
3232
/// # fn a() {}

clippy_lints/src/empty_enum.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,11 @@ declare_clippy_lint! {
2323
///
2424
///
2525
/// ### Example
26-
/// Bad:
2726
/// ```rust
2827
/// enum Test {}
2928
/// ```
3029
///
31-
/// Good:
30+
/// Use instead:
3231
/// ```rust
3332
/// #![feature(never_type)]
3433
///

clippy_lints/src/entry.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ declare_clippy_lint! {
4646
/// map.insert(k, v);
4747
/// }
4848
/// ```
49-
/// can both be rewritten as:
49+
/// Use instead:
5050
/// ```rust
5151
/// # use std::collections::HashMap;
5252
/// # let mut map = HashMap::new();

clippy_lints/src/enum_variants.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ declare_clippy_lint! {
3232
/// BattenbergCake,
3333
/// }
3434
/// ```
35-
/// Could be written as:
35+
/// Use instead:
3636
/// ```rust
3737
/// enum Cake {
3838
/// BlackForest,

clippy_lints/src/equatable_if_let.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ declare_clippy_lint! {
2626
/// do_thing();
2727
/// }
2828
/// ```
29-
/// Should be written
29+
/// Use instead:
3030
/// ```rust,ignore
3131
/// if x == Some(2) {
3232
/// do_thing();

clippy_lints/src/escape.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,14 @@ declare_clippy_lint! {
3131
/// ### Example
3232
/// ```rust
3333
/// # fn foo(bar: usize) {}
34-
/// // Bad
3534
/// let x = Box::new(1);
3635
/// foo(*x);
3736
/// println!("{}", *x);
37+
/// ```
3838
///
39-
/// // Good
39+
/// Use instead:
40+
/// ```rust
41+
/// # fn foo(bar: usize) {}
4042
/// let x = 1;
4143
/// foo(x);
4244
/// println!("{}", x);

clippy_lints/src/excessive_bools.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ declare_clippy_lint! {
1818
/// readability and API.
1919
///
2020
/// ### Example
21-
/// Bad:
2221
/// ```rust
2322
/// struct S {
2423
/// is_pending: bool,
@@ -27,7 +26,7 @@ declare_clippy_lint! {
2726
/// }
2827
/// ```
2928
///
30-
/// Good:
29+
/// Use instead:
3130
/// ```rust
3231
/// enum S {
3332
/// Pending,

clippy_lints/src/explicit_write.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,16 @@ declare_clippy_lint! {
2121
/// ```rust
2222
/// # use std::io::Write;
2323
/// # let bar = "furchtbar";
24-
/// // this would be clearer as `eprintln!("foo: {:?}", bar);`
2524
/// writeln!(&mut std::io::stderr(), "foo: {:?}", bar).unwrap();
25+
/// writeln!(&mut std::io::stdout(), "foo: {:?}", bar).unwrap();
26+
/// ```
27+
///
28+
/// Use instead:
29+
/// ```rust
30+
/// # use std::io::Write;
31+
/// # let bar = "furchtbar";
32+
/// eprintln!("foo: {:?}", bar);
33+
/// println!("foo: {:?}", bar);
2634
/// ```
2735
#[clippy::version = "pre 1.29.0"]
2836
pub EXPLICIT_WRITE,

0 commit comments

Comments
 (0)