Skip to content

Commit 781fdab

Browse files
authored
Move internal lints to their own crate (#13223)
This makes it so switching the internal feature on/off no longer rebuilds `clippy_lints`. r? @flip1995 changelog: none
2 parents bcd76c3 + 5b4b463 commit 781fdab

File tree

63 files changed

+295
-333
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+295
-333
lines changed

.github/workflows/clippy_mq.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ jobs:
6666
run: cargo test --features internal -- --skip dogfood
6767

6868
- name: Test clippy_lints
69-
run: cargo test --features internal
69+
run: cargo test
7070
working-directory: clippy_lints
7171

7272
- name: Test clippy_utils

.github/workflows/clippy_pr.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ jobs:
4242
run: cargo test --features internal
4343

4444
- name: Test clippy_lints
45-
run: cargo test --features internal
45+
run: cargo test
4646
working-directory: clippy_lints
4747

4848
- name: Test clippy_utils

Cargo.toml

+3-2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ clippy_config = { path = "clippy_config" }
2727
clippy_lints = { path = "clippy_lints" }
2828
clippy_utils = { path = "clippy_utils" }
2929
rustc_tools_util = { path = "rustc_tools_util", version = "0.4.2" }
30+
clippy_lints_internal = { path = "clippy_lints_internal", optional = true }
3031
tempfile = { version = "3.3", optional = true }
3132
termize = "0.1"
3233
color-print = "0.3.4"
@@ -58,8 +59,8 @@ tokio = { version = "1", features = ["io-util"] }
5859
rustc_tools_util = { path = "rustc_tools_util", version = "0.4.2" }
5960

6061
[features]
61-
integration = ["tempfile"]
62-
internal = ["clippy_lints/internal", "tempfile"]
62+
integration = ["dep:tempfile"]
63+
internal = ["dep:clippy_lints_internal", "dep:tempfile"]
6364

6465
[package.metadata.rust-analyzer]
6566
# This package uses #[feature(rustc_private)]

book/src/development/defining_lints.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ lint involves some boilerplate code.
99

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

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

1515
- `cargo`
@@ -23,7 +23,6 @@ besides the numerous standalone lints living under `clippy_lints/src/`:
2323
- `transmute`
2424
- `types`
2525
- `unit_types`
26-
- `utils / internal` (Clippy internal lints)
2726

2827
These types group together lints that share some common behaviors. For instance,
2928
`functions` groups together lints that deal with some aspects of functions in

clippy_dev/src/main.rs

-1
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,6 @@ enum DevCommand {
170170
"restriction",
171171
"cargo",
172172
"nursery",
173-
"internal",
174173
],
175174
default_value = "nursery",
176175
)]

clippy_dev/src/update_lints.rs

