Skip to content

Commit

Permalink
Replace the metadata collector with blessable tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexendoo committed Aug 5, 2024
1 parent e611c8e commit 27ef4ed
Show file tree
Hide file tree
Showing 16 changed files with 417 additions and 1,205 deletions.
6 changes: 3 additions & 3 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
[alias]
bless = "test --config env.RUSTC_BLESS='1'"
uitest = "test --test compile-test"
uibless = "test --test compile-test -- -- --bless"
bless = "test -- -- --bless"
uibless = "bless --test compile-test"
dev = "run --package clippy_dev --bin clippy_dev --manifest-path clippy_dev/Cargo.toml --"
lintcheck = "run --package lintcheck --bin lintcheck --manifest-path lintcheck/Cargo.toml -- "
collect-metadata = "test --test dogfood --features internal -- collect_metadata"
collect-metadata = "test --test compile-test --config env.COLLECT_METADATA='1'"

[build]
# -Zbinary-dep-depinfo allows us to track which rlib files to use for compiling UI tests
Expand Down
5 changes: 0 additions & 5 deletions .github/workflows/clippy_bors.yml
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,6 @@ jobs:
- name: Test metadata collection
run: cargo collect-metadata

- name: Test lint_configuration.md is up-to-date
run: |
echo "run \`cargo collect-metadata\` if this fails"
git update-index --refresh
integration_build:
needs: changelog
runs-on: ubuntu-latest
Expand Down
4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,11 @@ color-print = "0.3.4"
anstream = "0.6.0"

[dev-dependencies]
cargo_metadata = "0.18.1"
ui_test = "0.25"
regex = "1.5.5"
serde = { version = "1.0.145", features = ["derive"] }
serde_json = "1.0.122"
toml = "0.7.3"
walkdir = "2.3"
filetime = "0.2.9"
Expand All @@ -41,7 +44,6 @@ itertools = "0.12"
clippy_utils = { path = "clippy_utils" }
if_chain = "1.0"
quote = "1.0.25"
serde = { version = "1.0.145", features = ["derive"] }
syn = { version = "2.0", features = ["full"] }
futures = "0.3"
parking_lot = "0.12"
Expand Down
2 changes: 1 addition & 1 deletion book/src/development/adding_lints.md
Original file line number Diff line number Diff line change
Expand Up @@ -739,7 +739,7 @@ for some users. Adding a configuration is done in the following steps:

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

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

[`clippy_config::conf`]: https://github.com/rust-lang/rust-clippy/blob/master/clippy_config/src/conf.rs
[`clippy_lints` lib file]: https://github.com/rust-lang/rust-clippy/blob/master/clippy_lints/src/lib.rs
Expand Down
4 changes: 1 addition & 3 deletions book/src/lint_configuration.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!--
This file is generated by `cargo collect-metadata`.
This file is generated by `cargo bless --test config-metadata`.
Please use that command to update the file and do not edit it by hand.
-->

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


2 changes: 1 addition & 1 deletion clippy_dev/src/update_lints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,7 @@ fn gen_declared_lints<'a>(
details.sort_unstable();

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

