Skip to content

Commit fe70f6d

Browse files
committed
Create new lints with #[clippy::version = "nightly"]
1 parent 5c031d1 commit fe70f6d

File tree

19 files changed

+48
-47
lines changed

19 files changed

+48
-47
lines changed

book/src/development/adding_lints.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ declare_clippy_lint! {
223223
/// ```rust
224224
/// // example code
225225
/// ```
226-
#[clippy::version = "1.29.0"]
226+
#[clippy::version = "nightly"]
227227
pub FOO_FUNCTIONS,
228228
pedantic,
229229
"function named `foo`, which is not a descriptive name"
@@ -577,7 +577,7 @@ declare_clippy_lint! {
577577
/// ```rust,ignore
578578
/// // A short example of improved code that doesn't trigger the lint
579579
/// ```
580-
#[clippy::version = "1.29.0"]
580+
#[clippy::version = "nightly"]
581581
pub FOO_FUNCTIONS,
582582
pedantic,
583583
"function named `foo`, which is not a descriptive name"

book/src/development/defining_lints.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,10 +169,10 @@ declare_clippy_lint! {
169169
/// ```rust
170170
/// // example code which does not raise Clippy warning
171171
/// ```
172-
#[clippy::version = "1.70.0"] // <- In which version was this implemented, keep it up to date!
172+
#[clippy::version = "nightly"]
173173
pub LINT_NAME, // <- The lint name IN_ALL_CAPS
174174
pedantic, // <- The lint group
175-
"default lint description" // <- A lint description, e.g. "A function has an unit return type."
175+
"default lint description" // <- A lint description, e.g. "A function has an unit return type"
176176
}
177177
```
178178

book/src/development/infrastructure/changelog_update.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,8 @@ that label in the changelog. If you can, remove the `beta-accepted` labels
111111
112112
### 4. Update `clippy::version` attributes
113113

114-
Next, make sure to check that the `#[clippy::version]` attributes for the added
115-
lints contain the correct version.
114+
Next, make sure to check that the `#[clippy::version]` attributes for the newly
115+
added, renamed and deprecated lints contain the correct version.
116116

117117
[changelog]: https://github.com/rust-lang/rust-clippy/blob/master/CHANGELOG.md
118118
[forge]: https://forge.rust-lang.org/

clippy_dev/src/new_lint.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::utils::{clippy_project_root, clippy_version};
1+
use crate::utils::clippy_project_root;
22
use clap::ValueEnum;
33
use indoc::{formatdoc, writedoc};
44
use std::fmt::{self, Write as _};
@@ -193,11 +193,6 @@ fn to_camel_case(name: &str) -> String {
193193
.collect()
194194
}
195195

196-
pub(crate) fn get_stabilization_version() -> String {
197-
let (minor, patch) = clippy_version();
198-
format!("{minor}.{patch}.0")
199-
}
200-
201196
fn get_test_file_contents(lint_name: &str, msrv: bool) -> String {
202197
let mut test = formatdoc!(
203198
r"
@@ -351,13 +346,12 @@ fn get_lint_declaration(name_upper: &str, category: &str) -> String {
351346
/// ```no_run
352347
/// // example code which does not raise clippy warning
353348
/// ```
354-
#[clippy::version = "{}"]
349+
#[clippy::version = "nightly"]
355350
pub {name_upper},
356351
{category},
357352
"default lint description"
358353
}}
359354
"#,
360-
get_stabilization_version(),
361355
)
362356
}
363357

clippy_dev/src/update_lints.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -197,13 +197,12 @@ pub fn rename(old_name: &str, new_name: &str, uplift: bool) {
197197
});
198198
}
199199

