Skip to content

Commit 3bfe98d

Browse files
committed
Auto merge of #7813 - xFrednet:6492-lint-version, r=flip1995
Add Clippy version to Clippy's lint list Hey, hey, the semester is finally over, and I wanted to get back into hacking on Clippy. It has also been some time since our metadata collection monster has been feed. So, this PR adds a new attribute `clippy::version` to document which version a lint was stabilized. I considered using `git blame` but that would be very hacky and probably not accurate. I'm also thinking that this attribute can be used to have a `clippy::nightly` lint group which is allow-by-default that delays setting the actual lint group until the defined version is reached. Just something to consider regarding #6623 🙃 This PR only adds the version to 4 lints to keep it reviewable. I'll do a followup PR to add the version to other lints if the implementation is accepted 🙃 ![image](https://user-images.githubusercontent.com/17087237/137118859-0aafdfdf-7595-4289-8ba4-33d58eb6991d.png) Also, mobile approved xD ![image](https://user-images.githubusercontent.com/17087237/137118944-833cf7fb-a4a1-45d6-9af8-32c951822360.png) --- r? `@flip1995` cc: #7172 closes: #6492 changelog: [Clippy's lint list](https://rust-lang.github.io/rust-clippy/master/index.html) now displays the version a lint was added. 🎉 --- Example lint declaration after this update: ```rs declare_clippy_lint! { /// [...] /// /// ### Example /// ```rust /// // Bad /// let x = 3.14; /// // Good /// let x = std::f32::consts::PI; /// ``` #[clippy::version = "pre 1.29.0"] pub APPROX_CONSTANT, correctness, "the approximate of a known float constant (in `std::fXX::consts`)" } ```
2 parents 8389df9 + 8c45fd8 commit 3bfe98d

File tree

271 files changed

+873
-42
lines changed

Some content is hidden

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

271 files changed

+873
-42
lines changed

clippy_dev/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ opener = "0.5"
1212
regex = "1.5"
1313
shell-escape = "0.1"
1414
walkdir = "2.3"
15+
cargo_metadata = "0.14"
1516

1617
[features]
1718
deny-warnings = []

clippy_dev/src/new_lint.rs

+18-3
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,18 @@ fn to_camel_case(name: &str) -> String {
132132
.collect()
133133
}
134134

