Skip to content

Commit ad4b186

Browse files
committed
Replace the metadata collector with tests
1 parent e17d254 commit ad4b186

File tree

16 files changed

+456
-1205
lines changed

16 files changed

+456
-1205
lines changed

.cargo/config.toml

Lines changed: 3 additions & 3 deletions
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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -135,11 +135,6 @@ jobs:
135135
- name: Test metadata collection
136136
run: cargo collect-metadata
137137

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

Cargo.toml

Lines changed: 3 additions & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 3 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 3 deletions
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

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ extern crate declare_clippy_lint;
6868
#[cfg_attr(feature = "internal", allow(clippy::missing_clippy_version_attribute))]
6969
mod utils;
7070

71-
mod declared_lints;
72-
mod deprecated_lints;
71+
pub mod declared_lints;
72+
pub mod deprecated_lints;
7373

7474
// begin lints modules, do not remove this comment, it’s used in `update_lints`
7575
mod absolute_paths;
@@ -441,7 +441,7 @@ impl RegistrationGroups {
441441
}
442442
}
443443

444-
#[derive(Copy, Clone)]
444+
#[derive(Copy, Clone, Debug)]
445445
pub(crate) enum LintCategory {
446446
Cargo,
447447
Complexity,
@@ -480,11 +480,39 @@ impl LintCategory {
480480
}
481481
}
482482

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

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

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

clippy_lints/src/utils/internal_lints.rs

Lines changed: 0 additions & 1 deletion
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;

clippy_lints/src/utils/internal_lints/lint_without_lint_pass.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,18 @@ pub(super) fn extract_clippy_version_value(cx: &LateContext<'_>, item: &'_ Item<
261261
})
262262
}
263263

264+
const DEPRECATED_LINT_TYPE: [&str; 3] = ["clippy_lints", "deprecated_lints", "ClippyDeprecatedLint"];
265+
266+
fn is_deprecated_lint(cx: &LateContext<'_>, ty: &hir::Ty<'_>) -> bool {
267+
if let TyKind::Path(ref path) = ty.kind {
268+
if let Res::Def(DefKind::Struct, def_id) = cx.qpath_res(path, ty.hir_id) {
269+
return match_def_path(cx, def_id, &DEPRECATED_LINT_TYPE);
270+
}
271+
}
272+
273+
false
274+
}
275+
264276
struct LintCollector<'a, 'tcx> {
265277
output: &'a mut FxHashSet<Symbol>,
266278
cx: &'a LateContext<'tcx>,

0 commit comments

Comments
 (0)