+14-76
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,16 @@ fn generate_lint_files(
3838
deprecated_lints: &[DeprecatedLint],
3939
renamed_lints: &[RenamedLint],
4040
) {
41-
let internal_lints = Lint::internal_lints(lints);
42-
let mut usable_lints = Lint::usable_lints(lints);
43-
usable_lints.sort_by_key(|lint| lint.name.clone());
41+
let mut lints = lints.to_owned();
42+
lints.sort_by_key(|lint| lint.name.clone());
4443

4544
replace_region_in_file(
4645
update_mode,
4746
Path::new("README.md"),
4847
"[There are over ",
4948
" lints included in this crate!]",
5049
|res| {
51-
write!(res, "{}", round_to_fifty(usable_lints.len())).unwrap();
50+
write!(res, "{}", round_to_fifty(lints.len())).unwrap();
5251
},
5352
);
5453

@@ -58,7 +57,7 @@ fn generate_lint_files(
5857
"[There are over ",
5958
" lints included in this crate!]",
6059
|res| {
61-
write!(res, "{}", round_to_fifty(usable_lints.len())).unwrap();
60+
write!(res, "{}", round_to_fifty(lints.len())).unwrap();
6261
},
6362
);
6463

@@ -68,7 +67,7 @@ fn generate_lint_files(
6867
"<!-- begin autogenerated links to lint list -->\n",
6968
"<!-- end autogenerated links to lint list -->",
7069
|res| {
71-
for lint in usable_lints
70+
for lint in lints
7271
.iter()
7372
.map(|l| &*l.name)
7473
.chain(deprecated_lints.iter().filter_map(|l| l.name.strip_prefix("clippy::")))
@@ -87,7 +86,7 @@ fn generate_lint_files(
8786
"// begin lints modules, do not remove this comment, it’s used in `update_lints`\n",
8887
"// end lints modules, do not remove this comment, it’s used in `update_lints`",
8988
|res| {
90-
for lint_mod in usable_lints.iter().map(|l| &l.module).unique().sorted() {
89+
for lint_mod in lints.iter().map(|l| &l.module).unique().sorted() {
9190
writeln!(res, "mod {lint_mod};").unwrap();
9291
}
9392
},
@@ -96,7 +95,7 @@ fn generate_lint_files(
9695
process_file(
9796
"clippy_lints/src/declared_lints.rs",
9897
update_mode,
99-
&gen_declared_lints(internal_lints.iter(), usable_lints.iter()),
98+
&gen_declared_lints(lints.iter()),
10099
);
101100

102101
let content = gen_deprecated_lints_test(deprecated_lints);
@@ -107,10 +106,9 @@ fn generate_lint_files(
107106
}
108107

109108
pub fn print_lints() {
110-
let (lint_list, _, _) = gather_all();
111-
let usable_lints = Lint::usable_lints(&lint_list);
112-
let usable_lint_count = usable_lints.len();
113-
let grouped_by_lint_group = Lint::by_lint_group(usable_lints.into_iter());
109+
let (lints, _, _) = gather_all();
110+
let lint_count = lints.len();
111+
let grouped_by_lint_group = Lint::by_lint_group(lints.into_iter());
114112

115113
for (lint_group, mut lints) in grouped_by_lint_group {
116114
println!("\n## {lint_group}");
@@ -122,7 +120,7 @@ pub fn print_lints() {
122120
}
123121
}
124122

125-
println!("there are {usable_lint_count} lints");
123+
println!("there are {lint_count} lints");
126124
}
127125

128126
/// Runs the `rename_lint` command.
@@ -528,22 +526,6 @@ impl Lint {
528526
}
529527
}
530528

531-
/// Returns all non-deprecated lints and non-internal lints
532-
#[must_use]
533-
fn usable_lints(lints: &[Self]) -> Vec<Self> {
534-
lints
535-
.iter()
536-
.filter(|l| !l.group.starts_with("internal"))
537-
.cloned()
538-
.collect()
539-
}
540-
541-
/// Returns all internal lints
542-
#[must_use]
543-
fn internal_lints(lints: &[Self]) -> Vec<Self> {
544-
lints.iter().filter(|l| l.group == "internal").cloned().collect()
545-
}
546-
547529
/// Returns the lints in a `HashMap`, grouped by the different lint groups
548530
#[must_use]
549531
fn by_lint_group(lints: impl Iterator<Item = Self>) -> HashMap<String, Vec<Self>> {
@@ -580,23 +562,14 @@ impl RenamedLint {
580562

581563
/// Generates the code for registering lints
582564
#[must_use]
583-
fn gen_declared_lints<'a>(
584-
internal_lints: impl Iterator<Item = &'a Lint>,
585-
usable_lints: impl Iterator<Item = &'a Lint>,
586-
) -> String {
587-
let mut details: Vec<_> = internal_lints
588-
.map(|l| (false, &l.module, l.name.to_uppercase()))
589-
.chain(usable_lints.map(|l| (true, &l.module, l.name.to_uppercase())))
590-
.collect();
565+
fn gen_declared_lints<'a>(lints: impl Iterator<Item = &'a Lint>) -> String {
566+
let mut details: Vec<_> = lints.map(|l| (&l.module, l.name.to_uppercase())).collect();
591567
details.sort_unstable();
592568

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

596-
for (is_public, module_name, lint_name) in details {
597-
if !is_public {
598-
output.push_str(" #[cfg(feature = \"internal\")]\n");
599-
}
572+
for (module_name, lint_name) in details {
600573
let _: fmt::Result = writeln!(output, " crate::{module_name}::{lint_name}_INFO,");
601574
}
602575
output.push_str("];\n");
@@ -937,41 +910,6 @@ mod tests {
937910
assert_eq!(expected, result);
938911
}
939912

940-
#[test]
941-
fn test_usable_lints() {
942-
let lints = vec![
943-
Lint::new(
944-
"should_assert_eq2",
945-
"Not Deprecated",
946-
"\"abc\"",
947-
"module_name",
948-
Range::default(),
949-
),
950-
Lint::new(
951-
"should_assert_eq2",
952-
"internal",
953-
"\"abc\"",
954-
"module_name",
955-
Range::default(),
956-
),
957-
Lint::new(
958-
"should_assert_eq2",
959-
"internal_style",
960-
"\"abc\"",
961-
"module_name",
962-
Range::default(),
963-
),
964-
];
965-
let expected = vec![Lint::new(
966-
"should_assert_eq2",
967-
"Not Deprecated",
968-
"\"abc\"",
969-
"module_name",
970-
Range::default(),
971-
)];
972-
assert_eq!(expected, Lint::usable_lints(&lints));
973-
}
974-
975913
#[test]
976914
fn test_by_lint_group() {
977915
let lints = vec![

clippy_lints/Cargo.toml

-7
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,7 @@ itertools = "0.12"
1919
quine-mc_cluskey = "0.2"
2020
regex-syntax = "0.8"
2121
serde = { version = "1.0", features = ["derive"] }
22-
serde_json = { version = "1.0", optional = true }
23-
tempfile = { version = "3.3.0", optional = true }
2422
toml = "0.7.3"
25-
regex = { version = "1.5", optional = true }
2623
unicode-normalization = "0.1"
2724
unicode-script = { version = "0.5", default-features = false }
2825
semver = "1.0"
@@ -31,10 +28,6 @@ url = "2.2"
3128
[dev-dependencies]
3229
walkdir = "2.3"
3330

34-
[features]
35-
# build clippy with internal lints enabled, off by default
36-
internal = ["serde_json", "tempfile", "regex"]
37-
3831
[package.metadata.rust-analyzer]
3932
# This crate uses #[feature(rustc_private)]
4033
rustc_private = true

clippy_lints/src/declare_clippy_lint.rs

-13
Original file line numberDiff line numberDiff line change
@@ -165,17 +165,4 @@ macro_rules! declare_clippy_lint {
165165
$(, $eval_always)?
166166
}
167167
};
168-
169-
(
170-
$(#[doc = $lit:literal])*
171-
pub $lint_name:ident,
172-
internal,
173-
$desc:literal
174-
) => {
175-
declare_clippy_lint! {@
176-
$(#[doc = $lit])*
177-
pub $lint_name, Allow, crate::LintCategory::Internal, $desc,
178-
None, "0.0.0"
179-
}
180-
};
181168
}

clippy_lints/src/declared_lints.rs

-30
Original file line numberDiff line numberDiff line change
@@ -3,36 +3,6 @@
33
// Manual edits will be overwritten.
44

55
pub static LINTS: &[&crate::LintInfo] = &[
6-
#[cfg(feature = "internal")]
7-
crate::utils::internal_lints::almost_standard_lint_formulation::ALMOST_STANDARD_LINT_FORMULATION_INFO,
8-
#[cfg(feature = "internal")]
9-
crate::utils::internal_lints::collapsible_calls::COLLAPSIBLE_SPAN_LINT_CALLS_INFO,
10-
#[cfg(feature = "internal")]
11-
crate::utils::internal_lints::interning_defined_symbol::INTERNING_DEFINED_SYMBOL_INFO,
12-
#[cfg(feature = "internal")]
13-
crate::utils::internal_lints::interning_defined_symbol::UNNECESSARY_SYMBOL_STR_INFO,
14-
#[cfg(feature = "internal")]
15-
crate::utils::internal_lints::invalid_paths::INVALID_PATHS_INFO,
16-
#[cfg(feature = "internal")]
17-
crate::utils::internal_lints::lint_without_lint_pass::DEFAULT_LINT_INFO,
18-
#[cfg(feature = "internal")]
19-
crate::utils::internal_lints::lint_without_lint_pass::INVALID_CLIPPY_VERSION_ATTRIBUTE_INFO,
20-
#[cfg(feature = "internal")]
21-
crate::utils::internal_lints::lint_without_lint_pass::LINT_WITHOUT_LINT_PASS_INFO,
22-
#[cfg(feature = "internal")]
23-
crate::utils::internal_lints::lint_without_lint_pass::MISSING_CLIPPY_VERSION_ATTRIBUTE_INFO,
24-
#[cfg(feature = "internal")]
25-
crate::utils::internal_lints::msrv_attr_impl::MISSING_MSRV_ATTR_IMPL_INFO,
26-
#[cfg(feature = "internal")]
27-
crate::utils::internal_lints::outer_expn_data_pass::OUTER_EXPN_EXPN_DATA_INFO,
28-
#[cfg(feature = "internal")]
29-
crate::utils::internal_lints::produce_ice::PRODUCE_ICE_INFO,
30-
#[cfg(feature = "internal")]
31-
crate::utils::internal_lints::slow_symbol_comparisons::SLOW_SYMBOL_COMPARISONS_INFO,
32-
#[cfg(feature = "internal")]
33-
crate::utils::internal_lints::unnecessary_def_path::UNNECESSARY_DEF_PATH_INFO,
34-
#[cfg(feature = "internal")]
35-
crate::utils::internal_lints::unsorted_clippy_utils_paths::UNSORTED_CLIPPY_UTILS_PATHS_INFO,
366
crate::absolute_paths::ABSOLUTE_PATHS_INFO,
377
crate::almost_complete_range::ALMOST_COMPLETE_RANGE_INFO,
388
crate::approx_const::APPROX_CONSTANT_INFO,

0 commit comments

Comments
 (0)