135+
fn get_stabilisation_version() -> String {
136+
let mut command = cargo_metadata::MetadataCommand::new();
137+
command.no_deps();
138+
if let Ok(metadata) = command.exec() {
139+
if let Some(pkg) = metadata.packages.iter().find(|pkg| pkg.name == "clippy") {
140+
return format!("{}.{}.0", pkg.version.minor, pkg.version.patch);
141+
}
142+
}
143+
144+
String::from("<TODO set version(see doc/adding_lints.md)>")
145+
}
146+
135147
fn get_test_file_contents(lint_name: &str, header_commands: Option<&str>) -> String {
136148
let mut contents = format!(
137149
indoc! {"
@@ -178,6 +190,7 @@ fn get_lint_file_contents(lint: &LintData<'_>, enable_msrv: bool) -> String {
178190
},
179191
};
180192

193+
let version = get_stabilisation_version();
181194
let lint_name = lint.name;
182195
let category = lint.category;
183196
let name_camel = to_camel_case(lint.name);
@@ -212,7 +225,7 @@ fn get_lint_file_contents(lint: &LintData<'_>, enable_msrv: bool) -> String {
212225
});
213226

214227
result.push_str(&format!(
215-
indoc! {"
228+
indoc! {r#"
216229
declare_clippy_lint! {{
217230
/// ### What it does
218231
///
@@ -226,11 +239,13 @@ fn get_lint_file_contents(lint: &LintData<'_>, enable_msrv: bool) -> String {
226239
/// ```rust
227240
/// // example code which does not raise clippy warning
228241
/// ```
242+
#[clippy::version = "{version}"]
229243
pub {name_upper},
230244
{category},
231-
\"default lint description\"
245+
"default lint description"
232246
}}
233-
"},
247+
"#},
248+
version = version,
234249
name_upper = name_upper,
235250
category = category,
236251
));

clippy_dev/src/update_lints.rs

+5
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ static DEC_CLIPPY_LINT_RE: SyncLazy<Regex> = SyncLazy::new(|| {
1818
r#"(?x)
1919
declare_clippy_lint!\s*[\{(]
2020
(?:\s+///.*)*
21+
(?:\s*\#\[clippy::version\s*=\s*"[^"]*"\])?
2122
\s+pub\s+(?P<name>[A-Z_][A-Z_0-9]*)\s*,\s*
2223
(?P<cat>[a-z_]+)\s*,\s*
2324
"(?P<desc>(?:[^"\\]+|\\(?s).(?-s))*)"\s*[})]
@@ -31,6 +32,7 @@ static DEC_DEPRECATED_LINT_RE: SyncLazy<Regex> = SyncLazy::new(|| {
3132
r#"(?x)
3233
declare_deprecated_lint!\s*[{(]\s*
3334
(?:\s+///.*)*
35+
(?:\s*\#\[clippy::version\s*=\s*"[^"]*"\])?
3436
\s+pub\s+(?P<name>[A-Z_][A-Z_0-9]*)\s*,\s*
3537
"(?P<desc>(?:[^"\\]+|\\(?s).(?-s))*)"\s*[})]
3638
"#,
@@ -495,20 +497,23 @@ fn test_parse_contents() {
495497
let result: Vec<Lint> = parse_contents(
496498
r#"
497499
declare_clippy_lint! {
500+
#[clippy::version = "Hello Clippy!"]
498501
pub PTR_ARG,
499502
style,
500503
"really long \
501504
text"
502505
}
503506
504507
declare_clippy_lint!{
508+
#[clippy::version = "Test version"]
505509
pub DOC_MARKDOWN,
506510
pedantic,
507511
"single line"
508512
}
509513
510514
/// some doc comment
511515
declare_deprecated_lint! {
516+
#[clippy::version = "I'm a version"]
512517
pub SHOULD_ASSERT_EQ,
513518
"`assert!()` will be more flexible with RFC 2011"
514519
}

clippy_lints/src/absurd_extreme_comparisons.rs

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ declare_clippy_lint! {
3636
/// if vec.len() <= 0 {}
3737
/// if 100 > i32::MAX {}
3838
/// ```
39+
#[clippy::version = "pre 1.29.0"]
3940
pub ABSURD_EXTREME_COMPARISONS,
4041
correctness,
4142
"a comparison with a maximum or minimum value that is always true or false"

clippy_lints/src/approx_const.rs

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ declare_clippy_lint! {
3333
/// let x = std::f32::consts::PI;
3434
/// let y = std::f64::consts::FRAC_1_PI;
3535
/// ```
36+
#[clippy::version = "pre 1.29.0"]
3637
pub APPROX_CONSTANT,
3738
correctness,
3839
"the approximate of a known float constant (in `std::fXX::consts`)"

clippy_lints/src/arithmetic.rs

+2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ declare_clippy_lint! {
2525
/// # let a = 0;
2626
/// a + 1;
2727
/// ```
28+
#[clippy::version = "pre 1.29.0"]
2829
pub INTEGER_ARITHMETIC,
2930
restriction,
3031
"any integer arithmetic expression which could overflow or panic"
@@ -43,6 +44,7 @@ declare_clippy_lint! {
4344
/// # let a = 0.0;
4445
/// a + 1.0;
4546
/// ```
47+
#[clippy::version = "pre 1.29.0"]
4648
pub FLOAT_ARITHMETIC,
4749
restriction,
4850
"any floating-point arithmetic statement"

clippy_lints/src/as_conversions.rs

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ declare_clippy_lint! {
3838
/// f(a.try_into().expect("Unexpected u16 overflow in f"));
3939
/// ```
4040
///
41+
#[clippy::version = "1.41.0"]
4142
pub AS_CONVERSIONS,
4243
restriction,
4344
"using a potentially dangerous silent `as` conversion"

clippy_lints/src/asm_syntax.rs

+2
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ declare_clippy_lint! {
7575
/// asm!("lea ({}), {}", in(reg) ptr, lateout(reg) _, options(att_syntax));
7676
/// # }
7777
/// ```
78+
#[clippy::version = "1.49.0"]
7879
pub INLINE_ASM_X86_INTEL_SYNTAX,
7980
restriction,
8081
"prefer AT&T x86 assembly syntax"
@@ -111,6 +112,7 @@ declare_clippy_lint! {
111112
/// asm!("lea {}, [{}]", lateout(reg) _, in(reg) ptr);
112113
/// # }
113114
/// ```
115+
#[clippy::version = "1.49.0"]
114116
pub INLINE_ASM_X86_ATT_SYNTAX,
115117
restriction,
116118
"prefer Intel x86 assembly syntax"

clippy_lints/src/assertions_on_constants.rs

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ declare_clippy_lint! {
2626
/// const B: bool = false;
2727
/// assert!(B)
2828
/// ```
29+
#[clippy::version = "1.34.0"]
2930
pub ASSERTIONS_ON_CONSTANTS,
3031
style,
3132
"`assert!(true)` / `assert!(false)` will be optimized out by the compiler, and should probably be replaced by a `panic!()` or `unreachable!()`"

clippy_lints/src/assign_ops.rs

+2
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ declare_clippy_lint! {
3434
/// // Good
3535
/// a += b;
3636
/// ```
37+
#[clippy::version = "pre 1.29.0"]
3738
pub ASSIGN_OP_PATTERN,
3839
style,
3940
"assigning the result of an operation on a variable to that same variable"
@@ -60,6 +61,7 @@ declare_clippy_lint! {
6061
/// // ...
6162
/// a += a + b;
6263
/// ```
64+
#[clippy::version = "pre 1.29.0"]
6365
pub MISREFACTORED_ASSIGN_OP,
6466
suspicious,
6567
"having a variable on both sides of an assign op"

clippy_lints/src/async_yields_async.rs

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ declare_clippy_lint! {
3434
/// };
3535
/// }
3636
/// ```
37+
#[clippy::version = "1.48.0"]
3738
pub ASYNC_YIELDS_ASYNC,
3839
correctness,
3940
"async blocks that return a type that can be awaited"

clippy_lints/src/attrs.rs

+7
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ declare_clippy_lint! {
6666
/// #[inline(always)]
6767
/// fn not_quite_hot_code(..) { ... }
6868
/// ```
69+
#[clippy::version = "pre 1.29.0"]
6970
pub INLINE_ALWAYS,
7071
pedantic,
7172
"use of `#[inline(always)]`"
@@ -100,6 +101,7 @@ declare_clippy_lint! {
100101
/// #[macro_use]
101102
/// extern crate baz;
102103
/// ```
104+
#[clippy::version = "pre 1.29.0"]
103105
pub USELESS_ATTRIBUTE,
104106
correctness,
105107
"use of lint attributes on `extern crate` items"
@@ -119,6 +121,7 @@ declare_clippy_lint! {
119121
/// #[deprecated(since = "forever")]
120122
/// fn something_else() { /* ... */ }
121123
/// ```
124+
#[clippy::version = "pre 1.29.0"]
122125
pub DEPRECATED_SEMVER,
123126
correctness,
124127
"use of `#[deprecated(since = \"x\")]` where x is not semver"
@@ -156,6 +159,7 @@ declare_clippy_lint! {
156159
/// #[allow(dead_code)]
157160
/// fn this_is_fine_too() { }
158161
/// ```
162+
#[clippy::version = "pre 1.29.0"]
159163
pub EMPTY_LINE_AFTER_OUTER_ATTR,
160164
nursery,
161165
"empty line after outer attribute"
@@ -179,6 +183,7 @@ declare_clippy_lint! {
179183
/// ```rust
180184
/// #![deny(clippy::as_conversions)]
181185
/// ```
186+
#[clippy::version = "1.47.0"]
182187
pub BLANKET_CLIPPY_RESTRICTION_LINTS,
183188
suspicious,
184189
"enabling the complete restriction group"
@@ -210,6 +215,7 @@ declare_clippy_lint! {
210215
/// #[rustfmt::skip]
211216
/// fn main() { }
212217
/// ```
218+
#[clippy::version = "1.32.0"]
213219
pub DEPRECATED_CFG_ATTR,
214220
complexity,
215221
"usage of `cfg_attr(rustfmt)` instead of tool attributes"
@@ -242,6 +248,7 @@ declare_clippy_lint! {
242248
/// fn conditional() { }
243249
/// ```
244250
/// Check the [Rust Reference](https://doc.rust-lang.org/reference/conditional-compilation.html#target_os) for more details.
251+
#[clippy::version = "1.45.0"]
245252
pub MISMATCHED_TARGET_OS,
246253
correctness,
247254
"usage of `cfg(operating_system)` instead of `cfg(target_os = \"operating_system\")`"

clippy_lints/src/await_holding_invalid.rs

+2
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ declare_clippy_lint! {
4747
/// bar.await;
4848
/// }
4949
/// ```
50+
#[clippy::version = "1.45.0"]
5051
pub AWAIT_HOLDING_LOCK,
5152
pedantic,
5253
"Inside an async function, holding a MutexGuard while calling await"
@@ -88,6 +89,7 @@ declare_clippy_lint! {
8889
/// bar.await;
8990
/// }
9091
/// ```
92+
#[clippy::version = "1.49.0"]
9193
pub AWAIT_HOLDING_REFCELL_REF,
9294
pedantic,
9395
"Inside an async function, holding a RefCell ref while calling await"

clippy_lints/src/bit_mask.rs

+3
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ declare_clippy_lint! {
4141
/// # let x = 1;
4242
/// if (x & 1 == 2) { }
4343
/// ```
44+
#[clippy::version = "pre 1.29.0"]
4445
pub BAD_BIT_MASK,
4546
correctness,
4647
"expressions of the form `_ & mask == select` that will only ever return `true` or `false`"
@@ -73,6 +74,7 @@ declare_clippy_lint! {
7374
/// # let x = 1;
7475
/// if (x | 1 > 3) { }
7576
/// ```
77+
#[clippy::version = "pre 1.29.0"]
7678
pub INEFFECTIVE_BIT_MASK,
7779
correctness,
7880
"expressions where a bit mask will be rendered useless by a comparison, e.g., `(x | 1) > 2`"
@@ -95,6 +97,7 @@ declare_clippy_lint! {
9597
/// # let x = 1;
9698
/// if x & 0b1111 == 0 { }
9799
/// ```
100+
#[clippy::version = "pre 1.29.0"]
98101
pub VERBOSE_BIT_MASK,
99102
pedantic,
100103
"expressions where a bit mask is less readable than the corresponding method call"

clippy_lints/src/blacklisted_name.rs

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ declare_clippy_lint! {
1717
/// ```rust
1818
/// let foo = 3.14;
1919
/// ```
20+
#[clippy::version = "pre 1.29.0"]
2021
pub BLACKLISTED_NAME,
2122
style,
2223
"usage of a blacklisted/placeholder name"

clippy_lints/src/blocks_in_if_conditions.rs

+1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ declare_clippy_lint! {
4141
/// let res = { let x = somefunc(); x };
4242
/// if res { /* ... */ }
4343
/// ```
44+
#[clippy::version = "1.45.0"]
4445
pub BLOCKS_IN_IF_CONDITIONS,
4546
style,
4647
"useless or complex blocks that can be eliminated in conditions"

clippy_lints/src/bool_assert_comparison.rs

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ declare_clippy_lint! {
2323
/// // Good
2424
/// assert!(!"a".is_empty());
2525
/// ```
26+
#[clippy::version = "1.53.0"]
2627
pub BOOL_ASSERT_COMPARISON,
2728
style,
2829
"Using a boolean as comparison value in an assert_* macro when there is no need"

clippy_lints/src/booleans.rs

+2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ declare_clippy_lint! {
3131
/// if a && true // should be: if a
3232
/// if !(a == b) // should be: if a != b
3333
/// ```
34+
#[clippy::version = "pre 1.29.0"]
3435
pub NONMINIMAL_BOOL,
3536
complexity,
3637
"boolean expressions that can be written more concisely"
@@ -52,6 +53,7 @@ declare_clippy_lint! {
5253
/// if a && b || a { ... }
5354
/// ```
5455
/// The `b` is unnecessary, the expression is equivalent to `if a`.
56+
#[clippy::version = "pre 1.29.0"]
5557
pub LOGIC_BUG,
5658
correctness,
5759
"boolean expressions that contain terminals which can be eliminated"

clippy_lints/src/bytecount.rs

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ declare_clippy_lint! {
3030
/// # let vec = vec![1_u8];
3131
/// &vec.iter().filter(|x| **x == 0u8).count(); // use bytecount::count instead
3232
/// ```
33+
#[clippy::version = "pre 1.29.0"]
3334
pub NAIVE_BYTECOUNT,
3435
pedantic,
3536
"use of naive `<slice>.filter(|&x| x == y).count()` to count byte values"

clippy_lints/src/cargo_common_metadata.rs

+1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ declare_clippy_lint! {
4242
/// keywords = ["clippy", "lint", "plugin"]
4343
/// categories = ["development-tools", "development-tools::cargo-plugins"]
4444
/// ```
45+
#[clippy::version = "1.32.0"]
4546
pub CARGO_COMMON_METADATA,
4647
cargo,
4748
"common metadata is defined in `Cargo.toml`"

clippy_lints/src/case_sensitive_file_extension_comparisons.rs

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ declare_clippy_lint! {
2727
/// filename.rsplit('.').next().map(|ext| ext.eq_ignore_ascii_case("rs")) == Some(true)
2828
/// }
2929
/// ```
30+
#[clippy::version = "1.51.0"]
3031
pub CASE_SENSITIVE_FILE_EXTENSION_COMPARISONS,
3132
pedantic,
3233
"Checks for calls to ends_with with case-sensitive file extensions"

0 commit comments

Comments
 (0)