Skip to content

Move internal lints to their own crate #13223

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

Merged
merged 1 commit into from
Apr 18, 2025
Merged
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
2 changes: 1 addition & 1 deletion .github/workflows/clippy_mq.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ jobs:
run: cargo test --features internal -- --skip dogfood

- name: Test clippy_lints
run: cargo test --features internal
run: cargo test
working-directory: clippy_lints

- name: Test clippy_utils
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/clippy_pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:
run: cargo test --features internal

- name: Test clippy_lints
run: cargo test --features internal
run: cargo test
working-directory: clippy_lints

- name: Test clippy_utils
Expand Down
5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ path = "src/driver.rs"
clippy_config = { path = "clippy_config" }
clippy_lints = { path = "clippy_lints" }
rustc_tools_util = { path = "rustc_tools_util", version = "0.4.2" }
clippy_lints_internal = { path = "clippy_lints_internal", optional = true }
tempfile = { version = "3.3", optional = true }
termize = "0.1"
color-print = "0.3.4"
Expand Down Expand Up @@ -57,8 +58,8 @@ tokio = { version = "1", features = ["io-util"] }
rustc_tools_util = { path = "rustc_tools_util", version = "0.4.2" }

[features]
integration = ["tempfile"]
internal = ["clippy_lints/internal", "tempfile"]
integration = ["dep:tempfile"]
internal = ["dep:clippy_lints_internal", "dep:tempfile"]

[package.metadata.rust-analyzer]
# This package uses #[feature(rustc_private)]
Expand Down
3 changes: 1 addition & 2 deletions book/src/development/defining_lints.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ lint involves some boilerplate code.

A lint type is the category of items and expressions in which your lint focuses on.

As of the writing of this documentation update, there are 12 _types_ of lints
As of the writing of this documentation update, there are 11 _types_ of lints
besides the numerous standalone lints living under `clippy_lints/src/`:

- `cargo`
Expand All @@ -23,7 +23,6 @@ besides the numerous standalone lints living under `clippy_lints/src/`:
- `transmute`
- `types`
- `unit_types`
- `utils / internal` (Clippy internal lints)

