Skip to content

Commit cdfa8e9

Browse files
authored
Merge pull request #1146 from birkenfeld/housekeeping
Some housekeeping on lint descriptions
2 parents 74c7880 + 9a22140 commit cdfa8e9

Some content is hidden

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

79 files changed

+1416
-1169
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ out
77
*.so
88
*.rlib
99
*.dll
10+
*.pyc
1011

1112
# Executables
1213
*.exe

CONTRIBUTING.md

+7-4
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,16 @@ travis build actually checks for this.
4242

4343
Also please document your lint with a doc comment akin to the following:
4444
```rust
45-
/// **What it does:** Describe what the lint matches.
45+
/// **What it does:** Checks for ... (describe what the lint matches).
4646
///
47-
/// **Why is this bad?** Write the reason for linting the code.
47+
/// **Why is this bad?** Supply the reason for linting the code.
4848
///
49-
/// **Known problems:** Hopefully none.
49+
/// **Known problems:** None. (Or describe where it could go wrong.)
5050
///
51-
/// **Example:** Insert a short example if you have one
51+
/// **Example:**
52+
/// ```rust
53+
/// Insert a short example if you have one.
54+
/// ```
5255
```
5356

5457
Our `util/update_wiki.py` script can then add your lint docs to the wiki.

README.md

+70-70
Large diffs are not rendered by default.

clippy_lints/src/approx_const.rs

+17-6
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,22 @@ use std::f64::consts as f64;
44
use syntax::ast::{Lit, LitKind, FloatTy};
55
use utils::span_lint;
66

7-
/// **What it does:** This lint checks for floating point literals that approximate constants which are defined in [`std::f32::consts`](https://doc.rust-lang.org/stable/std/f32/consts/#constants) or [`std::f64::consts`](https://doc.rust-lang.org/stable/std/f64/consts/#constants), respectively, suggesting to use the predefined constant.
7+
/// **What it does:** Checks for floating point literals that approximate
8+
/// constants which are defined in
9+
/// [`std::f32::consts`](https://doc.rust-lang.org/stable/std/f32/consts/#constants)
10+
/// or
11+
/// [`std::f64::consts`](https://doc.rust-lang.org/stable/std/f64/consts/#constants),
12+
/// respectively, suggesting to use the predefined constant.
813
///
9-
/// **Why is this bad?** Usually, the definition in the standard library is more precise than what people come up with. If you find that your definition is actually more precise, please [file a Rust issue](https://github.com/rust-lang/rust/issues).
14+
/// **Why is this bad?** Usually, the definition in the standard library is more
15+
/// precise than what people come up with. If you find that your definition is
16+
/// actually more precise, please [file a Rust
17+
/// issue](https://github.com/rust-lang/rust/issues).
1018
///
11-
/// **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.
19+
/// **Known problems:** If you happen to have a value that is within 1/8192 of a
20+
/// known constant, but is not *and should not* be the same, this lint will
21+
/// report your value anyway. We have not yet noticed any false positives in
22+
/// code we tested clippy with (this includes servo), but YMMV.
1223
///
1324
/// **Example:**
1425
/// ```rust
@@ -17,8 +28,7 @@ use utils::span_lint;
1728
declare_lint! {
1829
pub APPROX_CONSTANT,
1930
Warn,
20-
"the approximate of a known float constant (in `std::f64::consts` or `std::f32::consts`) \
21-
is found; suggests to use the constant"
31+
"the approximate of a known float constant (in `std::fXX::consts`)"
2232
}
2333

2434
// Tuples are of the form (constant, name, min_digits)
@@ -72,7 +82,8 @@ fn check_known_consts(cx: &LateContext, e: &Expr, s: &str, module: &str) {
7282
span_lint(cx,
7383
APPROX_CONSTANT,
7484
e.span,
75-
&format!("approximate value of `{}::consts::{}` found. Consider using it directly", module, &name));
85+
&format!("approximate value of `{}::consts::{}` found. \
86+
Consider using it directly", module, &name));
7687
return;
7788
}
7889
}