200-
let version = crate::new_lint::get_stabilization_version();
201200
rewrite_file(Path::new("clippy_lints/src/deprecated_lints.rs"), |s| {
202201
insert_at_marker(
203202
s,
204203
"// end renamed lints. used by `cargo dev rename_lint`",
205204
&format!(
206-
"#[clippy::version = \"{version}\"]\n \
205+
"#[clippy::version = \"nightly\"]\n \
207206
(\"{}\", \"{}\"),\n ",
208207
lint.old_name, lint.new_name,
209208
),
@@ -333,12 +332,11 @@ pub fn deprecate(name: &str, reason: &str) {
333332
let deprecated_lints_path = &*clippy_project_root().join("clippy_lints/src/deprecated_lints.rs");
334333

335334
if remove_lint_declaration(stripped_name, &mod_path, &mut lints).unwrap_or(false) {
336-
let version = crate::new_lint::get_stabilization_version();
337335
rewrite_file(deprecated_lints_path, |s| {
338336
insert_at_marker(
339337
s,
340338
"// end deprecated lints. used by `cargo dev deprecate_lint`",
341-
&format!("#[clippy::version = \"{version}\"]\n (\"{prefixed_name}\", \"{reason}\"),\n ",),
339+
&format!("#[clippy::version = \"nightly\"]\n (\"{prefixed_name}\", \"{reason}\"),\n ",),
342340
)
343341
});
344342

clippy_lints/src/deprecated_lints.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ declare_with_version! { DEPRECATED(DEPRECATED_VERSION): &[(&str, &str)] = &[
4040
("clippy::pub_enum_variant_names", "`clippy::enum_variant_names` now covers this case via the `avoid-breaking-exported-api` config"),
4141
#[clippy::version = "1.54.0"]
4242
("clippy::wrong_pub_self_convention", "`clippy::wrong_self_convention` now covers this case via the `avoid-breaking-exported-api` config"),
43-
#[clippy::version = "1.86.0"]
43+
#[clippy::version = "nightly"]
4444
("clippy::option_map_or_err_ok", "`clippy::manual_ok_or` covers this case"),
4545
// end deprecated lints. used by `cargo dev deprecate_lint`
4646
]}
@@ -131,7 +131,7 @@ declare_with_version! { RENAMED(RENAMED_VERSION): &[(&str, &str)] = &[
131131
("clippy::clone_double_ref", "suspicious_double_ref_op"),
132132
#[clippy::version = ""]
133133
("clippy::cmp_nan", "invalid_nan_comparisons"),
134-
#[clippy::version = "1.86.0"]
134+
#[clippy::version = "nightly"]
135135
("clippy::double_neg", "double_negations"),
136136
#[clippy::version = ""]
137137
("clippy::drop_bounds", "drop_bounds"),

clippy_lints/src/doc/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ declare_clippy_lint! {
9898
/// ```no_run
9999
/// //! <code>[first](x)second</code>
100100
/// ```
101-
#[clippy::version = "1.86.0"]
101+
#[clippy::version = "nightly"]
102102
pub DOC_LINK_CODE,
103103
nursery,
104104
"link with code back-to-back with other code"
@@ -475,7 +475,7 @@ declare_clippy_lint! {
475475
/// /// and this line is overindented.
476476
/// # fn foo() {}
477477
/// ```
478-
#[clippy::version = "1.86.0"]
478+
#[clippy::version = "nightly"]
479479
pub DOC_OVERINDENTED_LIST_ITEMS,
480480
style,
481481
"ensure list items are not overindented"

clippy_lints/src/loops/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -734,7 +734,7 @@ declare_clippy_lint! {
734734
/// let mut some_slice = [1, 2, 3, 4, 5];
735735
/// some_slice.fill(0);
736736
/// ```
737-
#[clippy::version = "1.86.0"]
737+
#[clippy::version = "nightly"]
738738
pub MANUAL_SLICE_FILL,
739739
style,
740740
"manually filling a slice with a value"

clippy_lints/src/matches/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1000,7 +1000,7 @@ declare_clippy_lint! {
10001000
/// let a = func().ok();
10011001
/// let b = func().err();
10021002
/// ```
1003-
#[clippy::version = "1.86.0"]
1003+
#[clippy::version = "nightly"]
10041004
pub MANUAL_OK_ERR,
10051005
complexity,
10061006
"find manual implementations of `.ok()` or `.err()` on `Result`"

clippy_lints/src/mem_replace.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ declare_clippy_lint! {
6262
/// let mut an_option = Some(0);
6363
/// let taken = an_option.replace(1);
6464
/// ```
65-
#[clippy::version = "1.86.0"]
65+
#[clippy::version = "nightly"]
6666
pub MEM_REPLACE_OPTION_WITH_SOME,
6767
style,
6868
"replacing an `Option` with `Some` instead of `replace()`"

clippy_lints/src/methods/mod.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4313,7 +4313,7 @@ declare_clippy_lint! {
43134313
/// use std::num::NonZeroUsize;
43144314
/// const PLAYERS: NonZeroUsize = NonZeroUsize::new(3).unwrap();
43154315
/// ```
4316-
#[clippy::version = "1.86.0"]
4316+
#[clippy::version = "nightly"]
43174317
pub USELESS_NONZERO_NEW_UNCHECKED,
43184318
complexity,
43194319
"using `NonZero::new_unchecked()` in a `const` context"
@@ -4336,7 +4336,7 @@ declare_clippy_lint! {
43364336
/// ```no_run
43374337
/// let _ = std::iter::repeat_n(10, 3);
43384338
/// ```
4339-
#[clippy::version = "1.86.0"]
4339+
#[clippy::version = "nightly"]
43404340
pub MANUAL_REPEAT_N,
43414341
style,
43424342
"detect `repeat().take()` that can be replaced with `repeat_n()`"
@@ -4364,7 +4364,7 @@ declare_clippy_lint! {
43644364
/// let s = "Lorem ipsum";
43654365
/// &s.as_bytes()[1..5];
43664366
/// ```
4367-
#[clippy::version = "1.86.0"]
4367+
#[clippy::version = "nightly"]
43684368
pub SLICED_STRING_AS_BYTES,
43694369
perf,
43704370
"slicing a string and immediately calling as_bytes is less efficient and can lead to panics"
@@ -4404,7 +4404,7 @@ declare_clippy_lint! {
44044404
/// }
44054405
/// }
44064406
/// ```
4407-
#[clippy::version = "1.86.0"]
4407+
#[clippy::version = "nightly"]
44084408
pub RETURN_AND_THEN,
44094409
restriction,
44104410
"using `Option::and_then` or `Result::and_then` to chain a computation that returns an `Option` or a `Result`"
@@ -4431,7 +4431,7 @@ declare_clippy_lint! {
44314431
/// let file = BufReader::new(std::fs::File::open("./bytes.txt").unwrap());
44324432
/// file.bytes();
44334433
/// ```
4434-
#[clippy::version = "1.86.0"]
4434+
#[clippy::version = "nightly"]
44354435
pub UNBUFFERED_BYTES,
44364436
perf,
44374437
"calling .bytes() is very inefficient when data is not in memory"
@@ -4456,7 +4456,7 @@ declare_clippy_lint! {
44564456
/// values.contains(&10)
44574457
/// }
44584458
/// ```
4459-
#[clippy::version = "1.86.0"]
4459+
#[clippy::version = "nightly"]
44604460
pub MANUAL_CONTAINS,
44614461
perf,
44624462
"unnecessary `iter().any()` on slices that can be replaced with `contains()`"
@@ -4478,7 +4478,7 @@ declare_clippy_lint! {
44784478
/// ```no_run
44794479
/// let _ = std::io::Error::other("bad".to_string());
44804480
/// ```
4481-
#[clippy::version = "1.86.0"]
4481+
#[clippy::version = "nightly"]
44824482
pub IO_OTHER_ERROR,
44834483
style,
44844484
"calling `std::io::Error::new(std::io::ErrorKind::Other, _)`"

clippy_lints/src/precedence.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ declare_clippy_lint! {
3737
///
3838
/// ### Example
3939
/// `0x2345 & 0xF000 >> 12` equals 5, while `(0x2345 & 0xF000) >> 12` equals 2
40-
#[clippy::version = "1.86.0"]
40+
#[clippy::version = "nightly"]
4141
pub PRECEDENCE_BITS,
4242
restriction,
4343
"operations mixing bit shifting with bit combining/masking"

clippy_lints/src/single_option_map.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ declare_clippy_lint! {
3030
/// param * 2
3131
/// }
3232
/// ```
33-
#[clippy::version = "1.86.0"]
33+
#[clippy::version = "nightly"]
3434
pub SINGLE_OPTION_MAP,
3535
nursery,
3636
"Checks for functions with method calls to `.map(_)` on an arg of type `Option` as the outermost expression."

clippy_lints/src/unnecessary_semicolon.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ declare_clippy_lint! {
2929
/// println!("a is greater than 10");
3030
/// }
3131
/// ```
32-
#[clippy::version = "1.86.0"]
32+
#[clippy::version = "nightly"]
3333
pub UNNECESSARY_SEMICOLON,
3434
pedantic,
3535
"unnecessary semicolon after expression returning `()`"

clippy_lints/src/unneeded_struct_pattern.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ declare_clippy_lint! {
3232
/// None => 0,
3333
/// };
3434
/// ```
35-
#[clippy::version = "1.86.0"]
35+
#[clippy::version = "nightly"]
3636
pub UNNEEDED_STRUCT_PATTERN,
3737
style,
3838
"using struct pattern to match against unit variant"

clippy_lints/src/utils/internal_lints/lint_without_lint_pass.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ pub(super) fn is_lint_ref_type(cx: &LateContext<'_>, ty: &hir::Ty<'_>) -> bool {
218218

219219
fn check_invalid_clippy_version_attribute(cx: &LateContext<'_>, item: &'_ Item<'_>) {
220220
if let Some(value) = extract_clippy_version_value(cx, item) {
221-
if value.as_str() == "pre 1.29.0" {
221+
if matches!(value.as_str(), "pre 1.29.0" | "nightly") {
222222
return;
223223
}
224224

tests/ui-internal/check_clippy_version_attribute.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,14 @@ declare_tool_lint! {
3434
report_in_external_macro: true
3535
}
3636

37+
declare_tool_lint! {
38+
#[clippy::version = "nightly"]
39+
pub clippy::VALID_NIGHTLY,
40+
Warn,
41+
"Three",
42+
report_in_external_macro: true
43+
}
44+
3745
///////////////////////
3846
// Invalid attributes
3947
///////////////////////
@@ -86,6 +94,6 @@ mod internal_clippy_lints {
8694
}
8795

8896
use crate::internal_clippy_lints::ALLOW_MISSING_ATTRIBUTE_ONE;
89-
declare_lint_pass!(Pass2 => [VALID_ONE, VALID_TWO, VALID_THREE, INVALID_ONE, INVALID_TWO, MISSING_ATTRIBUTE_ONE, MISSING_ATTRIBUTE_TWO, ALLOW_MISSING_ATTRIBUTE_ONE]);
97+
declare_lint_pass!(Pass2 => [VALID_ONE, VALID_TWO, VALID_THREE, VALID_NIGHTLY, INVALID_ONE, INVALID_TWO, MISSING_ATTRIBUTE_ONE, MISSING_ATTRIBUTE_TWO, ALLOW_MISSING_ATTRIBUTE_ONE]);
9098

9199
fn main() {}

tests/ui-internal/check_clippy_version_attribute.stderr

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: this item has an invalid `clippy::version` attribute
2-
--> tests/ui-internal/check_clippy_version_attribute.rs:40:1
2+
--> tests/ui-internal/check_clippy_version_attribute.rs:48:1
33
|
44
LL | / declare_tool_lint! {
55
LL | |
@@ -20,7 +20,7 @@ LL | #![deny(clippy::internal)]
2020
= note: this error originates in the macro `$crate::declare_tool_lint` which comes from the expansion of the macro `declare_tool_lint` (in Nightly builds, run with -Z macro-backtrace for more info)
2121

2222
error: this item has an invalid `clippy::version` attribute
23-
--> tests/ui-internal/check_clippy_version_attribute.rs:49:1
23+
--> tests/ui-internal/check_clippy_version_attribute.rs:57:1
2424
|
2525
LL | / declare_tool_lint! {
2626
LL | |
@@ -35,7 +35,7 @@ LL | | }
3535
= note: this error originates in the macro `$crate::declare_tool_lint` which comes from the expansion of the macro `declare_tool_lint` (in Nightly builds, run with -Z macro-backtrace for more info)
3636

3737
error: this lint is missing the `clippy::version` attribute or version value
38-
--> tests/ui-internal/check_clippy_version_attribute.rs:61:1
38+
--> tests/ui-internal/check_clippy_version_attribute.rs:69:1
3939
|
4040
LL | / declare_tool_lint! {
4141
LL | |
@@ -51,7 +51,7 @@ LL | | }
5151
= note: this error originates in the macro `$crate::declare_tool_lint` which comes from the expansion of the macro `declare_tool_lint` (in Nightly builds, run with -Z macro-backtrace for more info)
5252

5353
error: this lint is missing the `clippy::version` attribute or version value
54-
--> tests/ui-internal/check_clippy_version_attribute.rs:70:1
54+
--> tests/ui-internal/check_clippy_version_attribute.rs:78:1
5555
|
5656
LL | / declare_tool_lint! {
5757
LL | |

util/gh-pages/script.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -242,16 +242,17 @@ window.filters = {
242242
filters.allLints = Array.prototype.slice.call(
243243
document.getElementsByTagName("article"),
244244
).map(elem => {
245-
let version = elem.querySelector(".label-version").innerText;
245+
let versionText = elem.querySelector(".label-version").innerText;
246246
// Strip the "pre " prefix for pre 1.29.0 lints
247-
if (version.startsWith("pre ")) {
248-
version = version.slice(4);
247+
if (versionText.startsWith("pre ")) {
248+
versionText = versionText.slice(4);
249249
}
250+
const version = versionText == "nightly" ? Infinity : versionText.split(".")[1];
250251
return {
251-
elem: elem,
252+
elem,
252253
group: elem.querySelector(".label-lint-group").innerText,
253254
level: elem.querySelector(".label-lint-level").innerText,
254-
version: parseInt(version.split(".")[1]),
255+
version,
255256
applicability: elem.querySelector(".label-applicability").innerText,
256257
filteredOut: false,
257258
searchFilteredOut: false,

0 commit comments

Comments
 (0)