Skip to content

Create new lints with #[clippy::version = "nightly"] #14299

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions book/src/development/adding_lints.md
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ declare_clippy_lint! {
/// ```rust
/// // example code
/// ```
#[clippy::version = "1.29.0"]
#[clippy::version = "nightly"]
pub FOO_FUNCTIONS,
pedantic,
"function named `foo`, which is not a descriptive name"
Expand Down Expand Up @@ -587,7 +587,7 @@ declare_clippy_lint! {
/// ```rust,ignore
/// // A short example of improved code that doesn't trigger the lint
/// ```
#[clippy::version = "1.29.0"]
#[clippy::version = "nightly"]
pub FOO_FUNCTIONS,
pedantic,
"function named `foo`, which is not a descriptive name"
Expand Down
4 changes: 2 additions & 2 deletions book/src/development/defining_lints.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,10 @@ declare_clippy_lint! {
/// ```rust
/// // example code which does not raise Clippy warning
/// ```
#[clippy::version = "1.70.0"] // <- In which version was this implemented, keep it up to date!
#[clippy::version = "nightly"]
pub LINT_NAME, // <- The lint name IN_ALL_CAPS
pedantic, // <- The lint group
"default lint description" // <- A lint description, e.g. "A function has an unit return type."
"default lint description" // <- A lint description, e.g. "A function has an unit return type"
}
```

Expand Down
8 changes: 6 additions & 2 deletions book/src/development/infrastructure/changelog_update.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,12 @@ that label in the changelog. If you can, remove the `beta-accepted` labels

### 4. Update `clippy::version` attributes

Next, make sure to check that the `#[clippy::version]` attributes for the added
lints contain the correct version.
Next, make sure to check that the `#[clippy::version]` attributes for the newly
added and deprecated lints contain the version of the release you're writing the
changelog for.

Newly created lints will have `#[clippy::version = "nightly"]` and be handled
during the sync, but many existing PRs will still have an incorrect version.

[changelog]: https://github.com/rust-lang/rust-clippy/blob/master/CHANGELOG.md
[forge]: https://forge.rust-lang.org/
Expand Down
10 changes: 2 additions & 8 deletions clippy_dev/src/new_lint.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::utils::{clippy_project_root, clippy_version};
use crate::utils::clippy_project_root;
use clap::ValueEnum;
use indoc::{formatdoc, writedoc};
use std::fmt::{self, Write as _};
Expand Down Expand Up @@ -193,11 +193,6 @@ fn to_camel_case(name: &str) -> String {
.collect()
}

pub(crate) fn get_stabilization_version() -> String {
let (minor, patch) = clippy_version();
format!("{minor}.{patch}.0")
}

fn get_test_file_contents(lint_name: &str, msrv: bool) -> String {
let mut test = formatdoc!(
r"
Expand Down Expand Up @@ -351,13 +346,12 @@ fn get_lint_declaration(name_upper: &str, category: &str) -> String {
/// ```no_run
/// // example code which does not raise clippy warning
/// ```
#[clippy::version = "{}"]
#[clippy::version = "nightly"]
pub {name_upper},
{category},
"default lint description"
}}
"#,
get_stabilization_version(),
)
}

Expand Down
15 changes: 5 additions & 10 deletions clippy_dev/src/update_lints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,16 +196,11 @@ pub fn rename(old_name: &str, new_name: &str, uplift: bool) {
});
}

let version = crate::new_lint::get_stabilization_version();
rewrite_file(Path::new("clippy_lints/src/deprecated_lints.rs"), |s| {
insert_at_marker(
s,
"// end renamed lints. used by `cargo dev rename_lint`",
&format!(
"#[clippy::version = \"{version}\"]\n \
(\"{}\", \"{}\"),\n ",
lint.old_name, lint.new_name,
),
&format!("(\"{}\", \"{}\"),\n ", lint.old_name, lint.new_name,),
)
});

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