clippy_lints/src/arithmetic.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -3,37 +3,37 @@ use rustc::lint::*;
33
use syntax::codemap::Span;
44
use utils::span_lint;
55

6-
/// **What it does:** This lint checks for plain integer arithmetic
6+
/// **What it does:** Checks for plain integer arithmetic.
77
///
88
/// **Why is this bad?** This is only checked against overflow in debug builds.
99
/// In some applications one wants explicitly checked, wrapping or saturating
1010
/// arithmetic.
1111
///
12-
/// **Known problems:** None
12+
/// **Known problems:** None.
1313
///
1414
/// **Example:**
1515
/// ```rust
1616
/// a + 1
1717
/// ```
1818
declare_restriction_lint! {
1919
pub INTEGER_ARITHMETIC,
20-
"Any integer arithmetic statement"
20+
"any integer arithmetic statement"
2121
}
2222

23-
/// **What it does:** This lint checks for float arithmetic
23+
/// **What it does:** Checks for float arithmetic.
2424
///
2525
/// **Why is this bad?** For some embedded systems or kernel development, it
26-
/// can be useful to rule out floating-point numbers
26+
/// can be useful to rule out floating-point numbers.
2727
///
28-
/// **Known problems:** None
28+
/// **Known problems:** None.
2929
///
3030
/// **Example:**
3131
/// ```rust
3232
/// a + 1.0
3333
/// ```
3434
declare_restriction_lint! {
3535
pub FLOAT_ARITHMETIC,
36-
"Any floating-point arithmetic statement"
36+
"any floating-point arithmetic statement"
3737
}
3838

3939
#[derive(Copy, Clone, Default)]

clippy_lints/src/array_indexing.rs

+7-10
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,13 @@ use rustc::hir::*;
88
use syntax::ast::RangeLimits;
99
use utils::{self, higher};
1010

11-
/// **What it does:** Check for out of bounds array indexing with a constant index.
11+
/// **What it does:** Checks for out of bounds array indexing with a constant index.
1212
///
1313
/// **Why is this bad?** This will always panic at runtime.
1414
///
1515
/// **Known problems:** Hopefully none.
1616
///
1717
/// **Example:**
18-
///
1918
/// ```rust
2019
/// let x = [1,2,3,4];
2120
/// ...
@@ -25,27 +24,25 @@ use utils::{self, higher};
2524
declare_lint! {
2625
pub OUT_OF_BOUNDS_INDEXING,
2726
Deny,
28-
"out of bound constant indexing"
27+
"out of bounds constant indexing"
2928
}
3029

