Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 3bfe98d

Browse files
committed
Auto merge of rust-lang#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 rust-lang#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: rust-lang#7172 closes: rust-lang#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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 18 additions & 3 deletions
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

Lines changed: 5 additions & 0 deletions
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 2 additions & 0 deletions
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 2 additions & 0 deletions
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 2 additions & 0 deletions
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"

0 commit comments

Comments
 (0)