You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: clippy_lints/src/approx_const.rs
+17-6
Original file line number
Diff line number
Diff line change
@@ -4,11 +4,22 @@ use std::f64::consts as f64;
4
4
use syntax::ast::{Lit,LitKind,FloatTy};
5
5
use utils::span_lint;
6
6
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
/// respectively, suggesting to use the predefined constant.
8
13
///
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
/// **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.
12
23
///
13
24
/// **Example:**
14
25
/// ```rust
@@ -17,8 +28,7 @@ use utils::span_lint;
17
28
declare_lint!{
18
29
pubAPPROX_CONSTANT,
19
30
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`)"
22
32
}
23
33
24
34
// Tuples are of the form (constant, name, min_digits)
Copy file name to clipboardExpand all lines: clippy_lints/src/attrs.rs
+22-11
Original file line number
Diff line number
Diff line change
@@ -9,38 +9,49 @@ use syntax::codemap::Span;
9
9
use utils::{in_macro, match_path, span_lint};
10
10
use utils::paths;
11
11
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.
13
14
///
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.
15
18
///
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.
17
22
///
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.
19
26
///
20
27
/// **Example:**
21
28
/// ```rust
22
29
/// #[inline(always)]
23
30
/// fn not_quite_hot_code(..) { ... }
24
31
/// ```
25
32
declare_lint!{
26
-
pubINLINE_ALWAYS,Warn,
27
-
"`#[inline(always)]` is a bad idea in most cases"
33
+
pubINLINE_ALWAYS,
34
+
Warn,
35
+
"use of `#[inline(always)]`"
28
36
}
29
37
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.
31
40
///
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.
33
43
///
34
-
/// **Known problems:** None
44
+
/// **Known problems:** None.
35
45
///
36
46
/// **Example:**
37
47
/// ```rust
38
48
/// #[deprecated(since = "forever")]
39
49
/// fn something_else(..) { ... }
40
50
/// ```
41
51
declare_lint!{
42
-
pubDEPRECATED_SEMVER,Warn,
43
-
"`Warn` on `#[deprecated(since = \"x\")]` where x is not semver"
52
+
pubDEPRECATED_SEMVER,
53
+
Warn,
54
+
"use of `#[deprecated(since = \"x\")]` where x is not semver"
/// **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).
24
28
///
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.
26
32
///
27
-
/// **Known problems:** None
33
+
/// **Known problems:** None.
28
34
///
29
35
/// **Example:**
30
36
/// ```rust
@@ -33,20 +39,26 @@ use utils::span_lint;
33
39
declare_lint!{
34
40
pubBAD_BIT_MASK,
35
41
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`"
38
43
}
39
44
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:
41
48
///
42
49
/// |Comparison| Bit Op |Example |equals |
43
50
/// |----------|---------|-----------|-------|
44
51
/// |`>` / `<=`|`|` / `^`|`x | 2 > 3`|`x > 3`|
45
52
/// |`<` / `>=`|`|` / `^`|`x ^ 1 < 4`|`x < 4`|
46
53
///
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.
48
56
///
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).
50
62
///
51
63
/// **Example:**
52
64
/// ```rust
@@ -58,32 +70,6 @@ declare_lint! {
58
70
"expressions where a bit mask will be rendered useless by a comparison, e.g. `(x | 1) > 2`"
59
71
}
60
72
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:
0 commit comments