31-
/// **What it does:** Check for usage of indexing or slicing.
30+
/// **What it does:** Checks for usage of indexing or slicing.
3231
///
33-
/// **Why is this bad?** Usually, this can be safely allowed. However,
34-
/// in some domains such as kernel development, a panic can cause the
35-
/// whole operating system to crash.
32+
/// **Why is this bad?** Usually, this can be safely allowed. However, in some
33+
/// domains such as kernel development, a panic can cause the whole operating
34+
/// system to crash.
3635
///
3736
/// **Known problems:** Hopefully none.
3837
///
3938
/// **Example:**
40-
///
4139
/// ```rust
4240
/// ...
4341
/// x[2];
4442
/// &x[0..2];
4543
/// ```
46-
declare_lint! {
44+
declare_restriction_lint! {
4745
pub INDEXING_SLICING,
48-
Allow,
4946
"indexing/slicing usage"
5047
}
5148

clippy_lints/src/assign_ops.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ use rustc::lint::*;
33
use utils::{span_lint_and_then, snippet_opt, SpanlessEq, get_trait_def_id, implements_trait};
44
use utils::{higher, sugg};
55

6-
/// **What it does:** This lint checks for `+=` operations and similar.
6+
/// **What it does:** Checks for compound assignment operations (`+=` and similar).
77
///
8-
/// **Why is this bad?** Projects with many developers from languages without those operations may
9-
/// find them unreadable and not worth their weight.
8+
/// **Why is this bad?** Projects with many developers from languages without
9+
/// those operations may find them unreadable and not worth their weight.
1010
///
1111
/// **Known problems:** Types implementing `OpAssign` don't necessarily implement `Op`.
1212
///
@@ -16,17 +16,17 @@ use utils::{higher, sugg};
1616
/// ```
1717
declare_restriction_lint! {
1818
pub ASSIGN_OPS,
19-
"any assignment operation"
19+
"any compound assignment operation"
2020
}
2121

22-
/// **What it does:** Check for `a = a op b` or `a = b commutative_op a` patterns.
22+
/// **What it does:** Checks for `a = a op b` or `a = b commutative_op a` patterns.
2323
///
2424
/// **Why is this bad?** These can be written as the shorter `a op= b`.
2525
///
26-
/// **Known problems:** While forbidden by the spec, `OpAssign` traits may have implementations that differ from the regular `Op` impl.
26+
/// **Known problems:** While forbidden by the spec, `OpAssign` traits may have
27+
/// implementations that differ from the regular `Op` impl.
2728
///
2829
/// **Example:**
29-
///
3030
/// ```rust
3131
/// let mut a = 5;
3232
/// ...
@@ -38,14 +38,14 @@ declare_lint! {
3838
"assigning the result of an operation on a variable to that same variable"
3939
}
4040

41-
/// **What it does:** Check for `a op= a op b` or `a op= b op a` patterns.
41+
/// **What it does:** Checks for `a op= a op b` or `a op= b op a` patterns.
4242
///
43-
/// **Why is this bad?** Most likely these are bugs where one meant to write `a op= b`
43+
/// **Why is this bad?** Most likely these are bugs where one meant to write `a op= b`.
4444
///
45-
/// **Known problems:** Someone might actually mean `a op= a op b`, but that should rather be written as `a = (2 * a) op b` where applicable.
45+
/// **Known problems:** Someone might actually mean `a op= a op b`, but that
46+
/// should rather be written as `a = (2 * a) op b` where applicable.
4647
///
4748
/// **Example:**
48-
///
4949
/// ```rust
5050
/// let mut a = 5;
5151
/// ...

clippy_lints/src/attrs.rs

+22-11
Original file line numberDiff line numberDiff line change
@@ -9,38 +9,49 @@ use syntax::codemap::Span;
99
use utils::{in_macro, match_path, span_lint};
1010
use utils::paths;
1111

12-
/// **What it does:** This lint checks for items annotated with `#[inline(always)]`, unless the annotated function is empty or simply panics.
12+
/// **What it does:** Checks for items annotated with `#[inline(always)]`,
13+
/// unless the annotated function is empty or simply panics.
1314
///
14-
/// **Why is this bad?** While there are valid uses of this annotation (and once you know when to use it, by all means `allow` this lint), it's a common newbie-mistake to pepper one's code with it.
15+
/// **Why is this bad?** While there are valid uses of this annotation (and once
16+
/// you know when to use it, by all means `allow` this lint), it's a common
17+
/// newbie-mistake to pepper one's code with it.
1518
///
16-
/// As a rule of thumb, before slapping `#[inline(always)]` on a function, measure if that additional function call really affects your runtime profile sufficiently to make up for the increase in compile time.
19+
/// As a rule of thumb, before slapping `#[inline(always)]` on a function,
20+
/// measure if that additional function call really affects your runtime profile
21+
/// sufficiently to make up for the increase in compile time.
1722
///
18-
/// **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.
23+
/// **Known problems:** False positives, big time. This lint is meant to be
24+
/// deactivated by everyone doing serious performance work. This means having
25+
/// done the measurement.
1926
///
2027
/// **Example:**
2128
/// ```rust
2229
/// #[inline(always)]
2330
/// fn not_quite_hot_code(..) { ... }
2431
/// ```
2532
declare_lint! {
26-
pub INLINE_ALWAYS, Warn,
27-
"`#[inline(always)]` is a bad idea in most cases"
33+
pub INLINE_ALWAYS,
34+
Warn,
35+
"use of `#[inline(always)]`"
2836
}
2937

30-
/// **What it does:** This lint checks for `#[deprecated]` annotations with a `since` field that is not a valid semantic version..
38+
/// **What it does:** Checks for `#[deprecated]` annotations with a `since`
39+
/// field that is not a valid semantic version.
3140
///
32-
/// **Why is this bad?** For checking the version of the deprecation, it must be valid semver. Failing that, the contained information is useless.
41+
/// **Why is this bad?** For checking the version of the deprecation, it must be
42+
/// a valid semver. Failing that, the contained information is useless.
3343
///
34-
/// **Known problems:** None
44+
/// **Known problems:** None.
3545
///
3646
/// **Example:**
3747
/// ```rust
3848
/// #[deprecated(since = "forever")]
3949
/// fn something_else(..) { ... }
4050
/// ```
4151
declare_lint! {
42-
pub DEPRECATED_SEMVER, Warn,
43-
"`Warn` on `#[deprecated(since = \"x\")]` where x is not semver"
52+
pub DEPRECATED_SEMVER,
53+
Warn,
54+
"use of `#[deprecated(since = \"x\")]` where x is not semver"
4455
}
4556

4657
#[derive(Copy,Clone)]

clippy_lints/src/bit_mask.rs

+23-37
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@ use syntax::ast::LitKind;
66
use syntax::codemap::Span;
77
use utils::span_lint;
88

9-
/// **What it does:** This lint checks for incompatible bit masks in comparisons.
9+
/// **What it does:** Checks for incompatible bit masks in comparisons.
1010
///
11-
/// The formula for detecting if an expression of the type `_ <bit_op> m <cmp_op> c` (where `<bit_op>`
12-
/// is one of {`&`, `|`} and `<cmp_op>` is one of {`!=`, `>=`, `>`, `!=`, `>=`, `>`}) can be determined from the following table:
11+
/// The formula for detecting if an expression of the type `_ <bit_op> m
12+
/// <cmp_op> c` (where `<bit_op>` is one of {`&`, `|`} and `<cmp_op>` is one of
13+
/// {`!=`, `>=`, `>`, `!=`, `>=`, `>`}) can be determined from the following
14+
/// table:
1315
///
1416
/// |Comparison |Bit Op|Example |is always|Formula |
1517
/// |------------|------|------------|---------|----------------------|
@@ -20,11 +22,15 @@ use utils::span_lint;
2022
/// |`<` or `>=`| `|` |`x | 1 < 1` |`false` |`m >= c` |
2123
/// |`<=` or `>` | `|` |`x | 1 > 0` |`true` |`m > c` |
2224
///
23-
/// **Why is this bad?** If the bits that the comparison cares about are always set to zero or one by the bit mask, the comparison is constant `true` or `false` (depending on mask, compared value, and operators).
25+
/// **Why is this bad?** If the bits that the comparison cares about are always
26+
/// set to zero or one by the bit mask, the comparison is constant `true` or
27+
/// `false` (depending on mask, compared value, and operators).
2428
///
25-
/// So the code is actively misleading, and the only reason someone would write this intentionally is to win an underhanded Rust contest or create a test-case for this lint.
29+
/// So the code is actively misleading, and the only reason someone would write
30+
/// this intentionally is to win an underhanded Rust contest or create a
31+
/// test-case for this lint.
2632
///
27-
/// **Known problems:** None
33+
/// **Known problems:** None.
2834
///
2935
/// **Example:**
3036
/// ```rust
@@ -33,20 +39,26 @@ use utils::span_lint;
3339
declare_lint! {
3440
pub BAD_BIT_MASK,
3541
Warn,
36-
"expressions of the form `_ & mask == select` that will only ever return `true` or `false` \
37-
(because in the example `select` containing bits that `mask` doesn't have)"
42+
"expressions of the form `_ & mask == select` that will only ever return `true` or `false`"
3843
}
3944

40-
/// **What it does:** This lint checks for bit masks in comparisons which can be removed without changing the outcome. The basic structure can be seen in the following table:
45+
/// **What it does:** Checks for bit masks in comparisons which can be removed
46+
/// without changing the outcome. The basic structure can be seen in the
47+
/// following table:
4148
///
4249
/// |Comparison| Bit Op |Example |equals |
4350
/// |----------|---------|-----------|-------|
4451
/// |`>` / `<=`|`|` / `^`|`x | 2 > 3`|`x > 3`|
4552
/// |`<` / `>=`|`|` / `^`|`x ^ 1 < 4`|`x < 4`|
4653
///
47-
/// **Why is this bad?** Not equally evil as [`bad_bit_mask`](#bad_bit_mask), but still a bit misleading, because the bit mask is ineffective.
54+
/// **Why is this bad?** Not equally evil as [`bad_bit_mask`](#bad_bit_mask),
55+
/// but still a bit misleading, because the bit mask is ineffective.
4856
///
49-
/// **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).
57+
/// **Known problems:** False negatives: This lint will only match instances
58+
/// where we have figured out the math (which is for a power-of-two compared
59+
/// value). This means things like `x | 1 >= 7` (which would be better written
60+
/// as `x >= 6`) will not be reported (but bit masks like this are fairly
61+
/// uncommon).
5062
///
5163
/// **Example:**
5264
/// ```rust
@@ -58,32 +70,6 @@ declare_lint! {
5870
"expressions where a bit mask will be rendered useless by a comparison, e.g. `(x | 1) > 2`"
5971
}
6072

61-
/// Checks for incompatible bit masks in comparisons, e.g. `x & 1 == 2`.
62-
/// This cannot work because the bit that makes up the value two was
63-
/// zeroed out by the bit-and with 1. So the formula for detecting if an
64-
/// expression of the type `_ <bit_op> m <cmp_op> c` (where `<bit_op>`
65-
/// is one of {`&`, '|'} and `<cmp_op>` is one of {`!=`, `>=`, `>` ,
66-
/// `!=`, `>=`, `>`}) can be determined from the following table:
67-
///
68-
/// |Comparison |Bit Op|Example |is always|Formula |
69-
/// |------------|------|------------|---------|----------------------|
70-
/// |`==` or `!=`| `&` |`x & 2 == 3`|`false` |`c & m != c` |
71-
/// |`<` or `>=`| `&` |`x & 2 < 3` |`true` |`m < c` |
72-
/// |`>` or `<=`| `&` |`x & 1 > 1` |`false` |`m <= c` |
73-
/// |`==` or `!=`| `|` |`x | 1 == 0`|`false` |`c | m != c` |
74-
/// |`<` or `>=`| `|` |`x | 1 < 1` |`false` |`m >= c` |
75-
/// |`<=` or `>` | `|` |`x | 1 > 0` |`true` |`m > c` |
76-
///
77-
/// This lint is **deny** by default
78-
///
79-
/// There is also a lint that warns on ineffective masks that is *warn*
80-
/// by default.
81-
///
82-
/// |Comparison|Bit Op |Example |equals |Formula|
83-
/// |`>` / `<=`|`|` / `^`|`x | 2 > 3`|`x > 3`|`¹ && m <= c`|
84-
/// |`<` / `>=`|`|` / `^`|`x ^ 1 < 4`|`x < 4`|`¹ && m < c` |
85-
///
86-
/// `¹ power_of_two(c + 1)`
8773
#[derive(Copy,Clone)]
8874
pub struct BitMask;
8975

clippy_lints/src/blacklisted_name.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@ use rustc::lint::*;
22
use rustc::hir::*;
33
use utils::span_lint;
44

5-
/// **What it does:** This lints about usage of blacklisted names.
5+
/// **What it does:** Checks for usage of blacklisted names for variables, such
6+
/// as `foo`.
67
///
7-
/// **Why is this bad?** These names are usually placeholder names and should be avoided.
8+
/// **Why is this bad?** These names are usually placeholder names and should be
9+
/// avoided.
810
///
911
/// **Known problems:** None.
1012
///

0 commit comments

Comments
 (0)