if remove_lint_declaration(stripped_name, &mod_path, &mut lints).unwrap_or(false) {
let version = crate::new_lint::get_stabilization_version();
rewrite_file(deprecated_lints_path, |s| {
insert_at_marker(
s,
"// end deprecated lints. used by `cargo dev deprecate_lint`",
&format!("#[clippy::version = \"{version}\"]\n (\"{prefixed_name}\", \"{reason}\"),\n ",),
&format!("#[clippy::version = \"nightly\"]\n (\"{prefixed_name}\", \"{reason}\"),\n ",),
)
});

Expand Down Expand Up @@ -547,6 +541,7 @@ impl DeprecatedLint {
}
}

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

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

Expand Down
102 changes: 21 additions & 81 deletions clippy_lints/src/deprecated_lints.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,28 @@
// This file is managed by `cargo dev rename_lint` and `cargo dev deprecate_lint`.
// Prefer to use those when possible.

macro_rules! declare_with_version {
($name:ident($name_version:ident): &[$ty:ty] = &[$(
#[derive(Copy, Clone, Debug)]
pub struct Deprecation {
pub name: &'static str,
pub reason: &'static str,
pub version: &'static str,
}

macro_rules! deprecated {
($(
#[clippy::version = $version:literal]
$e:expr,
)*]) => {
pub static $name: &[$ty] = &[$($e),*];
#[allow(unused)]
pub static $name_version: &[&str] = &[$($version),*];
($name:literal, $reason:literal),
)*) => {
pub const DEPRECATED: &[Deprecation] = &[$(Deprecation {
name: $name,
reason: $reason,
version: $version,
}),*];
};
}

#[rustfmt::skip]
declare_with_version! { DEPRECATED(DEPRECATED_VERSION): &[(&str, &str)] = &[
deprecated![
#[clippy::version = "pre 1.29.0"]
("clippy::should_assert_eq", "`assert!(a == b)` can now print the values the same way `assert_eq!(a, b) can"),
#[clippy::version = "pre 1.29.0"]
Expand All @@ -40,152 +49,83 @@ declare_with_version! { DEPRECATED(DEPRECATED_VERSION): &[(&str, &str)] = &[
("clippy::pub_enum_variant_names", "`clippy::enum_variant_names` now covers this case via the `avoid-breaking-exported-api` config"),
#[clippy::version = "1.54.0"]
("clippy::wrong_pub_self_convention", "`clippy::wrong_self_convention` now covers this case via the `avoid-breaking-exported-api` config"),
#[clippy::version = "1.86.0"]
#[clippy::version = "nightly"]
("clippy::option_map_or_err_ok", "`clippy::manual_ok_or` covers this case"),
#[clippy::version = "1.86.0"]
("clippy::match_on_vec_items", "`clippy::indexing_slicing` covers indexing and slicing on `Vec<_>`"),
// end deprecated lints. used by `cargo dev deprecate_lint`
]}
];

#[rustfmt::skip]
declare_with_version! { RENAMED(RENAMED_VERSION): &[(&str, &str)] = &[
#[clippy::version = ""]
pub const RENAMED: &[(&str, &str)] = &[
("clippy::almost_complete_letter_range", "clippy::almost_complete_range"),
#[clippy::version = ""]
("clippy::blacklisted_name", "clippy::disallowed_names"),
#[clippy::version = ""]
("clippy::block_in_if_condition_expr", "clippy::blocks_in_conditions"),
#[clippy::version = ""]
("clippy::block_in_if_condition_stmt", "clippy::blocks_in_conditions"),
#[clippy::version = ""]
("clippy::blocks_in_if_conditions", "clippy::blocks_in_conditions"),
#[clippy::version = ""]
("clippy::box_vec", "clippy::box_collection"),
#[clippy::version = ""]
("clippy::const_static_lifetime", "clippy::redundant_static_lifetimes"),
#[clippy::version = ""]
("clippy::cyclomatic_complexity", "clippy::cognitive_complexity"),
#[clippy::version = ""]
("clippy::derive_hash_xor_eq", "clippy::derived_hash_with_manual_eq"),
#[clippy::version = ""]
("clippy::disallowed_method", "clippy::disallowed_methods"),
#[clippy::version = ""]
("clippy::disallowed_type", "clippy::disallowed_types"),
#[clippy::version = ""]
("clippy::eval_order_dependence", "clippy::mixed_read_write_in_expression"),
#[clippy::version = "1.51.0"]
("clippy::find_map", "clippy::manual_find_map"),
#[clippy::version = "1.53.0"]
("clippy::filter_map", "clippy::manual_filter_map"),
#[clippy::version = ""]
("clippy::fn_address_comparisons", "unpredictable_function_pointer_comparisons"),
#[clippy::version = ""]
("clippy::identity_conversion", "clippy::useless_conversion"),
#[clippy::version = "pre 1.29.0"]
("clippy::if_let_redundant_pattern_matching", "clippy::redundant_pattern_matching"),
#[clippy::version = ""]
("clippy::if_let_some_result", "clippy::match_result_ok"),
#[clippy::version = ""]
("clippy::incorrect_clone_impl_on_copy_type", "clippy::non_canonical_clone_impl"),
#[clippy::version = ""]
("clippy::incorrect_partial_ord_impl_on_ord_type", "clippy::non_canonical_partial_ord_impl"),
#[clippy::version = ""]
("clippy::integer_arithmetic", "clippy::arithmetic_side_effects"),
#[clippy::version = ""]
("clippy::logic_bug", "clippy::overly_complex_bool_expr"),
#[clippy::version = ""]
("clippy::new_without_default_derive", "clippy::new_without_default"),
#[clippy::version = ""]
("clippy::option_and_then_some", "clippy::bind_instead_of_map"),
#[clippy::version = ""]
("clippy::option_expect_used", "clippy::expect_used"),
#[clippy::version = ""]
("clippy::option_map_unwrap_or", "clippy::map_unwrap_or"),
#[clippy::version = ""]
("clippy::option_map_unwrap_or_else", "clippy::map_unwrap_or"),
#[clippy::version = ""]
("clippy::option_unwrap_used", "clippy::unwrap_used"),
#[clippy::version = ""]
("clippy::overflow_check_conditional", "clippy::panicking_overflow_checks"),
#[clippy::version = ""]
("clippy::ref_in_deref", "clippy::needless_borrow"),
#[clippy::version = ""]
("clippy::result_expect_used", "clippy::expect_used"),
#[clippy::version = ""]
("clippy::result_map_unwrap_or_else", "clippy::map_unwrap_or"),
#[clippy::version = ""]
("clippy::result_unwrap_used", "clippy::unwrap_used"),
#[clippy::version = ""]
("clippy::single_char_push_str", "clippy::single_char_add_str"),
#[clippy::version = ""]
("clippy::stutter", "clippy::module_name_repetitions"),
#[clippy::version = ""]
("clippy::thread_local_initializer_can_be_made_const", "clippy::missing_const_for_thread_local"),
#[clippy::version = ""]
("clippy::to_string_in_display", "clippy::recursive_format_impl"),
#[clippy::version = ""]
("clippy::unwrap_or_else_default", "clippy::unwrap_or_default"),
#[clippy::version = ""]
("clippy::zero_width_space", "clippy::invisible_characters"),
#[clippy::version = ""]
("clippy::cast_ref_to_mut", "invalid_reference_casting"),
#[clippy::version = ""]
("clippy::clone_double_ref", "suspicious_double_ref_op"),
#[clippy::version = ""]
("clippy::cmp_nan", "invalid_nan_comparisons"),
#[clippy::version = "CURRENT_RUSTC_VERSION"]
("clippy::invalid_null_ptr_usage", "invalid_null_arguments"),
#[clippy::version = "1.86.0"]
("clippy::double_neg", "double_negations"),
#[clippy::version = ""]
("clippy::drop_bounds", "drop_bounds"),
#[clippy::version = ""]
("clippy::drop_copy", "dropping_copy_types"),
#[clippy::version = ""]
("clippy::drop_ref", "dropping_references"),
#[clippy::version = ""]
("clippy::fn_null_check", "useless_ptr_null_checks"),
#[clippy::version = ""]
("clippy::for_loop_over_option", "for_loops_over_fallibles"),
#[clippy::version = ""]
("clippy::for_loop_over_result", "for_loops_over_fallibles"),
#[clippy::version = ""]
("clippy::for_loops_over_fallibles", "for_loops_over_fallibles"),
#[clippy::version = ""]
("clippy::forget_copy", "forgetting_copy_types"),
#[clippy::version = ""]
("clippy::forget_ref", "forgetting_references"),
#[clippy::version = ""]
("clippy::into_iter_on_array", "array_into_iter"),
#[clippy::version = ""]
("clippy::invalid_atomic_ordering", "invalid_atomic_ordering"),
#[clippy::version = ""]
("clippy::invalid_ref", "invalid_value"),
#[clippy::version = ""]
("clippy::invalid_utf8_in_unchecked", "invalid_from_utf8_unchecked"),
#[clippy::version = ""]
("clippy::let_underscore_drop", "let_underscore_drop"),
#[clippy::version = "1.80.0"]
("clippy::maybe_misused_cfg", "unexpected_cfgs"),
#[clippy::version = ""]
("clippy::mem_discriminant_non_enum", "enum_intrinsics_non_enums"),
#[clippy::version = "1.80.0"]
("clippy::mismatched_target_os", "unexpected_cfgs"),
#[clippy::version = ""]
("clippy::panic_params", "non_fmt_panics"),
#[clippy::version = ""]
("clippy::positional_named_format_parameters", "named_arguments_used_positionally"),
#[clippy::version = ""]
("clippy::temporary_cstring_as_ptr", "dangling_pointers_from_temporaries"),
#[clippy::version = ""]
("clippy::undropped_manually_drops", "undropped_manually_drops"),
#[clippy::version = ""]
("clippy::unknown_clippy_lints", "unknown_lints"),
#[clippy::version = ""]
("clippy::unused_label", "unused_labels"),
#[clippy::version = ""]
("clippy::vtable_address_comparisons", "ambiguous_wide_pointer_comparisons"),
#[clippy::version = ""]
("clippy::reverse_range_loop", "clippy::reversed_empty_ranges"),
// end renamed lints. used by `cargo dev rename_lint`
]}
];
3 changes: 2 additions & 1 deletion clippy_lints/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,7 @@ mod zombie_processes;

use clippy_config::{Conf, get_configuration_metadata, sanitize_explanation};
use clippy_utils::macros::FormatArgsStorage;
use deprecated_lints::Deprecation;
use rustc_data_structures::fx::FxHashSet;
use rustc_lint::{Lint, LintId};
use utils::attr_collector::{AttrCollector, AttrStorage};
Expand Down Expand Up @@ -560,7 +561,7 @@ pub fn register_lints(store: &mut rustc_lint::LintStore, conf: &'static Conf) {
for (old_name, new_name) in deprecated_lints::RENAMED {
store.register_renamed(old_name, new_name);
}
for (name, reason) in deprecated_lints::DEPRECATED {
for Deprecation { name, reason, .. } in deprecated_lints::DEPRECATED {
store.register_removed(name, reason);
}

Expand Down
2 changes: 1 addition & 1 deletion clippy_lints_internal/src/lint_without_lint_pass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ pub(super) fn is_lint_ref_type(cx: &LateContext<'_>, ty: &hir::Ty<'_>) -> bool {

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

Expand Down
Loading