Skip to content

Commit 182cd5f

Browse files
committed
Replace the metadata collector with tests
1 parent 8827107 commit 182cd5f

File tree

15 files changed

+448
-1206
lines changed

15 files changed

+448
-1206
lines changed

.cargo/config.toml

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
[alias]
2+
bless = "test --config env.RUSTC_BLESS='1'"
23
uitest = "test --test compile-test"
3-
uibless = "test --test compile-test -- -- --bless"
4-
bless = "test -- -- --bless"
4+
uibless = "bless --test compile-test"
55
dev = "run --package clippy_dev --bin clippy_dev --manifest-path clippy_dev/Cargo.toml --"
66
lintcheck = "run --package lintcheck --bin lintcheck --manifest-path lintcheck/Cargo.toml -- "
7-
collect-metadata = "test --test dogfood --features internal -- collect_metadata"
7+
collect-metadata = "test --test compile-test --config env.COLLECT_METADATA='1'"
88

99
[build]
1010
# -Zbinary-dep-depinfo allows us to track which rlib files to use for compiling UI tests

.github/workflows/clippy_bors.yml

-5
Original file line numberDiff line numberDiff line change
@@ -136,11 +136,6 @@ jobs:
136136
- name: Test metadata collection
137137
run: cargo collect-metadata
138138

139-
- name: Test lint_configuration.md is up-to-date
140-
run: |
141-
echo "run \`cargo collect-metadata\` if this fails"
142-
git update-index --refresh
143-
144139
integration_build:
145140
needs: changelog
146141
runs-on: ubuntu-latest

Cargo.toml

+3-1
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,11 @@ color-print = "0.3.4"
3030
anstream = "0.6.0"
3131

3232
[dev-dependencies]
33+
cargo_metadata = "0.18.1"
3334
ui_test = "0.25"
3435
regex = "1.5.5"
36+
serde = { version = "1.0.145", features = ["derive"] }
37+
serde_json = "1.0.122"
3538
toml = "0.7.3"
3639
walkdir = "2.3"
3740
filetime = "0.2.9"
@@ -41,7 +44,6 @@ itertools = "0.12"
4144
clippy_utils = { path = "clippy_utils" }
4245
if_chain = "1.0"
4346
quote = "1.0.25"
44-
serde = { version = "1.0.145", features = ["derive"] }
4547
syn = { version = "2.0", features = ["full"] }
4648
futures = "0.3"
4749
parking_lot = "0.12"

book/src/development/adding_lints.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -739,7 +739,7 @@ for some users. Adding a configuration is done in the following steps:
739739

740740
5. Update [Lint Configuration](../lint_configuration.md)
741741

742-
Run `cargo collect-metadata` to generate documentation changes for the book.
742+
Run `cargo bless --test config-metadata` to generate documentation changes for the book.
743743

744744
[`clippy_config::conf`]: https://github.com/rust-lang/rust-clippy/blob/master/clippy_config/src/conf.rs
745745
[`clippy_lints` lib file]: https://github.com/rust-lang/rust-clippy/blob/master/clippy_lints/src/lib.rs

book/src/lint_configuration.md

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
This file is generated by `cargo collect-metadata`.
2+
This file is generated by `cargo bless --test config-metadata`.
33
Please use that command to update the file and do not edit it by hand.
44
-->
55