for (is_public, module_name, lint_name) in details {
if !is_public {
Expand Down
4 changes: 1 addition & 3 deletions clippy_lints/src/declared_lints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use that command to update this file and do not edit by hand.
// Manual edits will be overwritten.

pub(crate) static LINTS: &[&crate::LintInfo] = &[
pub static LINTS: &[&crate::LintInfo] = &[
#[cfg(feature = "internal")]
crate::utils::internal_lints::almost_standard_lint_formulation::ALMOST_STANDARD_LINT_FORMULATION_INFO,
#[cfg(feature = "internal")]
Expand All @@ -24,8 +24,6 @@ pub(crate) static LINTS: &[&crate::LintInfo] = &[
#[cfg(feature = "internal")]
crate::utils::internal_lints::lint_without_lint_pass::MISSING_CLIPPY_VERSION_ATTRIBUTE_INFO,
#[cfg(feature = "internal")]
crate::utils::internal_lints::metadata_collector::METADATA_COLLECTOR_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,
Expand Down
38 changes: 24 additions & 14 deletions clippy_lints/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ pub mod deprecated_lints;
#[cfg_attr(feature = "internal", allow(clippy::missing_clippy_version_attribute))]
mod utils;

mod declared_lints;
mod renamed_lints;
pub mod declared_lints;
pub mod renamed_lints;

// begin lints modules, do not remove this comment, it’s used in `update_lints`
mod absolute_paths;
Expand Down Expand Up @@ -443,7 +443,7 @@ impl RegistrationGroups {
}
}

#[derive(Copy, Clone)]
#[derive(Copy, Clone, Debug)]
pub(crate) enum LintCategory {
Cargo,
Complexity,
Expand Down Expand Up @@ -482,11 +482,29 @@ impl LintCategory {
}
}

pub(crate) struct LintInfo {
pub struct LintInfo {
/// Double reference to maintain pointer equality
lint: &'static &'static Lint,
pub lint: &'static &'static Lint,
category: LintCategory,
explanation: &'static str,
pub explanation: &'static str,
/// e.g. `clippy_lints/src/absolute_paths.rs#43`
pub location: &'static str,
pub version: Option<&'static str>,
}

impl LintInfo {
/// Returns the lint name in lowercase without the `clippy::` prefix
#[allow(clippy::missing_panics_doc)]
pub fn name_lower(&self) -> String {
self.lint.name.strip_prefix("clippy::").unwrap().to_ascii_lowercase()
}

/// Returns the name of the lint's category in lowercase (`style`, `pedantic`)
pub fn category_lower(&self) -> String {
let mut category = format!("{:?}", self.category);
category.make_ascii_lowercase();
category
}
}

pub fn explain(name: &str) -> i32 {
Expand Down Expand Up @@ -537,14 +555,6 @@ pub fn register_lints(store: &mut rustc_lint::LintStore, conf: &'static Conf) {

include!("lib.deprecated.rs");

#[cfg(feature = "internal")]
{
if std::env::var("ENABLE_METADATA_COLLECTION").eq(&Ok("1".to_string())) {
store.register_late_pass(|_| Box::new(utils::internal_lints::metadata_collector::MetadataCollector::new()));
return;
}
}

let format_args_storage = FormatArgsStorage::default();
let format_args = format_args_storage.clone();
store.register_early_pass(move || {
Expand Down
1 change: 0 additions & 1 deletion clippy_lints/src/utils/internal_lints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ pub mod collapsible_calls;
pub mod interning_defined_symbol;
pub mod invalid_paths;
pub mod lint_without_lint_pass;
pub mod metadata_collector;
pub mod msrv_attr_impl;
pub mod outer_expn_data_pass;
pub mod produce_ice;
Expand Down
13 changes: 12 additions & 1 deletion clippy_lints/src/utils/internal_lints/lint_without_lint_pass.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use crate::utils::internal_lints::metadata_collector::is_deprecated_lint;
use clippy_utils::diagnostics::{span_lint, span_lint_and_help};
use clippy_utils::macros::root_macro_call_first_node;
use clippy_utils::{is_lint_allowed, match_def_path, paths};
Expand Down Expand Up @@ -322,6 +321,18 @@ pub(super) fn extract_clippy_version_value(cx: &LateContext<'_>, item: &'_ Item<
})
}

const DEPRECATED_LINT_TYPE: [&str; 3] = ["clippy_lints", "deprecated_lints", "ClippyDeprecatedLint"];

fn is_deprecated_lint(cx: &LateContext<'_>, ty: &hir::Ty<'_>) -> bool {
if let TyKind::Path(ref path) = ty.kind {
if let Res::Def(DefKind::Struct, def_id) = cx.qpath_res(path, ty.hir_id) {
return match_def_path(cx, def_id, &DEPRECATED_LINT_TYPE);
}
}

false
}

struct LintCollector<'a, 'tcx> {
output: &'a mut FxHashSet<Symbol>,
cx: &'a LateContext<'tcx>,
Expand Down
Loading

0 comments on commit 27ef4ed

Please sign in to comment.