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)]

0 commit comments

Comments
 (0)