Skip to content

Commit caa76e1

Browse files
committed
Improve docs
1 parent 26fdd3f commit caa76e1

Some content is hidden

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

55 files changed

+666
-237
lines changed

clippy_lints/src/approx_const.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ use utils::span_lint;
1010
///
1111
/// **Known problems:** If you happen to have a value that is within 1/8192 of a known constant, but is not *and should not* be the same, this lint will report your value anyway. We have not yet noticed any false positives in code we tested clippy with (this includes servo), but YMMV.
1212
///
13-
/// **Example:** `let x = 3.14;`
13+
/// **Example:**
14+
/// ```rust
15+
/// let x = 3.14;
16+
/// ```
1417
declare_lint! {
1518
pub APPROX_CONSTANT,
1619
Warn,

clippy_lints/src/arithmetic.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use utils::span_lint;
1212
/// **Known problems:** None
1313
///
1414
/// **Example:**
15-
/// ```
15+
/// ```rust
1616
/// a + 1
1717
/// ```
1818
declare_restriction_lint! {
@@ -28,7 +28,7 @@ declare_restriction_lint! {
2828
/// **Known problems:** None
2929
///
3030
/// **Example:**
31-
/// ```
31+
/// ```rust
3232
/// a + 1.0
3333
/// ```
3434
declare_restriction_lint! {

clippy_lints/src/array_indexing.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use utils::{self, higher};
1616
///
1717
/// **Example:**
1818
///
19-
/// ```
19+
/// ```rust
2020
/// let x = [1,2,3,4];
2121
/// ...
2222
/// x[9];
@@ -38,7 +38,7 @@ declare_lint! {
3838
///
3939
/// **Example:**
4040
///
41-
/// ```
41+
/// ```rust
4242
/// ...
4343
/// x[2];
4444
/// &x[0..2];

clippy_lints/src/assign_ops.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use utils::{higher, sugg};
1111
/// **Known problems:** Types implementing `OpAssign` don't necessarily implement `Op`.
1212
///
1313
/// **Example:**
14-
/// ```
14+
/// ```rust
1515
/// a += 1;
1616
/// ```
1717
declare_restriction_lint! {
@@ -27,7 +27,7 @@ declare_restriction_lint! {
2727
///
2828
/// **Example:**
2929
///
30-
/// ```
30+
/// ```rust
3131
/// let mut a = 5;
3232
/// ...
3333
/// a = a + b;

clippy_lints/src/attrs.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use utils::paths;
1818
/// **Known problems:** False positives, big time. This lint is meant to be deactivated by everyone doing serious performance work. This means having done the measurement.
1919
///
2020
/// **Example:**
21-
/// ```
21+
/// ```rust
2222
/// #[inline(always)]
2323
/// fn not_quite_hot_code(..) { ... }
2424
/// ```
@@ -34,7 +34,7 @@ declare_lint! {
3434
/// **Known problems:** None
3535
///
3636
/// **Example:**
37-
/// ```
37+
/// ```rust
3838
/// #[deprecated(since = "forever")]
3939
/// fn something_else(..) { ... }
4040
/// ```

clippy_lints/src/bit_mask.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@ use utils::span_lint;
2626
///
2727
/// **Known problems:** None
2828
///
29-
/// **Example:** `x & 1 == 2` (also see table above)
29+
/// **Example:**
30+
/// ```rust
31+
/// if (x & 1 == 2) { … }
32+
/// ```
3033
declare_lint! {
3134
pub BAD_BIT_MASK,
3235
Warn,
@@ -45,7 +48,10 @@ declare_lint! {
4548
///
4649
/// **Known problems:** False negatives: This lint will only match instances where we have figured out the math (which is for a power-of-two compared value). This means things like `x | 1 >= 7` (which would be better written as `x >= 6`) will not be reported (but bit masks like this are fairly uncommon).
4750
///
48-
/// **Example:** `x | 1 > 3` (also see table above)
51+
/// **Example:**
52+
/// ```rust
53+
/// if (x | 1 > 3) { … }
54+
/// ```
4955
declare_lint! {
5056
pub INEFFECTIVE_BIT_MASK,
5157
Warn,

clippy_lints/src/blacklisted_name.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ use utils::span_lint;
88
///
99
/// **Known problems:** None.
1010
///
11-
/// **Example:** `let foo = 3.14;`
11+
/// **Example:**
12+
/// ```rust
13+
/// let foo = 3.14;
14+
/// ```
1215
declare_lint! {
1316
pub BLACKLISTED_NAME,
1417
Warn,

clippy_lints/src/block_in_if_condition.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ use utils::*;
99
///
1010
/// **Known problems:** None
1111
///
12-
/// **Example:** `if { true } ..`
12+
/// **Example:**
13+
/// ```rust
14+
/// if { true } ..
15+
/// ```
1316
declare_lint! {
1417
pub BLOCK_IN_IF_CONDITION_EXPR, Warn,
1518
"braces can be eliminated in conditions that are expressions, e.g `if { true } ...`"
@@ -21,7 +24,12 @@ declare_lint! {
2124
///
2225
/// **Known problems:** None
2326
///
24-
/// **Example:** `if { let x = somefunc(); x } ..` or `if somefunc(|x| { x == 47 }) ..`
27+
/// **Example:**
28+
/// ```rust
29+
/// if { let x = somefunc(); x } ..
30+
/// // or
31+
/// if somefunc(|x| { x == 47 }) ..
32+
/// ```
2533
declare_lint! {
2634
pub BLOCK_IN_IF_CONDITION_STMT, Warn,
2735
"avoid complex blocks in conditions, instead move the block higher and bind it \

clippy_lints/src/booleans.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,23 @@ use syntax::codemap::{DUMMY_SP, dummy_spanned};
66
use syntax::util::ThinVec;
77
use utils::{span_lint_and_then, in_macro, snippet_opt, SpanlessEq};
88

9-
/// **What it does:** This lint checks for boolean expressions that can be written more concisely
9+
/// **What it does:** This lint checks for boolean expressions that can be written more concisely.
1010
///
11-
/// **Why is this bad?** Readability of boolean expressions suffers from unnecesessary duplication
11+
/// **Why is this bad?** Readability of boolean expressions suffers from unnecessary duplication.
1212
///
13-
/// **Known problems:** Ignores short circuting behavior of `||` and `&&`. Ignores `|`, `&` and `^`.
13+
/// **Known problems:** Ignores short circuiting behavior of `||` and `&&`. Ignores `|`, `&` and `^`.
1414
///
1515
/// **Example:** `if a && true` should be `if a` and `!(a == b)` should be `a != b`
1616
declare_lint! {
1717
pub NONMINIMAL_BOOL, Allow,
1818
"checks for boolean expressions that can be written more concisely"
1919
}
2020

21-
/// **What it does:** This lint checks for boolean expressions that contain terminals that can be eliminated
21+
/// **What it does:** This lint checks for boolean expressions that contain terminals that can be eliminated.
2222
///
23-
/// **Why is this bad?** This is most likely a logic bug
23+
/// **Why is this bad?** This is most likely a logic bug.
2424
///
25-
/// **Known problems:** Ignores short circuiting behavior
25+
/// **Known problems:** Ignores short circuiting behavior.
2626
///
2727
/// **Example:** The `b` in `if a && b || a` is unnecessary because the expression is equivalent to `if a`
2828
declare_lint! {

clippy_lints/src/collapsible_if.rs

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,44 @@ use utils::sugg::Sugg;
2626
///
2727
/// **Known problems:** None
2828
///
29-
/// **Example:** `if x { if y { .. } }`
29+
/// **Example:**
30+
/// ```rust
31+
/// if x {
32+
/// if y {
33+
/// …
34+
/// }
35+
/// }
36+
///
37+
/// // or
38+
///
39+
/// if x {
40+
/// …
41+
/// } else {
42+
/// if y {
43+
/// …
44+
/// }
45+
/// }
46+
/// ```
47+
///
48+
/// Should be written:
49+
///
50+
/// ```rust
51+
/// if x && y {
52+
/// …
53+
/// }
54+
///
55+
/// // or
56+
///
57+
/// if x {
58+
/// …
59+
/// } else if y {
60+
/// …
61+
/// }
62+
/// ```
3063
declare_lint! {
3164
pub COLLAPSIBLE_IF,
3265
Warn,
33-
"two nested `if`-expressions can be collapsed into one, e.g. `if x { if y { foo() } }` \
34-
can be written as `if x && y { foo() }` \
35-
and an `else { if .. }` expression can be collapsed to \
36-
`else if`"
66+
"`if`s that can be collapsed (e.g. `if x { if y { … } }` and `else { if x { … } }`)"
3767
}
3868

3969
#[derive(Copy,Clone)]

clippy_lints/src/copies.rs

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,51 @@ use syntax::util::small_vector::SmallVector;
88
use utils::{SpanlessEq, SpanlessHash};
99
use utils::{get_parent_expr, in_macro, span_lint_and_then, span_note_and_lint, snippet};
1010

11-
/// **What it does:** This lint checks for consecutive `ifs` with the same condition. This lint is
12-
/// `Warn` by default.
11+
/// **What it does:** This lint checks for consecutive `ifs` with the same condition.
1312
///
1413
/// **Why is this bad?** This is probably a copy & paste error.
1514
///
1615
/// **Known problems:** Hopefully none.
1716
///
18-
/// **Example:** `if a == b { .. } else if a == b { .. }`
17+
/// **Example:**
18+
/// ```rust
19+
/// if a == b {
20+
/// …
21+
/// } else if a == b {
22+
/// …
23+
/// }
24+
/// ```
25+
///
26+
/// Note that this lint ignores all conditions with a function call as it could have side effects:
27+
///
28+
/// ```rust
29+
/// if foo() {
30+
/// …
31+
/// } else if foo() { // not linted
32+
/// …
33+
/// }
34+
/// ```
1935
declare_lint! {
2036
pub IFS_SAME_COND,
2137
Warn,
2238
"consecutive `ifs` with the same condition"
2339
}
2440

2541
/// **What it does:** This lint checks for `if/else` with the same body as the *then* part and the
26-
/// *else* part. This lint is `Warn` by default.
42+
/// *else* part.
2743
///
2844
/// **Why is this bad?** This is probably a copy & paste error.
2945
///
3046
/// **Known problems:** Hopefully none.
3147
///
32-
/// **Example:** `if .. { 42 } else { 42 }`
48+
/// **Example:**
49+
/// ```rust
50+
/// let foo = if … {
51+
/// 42
52+
/// } else {
53+
/// 42
54+
/// };
55+
/// ```
3356
declare_lint! {
3457
pub IF_SAME_THEN_ELSE,
3558
Warn,

clippy_lints/src/enum_clike.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,22 @@ use rustc_const_math::*;
66
use rustc::hir::*;
77
use utils::span_lint;
88

9-
/// **What it does:** Lints on C-like enums that are `repr(isize/usize)` and have values that don't fit into an `i32`.
9+
/// **What it does:** Lints on C-like enumerations that are `repr(isize/usize)` and have values
10+
/// that don't fit into an `i32`.
1011
///
11-
/// **Why is this bad?** This will truncate the variant value on 32bit architectures, but works fine on 64 bit.
12+
/// **Why is this bad?** This will truncate the variant value on 32 bit architectures, but works
13+
/// fine on 64 bit.
1214
///
1315
/// **Known problems:** None
1416
///
15-
/// **Example:** `#[repr(usize)] enum NonPortable { X = 0x1_0000_0000, Y = 0 }`
17+
/// **Example:**
18+
/// ```rust
19+
/// #[repr(usize)]
20+
/// enum NonPortable {
21+
/// X = 0x1_0000_0000,
22+
/// Y = 0
23+
/// }
24+
/// ```
1625
declare_lint! {
1726
pub ENUM_CLIKE_UNPORTABLE_VARIANT, Warn,
1827
"finds C-like enums that are `repr(isize/usize)` and have values that don't fit into an `i32`"

clippy_lints/src/enum_glob_use.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,16 @@ use syntax::ast::NodeId;
99
use syntax::codemap::Span;
1010
use utils::span_lint;
1111

12-
/// **What it does:** Warns when `use`ing all variants of an enum
12+
/// **What it does:** Warns when `use`ing all variants of an enumeration.
1313
///
14-
/// **Why is this bad?** It is usually better style to use the prefixed name of an enum variant, rather than importing variants
14+
/// **Why is this bad?** It is usually better style to use the prefixed name of an enumeration variant, rather than importing variants
1515
///
16-
/// **Known problems:** Old-style enums that prefix the variants are still around
16+
/// **Known problems:** Old-style enumerations that prefix the variants are still around
1717
///
18-
/// **Example:** `use std::cmp::Ordering::*;`
18+
/// **Example:**
19+
/// ```rust
20+
/// use std::cmp::Ordering::*;
21+
/// ```
1922
declare_lint! { pub ENUM_GLOB_USE, Allow,
2023
"finds use items that import all variants of an enum" }
2124

clippy_lints/src/enum_variants.rs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,21 @@ use syntax::parse::token::InternedString;
77
use utils::{span_help_and_lint, span_lint};
88
use utils::{camel_case_from, camel_case_until, in_macro};
99

10-
/// **What it does:** Warns on enum variants that are prefixed or suffixed by the same characters
10+
/// **What it does:** Warns on enumeration variants that are prefixed or suffixed by the same
11+
/// characters.
1112
///
12-
/// **Why is this bad?** Enum variant names should specify their variant, not the enum, too.
13+
/// **Why is this bad?** Enumeration variant names should specify their variant, not repeat the
14+
/// enumeration name.
1315
///
1416
/// **Known problems:** None
1517
///
16-
/// **Example:** enum Cake { BlackForestCake, HummingbirdCake }
18+
/// **Example:**
19+
/// ```rust
20+
/// enum Cake {
21+
/// BlackForestCake,
22+
/// HummingbirdCake,
23+
/// }
24+
/// ```
1725
declare_lint! {
1826
pub ENUM_VARIANT_NAMES, Warn,
1927
"finds enums where all variants share a prefix/postfix"
@@ -25,7 +33,12 @@ declare_lint! {
2533
///
2634
/// **Known problems:** None
2735
///
28-
/// **Example:** mod cake { struct BlackForestCake; }
36+
/// **Example:**
37+
/// ```rust
38+
/// mod cake {
39+
/// struct BlackForestCake;
40+
/// }
41+
/// ```
2942
declare_lint! {
3043
pub STUTTER, Allow,
3144
"finds type names prefixed/postfixed with their containing module's name"

clippy_lints/src/eq_op.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,15 @@ use utils::{SpanlessEq, span_lint};
88
///
99
/// **Why is this bad?** This is usually just a typo or a copy and paste error.
1010
///
11-
/// **Known problems:** False negatives: We had some false positives regarding calls (notably [racer](https://github.com/phildawes/racer) had one instance of `x.pop() && x.pop()`), so we removed matching any function or method calls. We may introduce a whitelist of known pure functions in the future.
11+
/// **Known problems:** False negatives: We had some false positives regarding calls (notably
12+
/// [racer](https://github.com/phildawes/racer) had one instance of `x.pop() && x.pop()`), so we
13+
/// removed matching any function or method calls. We may introduce a whitelist of known pure
14+
/// functions in the future.
1215
///
13-
/// **Example:** `x + 1 == x + 1`
16+
/// **Example:**
17+
/// ```rust
18+
/// x + 1 == x + 1
19+
/// ```
1420
declare_lint! {
1521
pub EQ_OP,
1622
Warn,

clippy_lints/src/escape.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ pub struct Pass {
1919

2020
/// **What it does:** This lint checks for usage of `Box<T>` where an unboxed `T` would work fine.
2121
///
22-
/// **Why is this bad?** This is an unnecessary allocation, and bad for performance. It is only necessary to allocate if you wish to move the box into something.
22+
/// **Why is this bad?** This is an unnecessary allocation, and bad for performance. It is only
23+
/// necessary to allocate if you wish to move the box into something.
2324
///
2425
/// **Known problems:** None
2526
///

0 commit comments

Comments
 (0)