Skip to content

Commit ea71df3

Browse files
committed
Create new lints with #[clippy::version = "nightly"]
1 parent 781fdab commit ea71df3

File tree

14 files changed

+104
-127
lines changed

14 files changed

+104
-127
lines changed

book/src/development/adding_lints.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ declare_clippy_lint! {
233233
/// ```rust
234234
/// // example code
235235
/// ```
236-
#[clippy::version = "1.29.0"]
236+
#[clippy::version = "nightly"]
237237
pub FOO_FUNCTIONS,
238238
pedantic,
239239
"function named `foo`, which is not a descriptive name"
@@ -587,7 +587,7 @@ declare_clippy_lint! {
587587
/// ```rust,ignore
588588
/// // A short example of improved code that doesn't trigger the lint
589589
/// ```
590-
#[clippy::version = "1.29.0"]
590+
#[clippy::version = "nightly"]
591591
pub FOO_FUNCTIONS,
592592
pedantic,
593593
"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
@@ -168,10 +168,10 @@ declare_clippy_lint! {
168168
/// ```rust
169169
/// // example code which does not raise Clippy warning
170170
/// ```
171-
#[clippy::version = "1.70.0"] // <- In which version was this implemented, keep it up to date!
171+
#[clippy::version = "nightly"]
172172
pub LINT_NAME, // <- The lint name IN_ALL_CAPS
173173
pedantic, // <- The lint group
174-
"default lint description" // <- A lint description, e.g. "A function has an unit return type."
174+
"default lint description" // <- A lint description, e.g. "A function has an unit return type"
175175
}
176176
```
177177

book/src/development/infrastructure/changelog_update.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,12 @@ 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 and deprecated lints contain the version of the release you're writing the
116+
changelog for.
117+
118+
Newly created lints will have `#[clippy::version = "nightly"]` and be handled
119+
during the sync, but many existing PRs will still have an incorrect version.
116120

117121
[changelog]: https://github.com/rust-lang/rust-clippy/blob/master/CHANGELOG.md
118122
[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: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -196,16 +196,11 @@ pub fn rename(old_name: &str, new_name: &str, uplift: bool) {
196196
});
197197
}
198198

199-
let version = crate::new_lint::get_stabilization_version();
200199
rewrite_file(Path::new("clippy_lints/src/deprecated_lints.rs"), |s| {
201200
insert_at_marker(
202201
s,
203202
"// end renamed lints. used by `cargo dev rename_lint`",
204-
&format!(
205-
"#[clippy::version = \"{version}\"]\n \
206-
(\"{}\", \"{}\"),\n ",
207-
lint.old_name, lint.new_name,
208-
),
203+
&format!("(\"{}\", \"{}\"),\n ", lint.old_name, lint.new_name,),
209204
)
210205
});
211206

@@ -332,12 +327,11 @@ pub fn deprecate(name: &str, reason: &str) {
332327
let deprecated_lints_path = &*clippy_project_root().join("clippy_lints/src/deprecated_lints.rs");
333328

334329
if remove_lint_declaration(stripped_name, &mod_path, &mut lints).unwrap_or(false) {
335-
let version = crate::new_lint::get_stabilization_version();
336330
rewrite_file(deprecated_lints_path, |s| {
337331
insert_at_marker(
338332
s,
339333
"// end deprecated lints. used by `cargo dev deprecate_lint`",
340-
&format!("#[clippy::version = \"{version}\"]\n (\"{prefixed_name}\", \"{reason}\"),\n ",),
334+
&format!("#[clippy::version = \"nightly\"]\n (\"{prefixed_name}\", \"{reason}\"),\n ",),
341335
)
342336
});
343337

@@ -547,6 +541,7 @@ impl DeprecatedLint {
547541
}
548542
}
549543

544+
#[derive(Debug)]
550545
struct RenamedLint {
551546
old_name: String,
552547
new_name: String,
@@ -741,10 +736,10 @@ fn parse_contents(contents: &str, module: &str, lints: &mut Vec<Lint>) {
741736

742737
/// Parse a source file looking for `declare_deprecated_lint` macro invocations.
743738
fn parse_deprecated_contents(contents: &str, deprecated: &mut Vec<DeprecatedLint>, renamed: &mut Vec<RenamedLint>) {
744-
let Some((_, contents)) = contents.split_once("\ndeclare_with_version! { DEPRECATED") else {
739+
let Some((_, contents)) = contents.split_once("\ndeprecated![") else {
745740
return;
746741
};
747-
let Some((deprecated_src, renamed_src)) = contents.split_once("\ndeclare_with_version! { RENAMED") else {
742+
let Some((deprecated_src, renamed_src)) = contents.split_once("\npub const RENAMED") else {
748743
return;
749744
};
750745

clippy_lints/src/deprecated_lints.rs

Lines changed: 21 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,28 @@
11
// This file is managed by `cargo dev rename_lint` and `cargo dev deprecate_lint`.
22
// Prefer to use those when possible.
33

4-
macro_rules! declare_with_version {
5-
($name:ident($name_version:ident): &[$ty:ty] = &[$(
4+
#[derive(Copy, Clone, Debug)]
5+
pub struct Deprecation {
6+
pub name: &'static str,
7+
pub reason: &'static str,
8+
pub version: &'static str,
9+
}
10+
11+
macro_rules! deprecated {
12+
($(
613
#[clippy::version = $version:literal]
7-
$e:expr,
8-
)*]) => {
9-
pub static $name: &[$ty] = &[$($e),*];
10-
#[allow(unused)]
11-
pub static $name_version: &[&str] = &[$($version),*];
14+
($name:literal, $reason:literal),
15+
)*) => {
16+
pub const DEPRECATED: &[Deprecation] = &[$(Deprecation {
17+
name: $name,
18+
reason: $reason,
19+
version: $version,
20+
}),*];
1221
};
1322
}
1423

1524
#[rustfmt::skip]
16-
declare_with_version! { DEPRECATED(DEPRECATED_VERSION): &[(&str, &str)] = &[
25+
deprecated![
1726
#[clippy::version = "pre 1.29.0"]
1827
("clippy::should_assert_eq", "`assert!(a == b)` can now print the values the same way `assert_eq!(a, b) can"),
1928
#[clippy::version = "pre 1.29.0"]
@@ -40,152 +49,83 @@ declare_with_version! { DEPRECATED(DEPRECATED_VERSION): &[(&str, &str)] = &[
4049
("clippy::pub_enum_variant_names", "`clippy::enum_variant_names` now covers this case via the `avoid-breaking-exported-api` config"),
4150
#[clippy::version = "1.54.0"]
4251
("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"]
52+
#[clippy::version = "nightly"]
4453
("clippy::option_map_or_err_ok", "`clippy::manual_ok_or` covers this case"),
4554
#[clippy::version = "1.86.0"]
4655
("clippy::match_on_vec_items", "`clippy::indexing_slicing` covers indexing and slicing on `Vec<_>`"),
4756
// end deprecated lints. used by `cargo dev deprecate_lint`
48-
]}
57+
];
4958

5059
#[rustfmt::skip]
51-
declare_with_version! { RENAMED(RENAMED_VERSION): &[(&str, &str)] = &[
52-
#[clippy::version = ""]
60+
pub const RENAMED: &[(&str, &str)] = &[
5361
("clippy::almost_complete_letter_range", "clippy::almost_complete_range"),
54-
#[clippy::version = ""]
5562
("clippy::blacklisted_name", "clippy::disallowed_names"),
56-
#[clippy::version = ""]
5763
("clippy::block_in_if_condition_expr", "clippy::blocks_in_conditions"),
58-
#[clippy::version = ""]
5964
("clippy::block_in_if_condition_stmt", "clippy::blocks_in_conditions"),
60-
#[clippy::version = ""]
6165
("clippy::blocks_in_if_conditions", "clippy::blocks_in_conditions"),
62-
#[clippy::version = ""]
6366
("clippy::box_vec", "clippy::box_collection"),
64-
#[clippy::version = ""]
6567
("clippy::const_static_lifetime", "clippy::redundant_static_lifetimes"),
66-
#[clippy::version = ""]
6768
("clippy::cyclomatic_complexity", "clippy::cognitive_complexity"),
68-
#[clippy::version = ""]
6969
("clippy::derive_hash_xor_eq", "clippy::derived_hash_with_manual_eq"),
70-
#[clippy::version = ""]
7170
("clippy::disallowed_method", "clippy::disallowed_methods"),
72-
#[clippy::version = ""]
7371
("clippy::disallowed_type", "clippy::disallowed_types"),
74-
#[clippy::version = ""]
7572
("clippy::eval_order_dependence", "clippy::mixed_read_write_in_expression"),
76-
#[clippy::version = "1.51.0"]
7773
("clippy::find_map", "clippy::manual_find_map"),
78-
#[clippy::version = "1.53.0"]
7974
("clippy::filter_map", "clippy::manual_filter_map"),
80-
#[clippy::version = ""]
8175
("clippy::fn_address_comparisons", "unpredictable_function_pointer_comparisons"),
82-
#[clippy::version = ""]
8376
("clippy::identity_conversion", "clippy::useless_conversion"),
84-
#[clippy::version = "pre 1.29.0"]
8577
("clippy::if_let_redundant_pattern_matching", "clippy::redundant_pattern_matching"),
86-
#[clippy::version = ""]
8778
("clippy::if_let_some_result", "clippy::match_result_ok"),
88-
#[clippy::version = ""]
8979
("clippy::incorrect_clone_impl_on_copy_type", "clippy::non_canonical_clone_impl"),
90-
#[clippy::version = ""]
9180
("clippy::incorrect_partial_ord_impl_on_ord_type", "clippy::non_canonical_partial_ord_impl"),
92-
#[clippy::version = ""]
9381
("clippy::integer_arithmetic", "clippy::arithmetic_side_effects"),
94-
#[clippy::version = ""]
9582
("clippy::logic_bug", "clippy::overly_complex_bool_expr"),
96-
#[clippy::version = ""]
9783
("clippy::new_without_default_derive", "clippy::new_without_default"),
98-
#[clippy::version = ""]
9984
("clippy::option_and_then_some", "clippy::bind_instead_of_map"),
100-
#[clippy::version = ""]
10185
("clippy::option_expect_used", "clippy::expect_used"),
102-
#[clippy::version = ""]
10386
("clippy::option_map_unwrap_or", "clippy::map_unwrap_or"),
104-
#[clippy::version = ""]
10587
("clippy::option_map_unwrap_or_else", "clippy::map_unwrap_or"),
106-
#[clippy::version = ""]
10788
("clippy::option_unwrap_used", "clippy::unwrap_used"),
108-
#[clippy::version = ""]
10989
("clippy::overflow_check_conditional", "clippy::panicking_overflow_checks"),
110-
#[clippy::version = ""]
11190
("clippy::ref_in_deref", "clippy::needless_borrow"),
112-
#[clippy::version = ""]
11391
("clippy::result_expect_used", "clippy::expect_used"),
114-
#[clippy::version = ""]
11592
("clippy::result_map_unwrap_or_else", "clippy::map_unwrap_or"),
116-
#[clippy::version = ""]
11793
("clippy::result_unwrap_used", "clippy::unwrap_used"),
118-
#[clippy::version = ""]
11994
("clippy::single_char_push_str", "clippy::single_char_add_str"),
120-
#[clippy::version = ""]
12195
("clippy::stutter", "clippy::module_name_repetitions"),
122-
#[clippy::version = ""]
12396
("clippy::thread_local_initializer_can_be_made_const", "clippy::missing_const_for_thread_local"),
124-
#[clippy::version = ""]
12597
("clippy::to_string_in_display", "clippy::recursive_format_impl"),
126-
#[clippy::version = ""]
12798
("clippy::unwrap_or_else_default", "clippy::unwrap_or_default"),
128-
#[clippy::version = ""]
12999
("clippy::zero_width_space", "clippy::invisible_characters"),
130-
#[clippy::version = ""]
131100
("clippy::cast_ref_to_mut", "invalid_reference_casting"),
132-
#[clippy::version = ""]
133101
("clippy::clone_double_ref", "suspicious_double_ref_op"),
134-
#[clippy::version = ""]
135102
("clippy::cmp_nan", "invalid_nan_comparisons"),
136-
#[clippy::version = "CURRENT_RUSTC_VERSION"]
137103
("clippy::invalid_null_ptr_usage", "invalid_null_arguments"),
138-
#[clippy::version = "1.86.0"]
139104
("clippy::double_neg", "double_negations"),
140-
#[clippy::version = ""]
141105
("clippy::drop_bounds", "drop_bounds"),
142-
#[clippy::version = ""]
143106
("clippy::drop_copy", "dropping_copy_types"),
144-
#[clippy::version = ""]
145107
("clippy::drop_ref", "dropping_references"),
146-
#[clippy::version = ""]
147108
("clippy::fn_null_check", "useless_ptr_null_checks"),
148-
#[clippy::version = ""]
149109
("clippy::for_loop_over_option", "for_loops_over_fallibles"),
150-
#[clippy::version = ""]
151110
("clippy::for_loop_over_result", "for_loops_over_fallibles"),
152-
#[clippy::version = ""]
153111
("clippy::for_loops_over_fallibles", "for_loops_over_fallibles"),
154-
#[clippy::version = ""]
155112
("clippy::forget_copy", "forgetting_copy_types"),
156-
#[clippy::version = ""]
157113
("clippy::forget_ref", "forgetting_references"),
158-
#[clippy::version = ""]
159114
("clippy::into_iter_on_array", "array_into_iter"),
160-
#[clippy::version = ""]
161115
("clippy::invalid_atomic_ordering", "invalid_atomic_ordering"),
162-
#[clippy::version = ""]
163116
("clippy::invalid_ref", "invalid_value"),
164-
#[clippy::version = ""]
165117
("clippy::invalid_utf8_in_unchecked", "invalid_from_utf8_unchecked"),
166-
#[clippy::version = ""]
167118
("clippy::let_underscore_drop", "let_underscore_drop"),
168-
#[clippy::version = "1.80.0"]
169119
("clippy::maybe_misused_cfg", "unexpected_cfgs"),
170-
#[clippy::version = ""]
171120
("clippy::mem_discriminant_non_enum", "enum_intrinsics_non_enums"),
172-
#[clippy::version = "1.80.0"]
173121
("clippy::mismatched_target_os", "unexpected_cfgs"),
174-
#[clippy::version = ""]
175122
("clippy::panic_params", "non_fmt_panics"),
176-
#[clippy::version = ""]
177123
("clippy::positional_named_format_parameters", "named_arguments_used_positionally"),
178-
#[clippy::version = ""]
179124
("clippy::temporary_cstring_as_ptr", "dangling_pointers_from_temporaries"),
180-
#[clippy::version = ""]
181125
("clippy::undropped_manually_drops", "undropped_manually_drops"),
182-
#[clippy::version = ""]
183126
("clippy::unknown_clippy_lints", "unknown_lints"),
184-
#[clippy::version = ""]
185127
("clippy::unused_label", "unused_labels"),
186-
#[clippy::version = ""]
187128
("clippy::vtable_address_comparisons", "ambiguous_wide_pointer_comparisons"),
188-
#[clippy::version = ""]
189129
("clippy::reverse_range_loop", "clippy::reversed_empty_ranges"),
190130
// end renamed lints. used by `cargo dev rename_lint`
191-
]}
131+
];

clippy_lints/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,7 @@ mod zombie_processes;
408408

409409
use clippy_config::{Conf, get_configuration_metadata, sanitize_explanation};
410410
use clippy_utils::macros::FormatArgsStorage;
411+
use deprecated_lints::Deprecation;
411412
use rustc_data_structures::fx::FxHashSet;
412413
use rustc_lint::{Lint, LintId};
413414
use utils::attr_collector::{AttrCollector, AttrStorage};
@@ -560,7 +561,7 @@ pub fn register_lints(store: &mut rustc_lint::LintStore, conf: &'static Conf) {
560561
for (old_name, new_name) in deprecated_lints::RENAMED {
561562
store.register_renamed(old_name, new_name);
562563
}
563-
for (name, reason) in deprecated_lints::DEPRECATED {
564+
for Deprecation { name, reason, .. } in deprecated_lints::DEPRECATED {
564565
store.register_removed(name, reason);
565566
}
566567

clippy_lints_internal/src/lint_without_lint_pass.rs

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

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

0 commit comments

Comments
 (0)