These types group together lints that share some common behaviors. For instance,
`functions` groups together lints that deal with some aspects of functions in
Expand Down
1 change: 0 additions & 1 deletion clippy_dev/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,6 @@ enum DevCommand {
"restriction",
"cargo",
"nursery",
"internal",
],
default_value = "nursery",
)]
Expand Down
90 changes: 14 additions & 76 deletions clippy_dev/src/update_lints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,16 @@ fn generate_lint_files(
deprecated_lints: &[DeprecatedLint],
renamed_lints: &[RenamedLint],
) {
let internal_lints = Lint::internal_lints(lints);
let mut usable_lints = Lint::usable_lints(lints);
usable_lints.sort_by_key(|lint| lint.name.clone());
let mut lints = lints.to_owned();
lints.sort_by_key(|lint| lint.name.clone());

replace_region_in_file(
update_mode,
Path::new("README.md"),
"[There are over ",
" lints included in this crate!]",
|res| {
write!(res, "{}", round_to_fifty(usable_lints.len())).unwrap();
write!(res, "{}", round_to_fifty(lints.len())).unwrap();
},
);

Expand All @@ -57,7 +56,7 @@ fn generate_lint_files(
"[There are over ",
" lints included in this crate!]",
|res| {
write!(res, "{}", round_to_fifty(usable_lints.len())).unwrap();
write!(res, "{}", round_to_fifty(lints.len())).unwrap();
},
);

Expand All @@ -67,7 +66,7 @@ fn generate_lint_files(
"<!-- begin autogenerated links to lint list -->\n",
"<!-- end autogenerated links to lint list -->",
|res| {
for lint in usable_lints
for lint in lints
.iter()
.map(|l| &*l.name)
.chain(deprecated_lints.iter().filter_map(|l| l.name.strip_prefix("clippy::")))
Expand All @@ -86,7 +85,7 @@ fn generate_lint_files(
"// begin lints modules, do not remove this comment, it’s used in `update_lints`\n",
"// end lints modules, do not remove this comment, it’s used in `update_lints`",
|res| {
for lint_mod in usable_lints.iter().map(|l| &l.module).unique().sorted() {
for lint_mod in lints.iter().map(|l| &l.module).unique().sorted() {
writeln!(res, "mod {lint_mod};").unwrap();
}
},
Expand All @@ -95,7 +94,7 @@ fn generate_lint_files(
process_file(
"clippy_lints/src/declared_lints.rs",
update_mode,
&gen_declared_lints(internal_lints.iter(), usable_lints.iter()),
&gen_declared_lints(lints.iter()),
);

let content = gen_deprecated_lints_test(deprecated_lints);
Expand All @@ -106,10 +105,9 @@ fn generate_lint_files(
}

pub fn print_lints() {
let (lint_list, _, _) = gather_all();
let usable_lints = Lint::usable_lints(&lint_list);
let usable_lint_count = usable_lints.len();
let grouped_by_lint_group = Lint::by_lint_group(usable_lints.into_iter());
let (lints, _, _) = gather_all();
let lint_count = lints.len();
let grouped_by_lint_group = Lint::by_lint_group(lints.into_iter());

for (lint_group, mut lints) in grouped_by_lint_group {
println!("\n## {lint_group}");
Expand All @@ -121,7 +119,7 @@ pub fn print_lints() {
}
}

println!("there are {usable_lint_count} lints");
println!("there are {lint_count} lints");
}

/// Runs the `rename_lint` command.
Expand Down Expand Up @@ -527,22 +525,6 @@ impl Lint {
}
}

/// Returns all non-deprecated lints and non-internal lints
#[must_use]
fn usable_lints(lints: &[Self]) -> Vec<Self> {
lints
.iter()
.filter(|l| !l.group.starts_with("internal"))
.cloned()
.collect()
}

/// Returns all internal lints
#[must_use]
fn internal_lints(lints: &[Self]) -> Vec<Self> {
lints.iter().filter(|l| l.group == "internal").cloned().collect()
}

/// Returns the lints in a `HashMap`, grouped by the different lint groups
#[must_use]
fn by_lint_group(lints: impl Iterator<Item = Self>) -> HashMap<String, Vec<Self>> {
Expand Down Expand Up @@ -579,23 +561,14 @@ impl RenamedLint {

/// Generates the code for registering lints
#[must_use]
fn gen_declared_lints<'a>(
internal_lints: impl Iterator<Item = &'a Lint>,
usable_lints: impl Iterator<Item = &'a Lint>,
) -> String {
let mut details: Vec<_> = internal_lints
.map(|l| (false, &l.module, l.name.to_uppercase()))
.chain(usable_lints.map(|l| (true, &l.module, l.name.to_uppercase())))
.collect();
fn gen_declared_lints<'a>(lints: impl Iterator<Item = &'a Lint>) -> String {
let mut details: Vec<_> = lints.map(|l| (&l.module, l.name.to_uppercase())).collect();
details.sort_unstable();

let mut output = GENERATED_FILE_COMMENT.to_string();
output.push_str("pub static LINTS: &[&crate::LintInfo] = &[\n");

for (is_public, module_name, lint_name) in details {
if !is_public {
output.push_str(" #[cfg(feature = \"internal\")]\n");
}
for (module_name, lint_name) in details {
let _: fmt::Result = writeln!(output, " crate::{module_name}::{lint_name}_INFO,");
}
output.push_str("];\n");
Expand Down Expand Up @@ -936,41 +909,6 @@ mod tests {
assert_eq!(expected, result);
}

#[test]
fn test_usable_lints() {
let lints = vec![
Lint::new(
"should_assert_eq2",
"Not Deprecated",
"\"abc\"",
"module_name",
Range::default(),
),
Lint::new(
"should_assert_eq2",
"internal",
"\"abc\"",
"module_name",
Range::default(),
),
Lint::new(
"should_assert_eq2",
"internal_style",
"\"abc\"",
"module_name",
Range::default(),
),
];
let expected = vec![Lint::new(
"should_assert_eq2",
"Not Deprecated",
"\"abc\"",
"module_name",
Range::default(),
)];
assert_eq!(expected, Lint::usable_lints(&lints));
}

#[test]
fn test_by_lint_group() {
let lints = vec![
Expand Down
7 changes: 0 additions & 7 deletions clippy_lints/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@ itertools = "0.12"
quine-mc_cluskey = "0.2"
regex-syntax = "0.8"
serde = { version = "1.0", features = ["derive"] }
serde_json = { version = "1.0", optional = true }
tempfile = { version = "3.3.0", optional = true }
toml = "0.7.3"
regex = { version = "1.5", optional = true }
unicode-normalization = "0.1"
unicode-script = { version = "0.5", default-features = false }
semver = "1.0"
Expand All @@ -31,10 +28,6 @@ url = "2.2"
[dev-dependencies]
walkdir = "2.3"

[features]
# build clippy with internal lints enabled, off by default
internal = ["serde_json", "tempfile", "regex"]

[package.metadata.rust-analyzer]
# This crate uses #[feature(rustc_private)]
rustc_private = true
13 changes: 0 additions & 13 deletions clippy_lints/src/declare_clippy_lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,17 +165,4 @@ macro_rules! declare_clippy_lint {
$(, $eval_always)?
}
};

(
$(#[doc = $lit:literal])*
pub $lint_name:ident,
internal,
$desc:literal
) => {
declare_clippy_lint! {@
$(#[doc = $lit])*
pub $lint_name, Allow, crate::LintCategory::Internal, $desc,
None, "0.0.0"
}
};
}
30 changes: 0 additions & 30 deletions clippy_lints/src/declared_lints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,6 @@
// Manual edits will be overwritten.

pub static LINTS: &[&crate::LintInfo] = &[
#[cfg(feature = "internal")]
crate::utils::internal_lints::almost_standard_lint_formulation::ALMOST_STANDARD_LINT_FORMULATION_INFO,
#[cfg(feature = "internal")]
crate::utils::internal_lints::collapsible_calls::COLLAPSIBLE_SPAN_LINT_CALLS_INFO,
#[cfg(feature = "internal")]
crate::utils::internal_lints::interning_defined_symbol::INTERNING_DEFINED_SYMBOL_INFO,
#[cfg(feature = "internal")]
crate::utils::internal_lints::interning_defined_symbol::UNNECESSARY_SYMBOL_STR_INFO,
#[cfg(feature = "internal")]
crate::utils::internal_lints::invalid_paths::INVALID_PATHS_INFO,
#[cfg(feature = "internal")]
crate::utils::internal_lints::lint_without_lint_pass::DEFAULT_LINT_INFO,
#[cfg(feature = "internal")]
crate::utils::internal_lints::lint_without_lint_pass::INVALID_CLIPPY_VERSION_ATTRIBUTE_INFO,
#[cfg(feature = "internal")]
crate::utils::internal_lints::lint_without_lint_pass::LINT_WITHOUT_LINT_PASS_INFO,
#[cfg(feature = "internal")]
crate::utils::internal_lints::lint_without_lint_pass::MISSING_CLIPPY_VERSION_ATTRIBUTE_INFO,
#[cfg(feature = "internal")]
crate::utils::internal_lints::msrv_attr_impl::MISSING_MSRV_ATTR_IMPL_INFO,
#[cfg(feature = "internal")]
crate::utils::internal_lints::outer_expn_data_pass::OUTER_EXPN_EXPN_DATA_INFO,
#[cfg(feature = "internal")]
crate::utils::internal_lints::produce_ice::PRODUCE_ICE_INFO,
#[cfg(feature = "internal")]
crate::utils::internal_lints::slow_symbol_comparisons::SLOW_SYMBOL_COMPARISONS_INFO,
#[cfg(feature = "internal")]
crate::utils::internal_lints::unnecessary_def_path::UNNECESSARY_DEF_PATH_INFO,
#[cfg(feature = "internal")]
crate::utils::internal_lints::unsorted_clippy_utils_paths::UNSORTED_CLIPPY_UTILS_PATHS_INFO,
crate::absolute_paths::ABSOLUTE_PATHS_INFO,
crate::almost_complete_range::ALMOST_COMPLETE_RANGE_INFO,
crate::approx_const::APPROX_CONSTANT_INFO,
Expand Down
Loading