Skip to content

Commit 0190457

Browse files
committed
Test that no nightly versions exist in the rust repo
1 parent 41c61ef commit 0190457

File tree

7 files changed

+74
-99
lines changed

7 files changed

+74
-99
lines changed

book/src/development/infrastructure/changelog_update.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,10 @@ that label in the changelog. If you can, remove the `beta-accepted` labels
112112
### 4. Update `clippy::version` attributes
113113

114114
Next, make sure to check that the `#[clippy::version]` attributes for the newly
115-
added, renamed and deprecated lints contain the correct version.
115+
added and deprecated lints contain the correct version.
116+
117+
Newly created lints will have `#[clippy::version = "nightly"]` and be handled
118+
during the sync, but many existing PRs will still have an incorrect version.
116119

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

clippy_dev/src/update_lints.rs

+4-7
Original file line numberDiff line numberDiff line change
@@ -201,11 +201,7 @@ pub fn rename(old_name: &str, new_name: &str, uplift: bool) {
201201
insert_at_marker(
202202
s,
203203
"// end renamed lints. used by `cargo dev rename_lint`",
204-
&format!(
205-
"#[clippy::version = \"nightly\"]\n \
206-
(\"{}\", \"{}\"),\n ",
207-
lint.old_name, lint.new_name,
208-
),
204+
&format!("(\"{}\", \"{}\"),\n ", lint.old_name, lint.new_name,),
209205
)
210206
});
211207

@@ -562,6 +558,7 @@ impl DeprecatedLint {
562558
}
563559
}
564560