@@ -949,5 +949,3 @@ Whether to also emit warnings for unsafe blocks with metavariable expansions in
949949
---
950950
**Affected lints:**
951951
* [`macro_metavars_in_unsafe`](https://rust-lang.github.io/rust-clippy/master/index.html#macro_metavars_in_unsafe)
952-
953-

clippy_dev/src/update_lints.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -604,7 +604,7 @@ fn gen_declared_lints<'a>(
604604
details.sort_unstable();
605605

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

609609
for (is_public, module_name, lint_name) in details {
610610
if !is_public {

clippy_lints/src/declared_lints.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Use that command to update this file and do not edit by hand.
33
// Manual edits will be overwritten.
44

5-
pub(crate) static LINTS: &[&crate::LintInfo] = &[
5+
pub static LINTS: &[&crate::LintInfo] = &[
66
#[cfg(feature = "internal")]
77
crate::utils::internal_lints::almost_standard_lint_formulation::ALMOST_STANDARD_LINT_FORMULATION_INFO,
88
#[cfg(feature = "internal")]
@@ -22,8 +22,6 @@ pub(crate) static LINTS: &[&crate::LintInfo] = &[
2222
#[cfg(feature = "internal")]
2323
crate::utils::internal_lints::lint_without_lint_pass::MISSING_CLIPPY_VERSION_ATTRIBUTE_INFO,
2424
#[cfg(feature = "internal")]
25-
crate::utils::internal_lints::metadata_collector::METADATA_COLLECTOR_INFO,
26-
#[cfg(feature = "internal")]
2725
crate::utils::internal_lints::msrv_attr_impl::MISSING_MSRV_ATTR_IMPL_INFO,
2826
#[cfg(feature = "internal")]
2927
crate::utils::internal_lints::outer_expn_data_pass::OUTER_EXPN_EXPN_DATA_INFO,

clippy_lints/src/lib.rs

+34-14
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ extern crate declare_clippy_lint;
6666
#[cfg_attr(feature = "internal", allow(clippy::missing_clippy_version_attribute))]
6767
mod utils;
6868

69-
mod declared_lints;
70-
mod deprecated_lints;
69+
pub mod declared_lints;
70+
pub mod deprecated_lints;
7171

7272
// begin lints modules, do not remove this comment, it’s used in `update_lints`
7373
mod absolute_paths;
@@ -440,7 +440,7 @@ impl RegistrationGroups {
440440
}
441441
}
442442

443-
#[derive(Copy, Clone)]
443+
#[derive(Copy, Clone, Debug)]
444444
pub(crate) enum LintCategory {
445445
Cargo,
446446
Complexity,
@@ -479,11 +479,39 @@ impl LintCategory {
479479
}
480480
}
481481

482-
pub(crate) struct LintInfo {
482+
pub struct LintInfo {
483483
/// Double reference to maintain pointer equality
484-
lint: &'static &'static Lint,
484+
pub lint: &'static &'static Lint,
485485
category: LintCategory,
486-
explanation: &'static str,
486+
pub explanation: &'static str,
487+
/// e.g. `clippy_lints/src/absolute_paths.rs#43`
488+
pub location: &'static str,
489+
pub version: Option<&'static str>,
490+
}
491+
492+
impl LintInfo {
493+
/// Returns the lint name in lowercase without the `clippy::` prefix
494+
#[allow(clippy::missing_panics_doc)]
495+
pub fn name_lower(&self) -> String {
496+
self.lint.name.strip_prefix("clippy::").unwrap().to_ascii_lowercase()
497+
}
498+
499+
/// Returns the name of the lint's category in lowercase (`style`, `pedantic`)
500+
pub fn category_str(&self) -> &'static str {
501+
match self.category {
502+
Cargo => "cargo",
503+
Complexity => "complexity",
504+
Correctness => "correctness",
505+
Nursery => "nursery",
506+
Pedantic => "pedantic",
507+
Perf => "perf",
508+
Restriction => "restriction",
509+
Style => "style",
510+
Suspicious => "suspicious",
511+
#[cfg(feature = "internal")]
512+
Internal => "internal",
513+
}
514+
}
487515
}
488516

489517
pub fn explain(name: &str) -> i32 {
@@ -538,14 +566,6 @@ pub fn register_lints(store: &mut rustc_lint::LintStore, conf: &'static Conf) {
538566
store.register_removed(name, reason);
539567
}
540568

541-
#[cfg(feature = "internal")]
542-
{
543-
if std::env::var("ENABLE_METADATA_COLLECTION").eq(&Ok("1".to_string())) {
544-
store.register_late_pass(|_| Box::new(utils::internal_lints::metadata_collector::MetadataCollector::new()));
545-
return;
546-
}
547-
}
548-
549569
let format_args_storage = FormatArgsStorage::default();
550570
let format_args = format_args_storage.clone();
551571
store.register_early_pass(move || {

clippy_lints/src/utils/internal_lints.rs

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ pub mod collapsible_calls;
33
pub mod interning_defined_symbol;
44
pub mod invalid_paths;
55
pub mod lint_without_lint_pass;
6-
pub mod metadata_collector;
76
pub mod msrv_attr_impl;
87
pub mod outer_expn_data_pass;
98
pub mod produce_ice;

0 commit comments

Comments
 (0)