561+
#[derive(Debug)]
565562
struct RenamedLint {
566563
old_name: String,
567564
new_name: String,
@@ -765,10 +762,10 @@ fn parse_contents(contents: &str, module: &str, lints: &mut Vec<Lint>) {
765762

766763
/// Parse a source file looking for `declare_deprecated_lint` macro invocations.
767764
fn parse_deprecated_contents(contents: &str, deprecated: &mut Vec<DeprecatedLint>, renamed: &mut Vec<RenamedLint>) {
768-
let Some((_, contents)) = contents.split_once("\ndeclare_with_version! { DEPRECATED") else {
765+
let Some((_, contents)) = contents.split_once("\ndeprecated![") else {
769766
return;
770767
};
771-
let Some((deprecated_src, renamed_src)) = contents.split_once("\ndeclare_with_version! { RENAMED") else {
768+
let Some((deprecated_src, renamed_src)) = contents.split_once("\npub const RENAMED") else {
772769
return;
773770
};
774771

clippy_lints/src/deprecated_lints.rs

+20-79
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"]
@@ -43,145 +52,77 @@ declare_with_version! { DEPRECATED(DEPRECATED_VERSION): &[(&str, &str)] = &[
4352
#[clippy::version = "nightly"]
4453
("clippy::option_map_or_err_ok", "`clippy::manual_ok_or` covers this case"),
4554
// end deprecated lints. used by `cargo dev deprecate_lint`
46-
]}
55+
];
4756

4857
#[rustfmt::skip]
49-
declare_with_version! { RENAMED(RENAMED_VERSION): &[(&str, &str)] = &[
50-
#[clippy::version = ""]
58+
pub const RENAMED: &[(&str, &str)] = &[
5159
("clippy::almost_complete_letter_range", "clippy::almost_complete_range"),
52-
#[clippy::version = ""]
5360
("clippy::blacklisted_name", "clippy::disallowed_names"),
54-
#[clippy::version = ""]
5561
("clippy::block_in_if_condition_expr", "clippy::blocks_in_conditions"),
56-
#[clippy::version = ""]
5762
("clippy::block_in_if_condition_stmt", "clippy::blocks_in_conditions"),
58-
#[clippy::version = ""]
5963
("clippy::blocks_in_if_conditions", "clippy::blocks_in_conditions"),
60-
#[clippy::version = ""]
6164
("clippy::box_vec", "clippy::box_collection"),
62-
#[clippy::version = ""]
6365
("clippy::const_static_lifetime", "clippy::redundant_static_lifetimes"),
64-
#[clippy::version = ""]
6566
("clippy::cyclomatic_complexity", "clippy::cognitive_complexity"),
66-
#[clippy::version = ""]
6767
("clippy::derive_hash_xor_eq", "clippy::derived_hash_with_manual_eq"),
68-
#[clippy::version = ""]
6968
("clippy::disallowed_method", "clippy::disallowed_methods"),
70-
#[clippy::version = ""]
7169
("clippy::disallowed_type", "clippy::disallowed_types"),
72-
#[clippy::version = ""]
7370
("clippy::eval_order_dependence", "clippy::mixed_read_write_in_expression"),
74-
#[clippy::version = "1.51.0"]
7571
("clippy::find_map", "clippy::manual_find_map"),
76-
#[clippy::version = "1.53.0"]
7772
("clippy::filter_map", "clippy::manual_filter_map"),
78-
#[clippy::version = ""]
7973
("clippy::fn_address_comparisons", "unpredictable_function_pointer_comparisons"),
80-
#[clippy::version = ""]
8174
("clippy::identity_conversion", "clippy::useless_conversion"),
82-
#[clippy::version = "pre 1.29.0"]
8375
("clippy::if_let_redundant_pattern_matching", "clippy::redundant_pattern_matching"),
84-
#[clippy::version = ""]
8576
("clippy::if_let_some_result", "clippy::match_result_ok"),
86-
#[clippy::version = ""]
8777
("clippy::incorrect_clone_impl_on_copy_type", "clippy::non_canonical_clone_impl"),
88-
#[clippy::version = ""]
8978
("clippy::incorrect_partial_ord_impl_on_ord_type", "clippy::non_canonical_partial_ord_impl"),
90-
#[clippy::version = ""]
9179
("clippy::integer_arithmetic", "clippy::arithmetic_side_effects"),
92-
#[clippy::version = ""]
9380
("clippy::logic_bug", "clippy::overly_complex_bool_expr"),
94-
#[clippy::version = ""]
9581
("clippy::new_without_default_derive", "clippy::new_without_default"),
96-
#[clippy::version = ""]
9782
("clippy::option_and_then_some", "clippy::bind_instead_of_map"),
98-
#[clippy::version = ""]
9983
("clippy::option_expect_used", "clippy::expect_used"),
100-
#[clippy::version = ""]
10184
("clippy::option_map_unwrap_or", "clippy::map_unwrap_or"),
102-
#[clippy::version = ""]
10385
("clippy::option_map_unwrap_or_else", "clippy::map_unwrap_or"),
104-
#[clippy::version = ""]
10586
("clippy::option_unwrap_used", "clippy::unwrap_used"),
106-
#[clippy::version = ""]
10787
("clippy::overflow_check_conditional", "clippy::panicking_overflow_checks"),
108-
#[clippy::version = ""]
10988
("clippy::ref_in_deref", "clippy::needless_borrow"),
110-
#[clippy::version = ""]
11189
("clippy::result_expect_used", "clippy::expect_used"),
112-
#[clippy::version = ""]
11390
("clippy::result_map_unwrap_or_else", "clippy::map_unwrap_or"),
114-
#[clippy::version = ""]
11591
("clippy::result_unwrap_used", "clippy::unwrap_used"),
116-
#[clippy::version = ""]
11792
("clippy::single_char_push_str", "clippy::single_char_add_str"),
118-
#[clippy::version = ""]
11993
("clippy::stutter", "clippy::module_name_repetitions"),
120-
#[clippy::version = ""]
12194
("clippy::thread_local_initializer_can_be_made_const", "clippy::missing_const_for_thread_local"),
122-
#[clippy::version = ""]
12395
("clippy::to_string_in_display", "clippy::recursive_format_impl"),
124-
#[clippy::version = ""]
12596
("clippy::unwrap_or_else_default", "clippy::unwrap_or_default"),
126-
#[clippy::version = ""]
12797
("clippy::zero_width_space", "clippy::invisible_characters"),
128-
#[clippy::version = ""]
12998
("clippy::cast_ref_to_mut", "invalid_reference_casting"),
130-
#[clippy::version = ""]
13199
("clippy::clone_double_ref", "suspicious_double_ref_op"),
132-
#[clippy::version = ""]
133100
("clippy::cmp_nan", "invalid_nan_comparisons"),
134-
#[clippy::version = "nightly"]
135101
("clippy::double_neg", "double_negations"),
136-
#[clippy::version = ""]
137102
("clippy::drop_bounds", "drop_bounds"),
138-
#[clippy::version = ""]
139103
("clippy::drop_copy", "dropping_copy_types"),
140-
#[clippy::version = ""]
141104
("clippy::drop_ref", "dropping_references"),
142-
#[clippy::version = ""]
143105
("clippy::fn_null_check", "useless_ptr_null_checks"),
144-
#[clippy::version = ""]
145106
("clippy::for_loop_over_option", "for_loops_over_fallibles"),
146-
#[clippy::version = ""]
147107
("clippy::for_loop_over_result", "for_loops_over_fallibles"),
148-
#[clippy::version = ""]
149108
("clippy::for_loops_over_fallibles", "for_loops_over_fallibles"),
150-
#[clippy::version = ""]
151109
("clippy::forget_copy", "forgetting_copy_types"),
152-
#[clippy::version = ""]
153110
("clippy::forget_ref", "forgetting_references"),
154-
#[clippy::version = ""]
155111
("clippy::into_iter_on_array", "array_into_iter"),
156-
#[clippy::version = ""]
157112
("clippy::invalid_atomic_ordering", "invalid_atomic_ordering"),
158-
#[clippy::version = ""]
159113
("clippy::invalid_ref", "invalid_value"),
160-
#[clippy::version = ""]
161114
("clippy::invalid_utf8_in_unchecked", "invalid_from_utf8_unchecked"),
162-
#[clippy::version = ""]
163115
("clippy::let_underscore_drop", "let_underscore_drop"),
164-
#[clippy::version = "1.80.0"]
165116
("clippy::maybe_misused_cfg", "unexpected_cfgs"),
166-
#[clippy::version = ""]
167117
("clippy::mem_discriminant_non_enum", "enum_intrinsics_non_enums"),
168-
#[clippy::version = "1.80.0"]
169118
("clippy::mismatched_target_os", "unexpected_cfgs"),
170-
#[clippy::version = ""]
171119
("clippy::panic_params", "non_fmt_panics"),
172-
#[clippy::version = ""]
173120
("clippy::positional_named_format_parameters", "named_arguments_used_positionally"),
174-
#[clippy::version = ""]
175121
("clippy::temporary_cstring_as_ptr", "dangling_pointers_from_temporaries"),
176-
#[clippy::version = ""]
177122
("clippy::undropped_manually_drops", "undropped_manually_drops"),
178-
#[clippy::version = ""]
179123
("clippy::unknown_clippy_lints", "unknown_lints"),
180-
#[clippy::version = ""]
181124
("clippy::unused_label", "unused_labels"),
182-
#[clippy::version = ""]
183125
("clippy::vtable_address_comparisons", "ambiguous_wide_pointer_comparisons"),
184-
#[clippy::version = ""]
185126
("clippy::reverse_range_loop", "clippy::reversed_empty_ranges"),
186127
// end renamed lints. used by `cargo dev rename_lint`
187-
]}
128+
];

clippy_lints/src/lib.rs

+2-1
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};
@@ -585,7 +586,7 @@ pub fn register_lints(store: &mut rustc_lint::LintStore, conf: &'static Conf) {
585586
for (old_name, new_name) in deprecated_lints::RENAMED {
586587
store.register_renamed(old_name, new_name);
587588
}
588-
for (name, reason) in deprecated_lints::DEPRECATED {
589+
for Deprecation { name, reason, .. } in deprecated_lints::DEPRECATED {
589590
store.register_removed(name, reason);
590591
}
591592

tests/compile-test.rs

+9-11
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use cargo_metadata::diagnostic::{Applicability, Diagnostic};
77
use clippy_config::ClippyConfiguration;
88
use clippy_lints::LintInfo;
99
use clippy_lints::declared_lints::LINTS;
10-
use clippy_lints::deprecated_lints::{DEPRECATED, DEPRECATED_VERSION, RENAMED};
10+
use clippy_lints::deprecated_lints::{DEPRECATED, Deprecation, RENAMED};
1111
use pulldown_cmark::{Options, Parser, html};
1212
use rinja::Template;
1313
use rinja::filters::Safe;
@@ -24,7 +24,7 @@ use std::ffi::{OsStr, OsString};
2424
use std::fmt::Write;
2525
use std::path::{Path, PathBuf};
2626
use std::sync::mpsc::{Sender, channel};
27-
use std::{fs, iter, thread};
27+
use std::{fs, thread};
2828

2929
// Test dependencies may need an `extern crate` here to ensure that they show up
3030
// in the depinfo file (otherwise cargo thinks they are unused)
@@ -466,10 +466,7 @@ impl DiagnosticCollector {
466466
let mut metadata: Vec<LintMetadata> = LINTS
467467
.iter()
468468
.map(|lint| LintMetadata::new(lint, &applicabilities, &configs))
469-
.chain(
470-
iter::zip(DEPRECATED, DEPRECATED_VERSION)
471-
.map(|((lint, reason), version)| LintMetadata::new_deprecated(lint, reason, version)),
472-
)
469+
.chain(DEPRECATED.iter().copied().map(LintMetadata::new_deprecated))
473470
.collect();
474471

475472
metadata.sort_unstable_by(|a, b| a.id.cmp(&b.id));
@@ -568,24 +565,25 @@ impl LintMetadata {
568565
}
569566
}
570567

571-
fn new_deprecated(name: &str, reason: &str, version: &'static str) -> Self {
568+
fn new_deprecated(deprecated: Deprecation) -> Self {
572569
// The reason starts with a lowercase letter and ends without a period.
573570
// This needs to be fixed for the website.
574-
let mut reason = reason.to_owned();
571+
let mut reason = deprecated.reason.to_owned();
575572
if let Some(reason) = reason.get_mut(0..1) {
576573
reason.make_ascii_uppercase();
577574
}
578575
Self {
579-
id: name.strip_prefix("clippy::").unwrap().into(),
576+
id: deprecated.name.strip_prefix("clippy::").unwrap().into(),
580577
id_location: None,
581578
group: "deprecated",
582579
level: "none",
583580
docs: format!(
584581
"### What it does\n\n\
585582
Nothing. This lint has been deprecated\n\n\
586-
### Deprecation reason\n\n{reason}.\n",
583+
### Deprecation reason\n\n{}.\n",
584+
deprecated.reason,
587585
),
588-
version,
586+
version: deprecated.version,
589587
applicability: Applicability::Unspecified,
590588
}
591589
}

tests/lint-definitions.rs

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#![feature(rustc_private)]
2+
3+
use clippy_lints::declared_lints::LINTS;
4+
use clippy_lints::deprecated_lints::DEPRECATED;
5+
use test_utils::IS_RUSTC_TEST_SUITE;
6+
7+
mod test_utils;
8+
9+
#[test]
10+
fn no_nightly_versions_in_rust_repo() {
11+
if !IS_RUSTC_TEST_SUITE {
12+
return;
13+
}
14+
15+
let mut failed = false;
16+
17+
for lint in LINTS {
18+
if lint.version == Some("nightly") {
19+
let name = lint.name_lower();
20+
let location = lint.location.replace("#L", ":");
21+
println!(r#"{location}: {name} has #[clippy::version = "nightly"]"#);
22+
failed = true;
23+
}
24+
}
25+
26+
for deprecation in DEPRECATED {
27+
if deprecation.version == "nightly" {
28+
let name = deprecation.name.strip_prefix("clippy::").unwrap();
29+
println!(r#"clippy_lints/src/deprecated_lints.rs: {name} has #[clippy::version = "nightly"]"#);
30+
failed = true;
31+
}
32+
}
33+
34+
assert!(!failed);
35+
}
File renamed without changes.

0 commit comments

Comments
 (0)