From e2ce4f9462c1d65b4dce084186c0e532c27fe5a3 Mon Sep 17 00:00:00 2001 From: Cameron Steffen Date: Sun, 9 Jan 2022 18:22:38 -0600 Subject: [PATCH] Combine internal features in clippy_lints --- .cargo/config.toml | 2 +- .github/workflows/clippy.yml | 6 ++-- .github/workflows/clippy_bors.yml | 6 ++-- Cargo.toml | 3 +- clippy_dev/src/update_lints.rs | 2 +- clippy_lints/Cargo.toml | 3 +- clippy_lints/src/lib.register_lints.rs | 28 +++++++++---------- clippy_lints/src/lib.rs | 13 ++++----- clippy_lints/src/utils/conf.rs | 2 +- clippy_lints/src/utils/internal_lints.rs | 2 +- .../internal_lints/metadata_collector.rs | 3 +- clippy_lints/src/utils/mod.rs | 2 +- tests/compile-test.rs | 2 +- tests/dogfood.rs | 10 +++---- 14 files changed, 39 insertions(+), 45 deletions(-) diff --git a/.cargo/config.toml b/.cargo/config.toml index c9ae0a961b644..f3dd9275a42be 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -2,7 +2,7 @@ uitest = "test --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 metadata-collector-lint -- run_metadata_collection_lint --ignored" +collect-metadata = "test --test dogfood --features internal -- run_metadata_collection_lint --ignored" [build] # -Zbinary-dep-depinfo allows us to track which rlib files to use for compiling UI tests diff --git a/.github/workflows/clippy.yml b/.github/workflows/clippy.yml index a14e530df4ec5..8b5e814b1772e 100644 --- a/.github/workflows/clippy.yml +++ b/.github/workflows/clippy.yml @@ -49,13 +49,13 @@ jobs: echo "LD_LIBRARY_PATH=${SYSROOT}/lib${LD_LIBRARY_PATH+:${LD_LIBRARY_PATH}}" >> $GITHUB_ENV - name: Build - run: cargo build --features deny-warnings,internal-lints,metadata-collector-lint + run: cargo build --features deny-warnings,internal - name: Test - run: cargo test --features deny-warnings,internal-lints,metadata-collector-lint + run: cargo test --features deny-warnings,internal - name: Test clippy_lints - run: cargo test --features deny-warnings,internal-lints,metadata-collector-lint + run: cargo test --features deny-warnings,internal working-directory: clippy_lints - name: Test clippy_utils diff --git a/.github/workflows/clippy_bors.yml b/.github/workflows/clippy_bors.yml index 06522606347d8..eb045ec30dc31 100644 --- a/.github/workflows/clippy_bors.yml +++ b/.github/workflows/clippy_bors.yml @@ -112,13 +112,13 @@ jobs: echo "$SYSROOT/bin" >> $GITHUB_PATH - name: Build - run: cargo build --features deny-warnings,internal-lints,metadata-collector-lint + run: cargo build --features deny-warnings,internal - name: Test - run: cargo test --features deny-warnings,internal-lints,metadata-collector-lint + run: cargo test --features deny-warnings,internal - name: Test clippy_lints - run: cargo test --features deny-warnings,internal-lints,metadata-collector-lint + run: cargo test --features deny-warnings,internal working-directory: clippy_lints - name: Test clippy_utils diff --git a/Cargo.toml b/Cargo.toml index 79a7ec92071c0..cb49dd84c39a9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -57,8 +57,7 @@ rustc_tools_util = { version = "0.2", path = "rustc_tools_util" } [features] deny-warnings = ["clippy_lints/deny-warnings"] integration = ["tempfile"] -internal-lints = ["clippy_lints/internal-lints"] -metadata-collector-lint = ["internal-lints", "clippy_lints/metadata-collector-lint"] +internal = ["clippy_lints/internal"] [package.metadata.rust-analyzer] # This package uses #[feature(rustc_private)] diff --git a/clippy_dev/src/update_lints.rs b/clippy_dev/src/update_lints.rs index 8dd073ef405a1..d368ef1f46a2a 100644 --- a/clippy_dev/src/update_lints.rs +++ b/clippy_dev/src/update_lints.rs @@ -321,7 +321,7 @@ fn gen_register_lint_list<'a>( for (is_public, module_name, lint_name) in details { if !is_public { - output.push_str(" #[cfg(feature = \"internal-lints\")]\n"); + output.push_str(" #[cfg(feature = \"internal\")]\n"); } output.push_str(&format!(" {}::{},\n", module_name, lint_name)); } diff --git a/clippy_lints/Cargo.toml b/clippy_lints/Cargo.toml index 639138ac9c52d..e9f87b60ece43 100644 --- a/clippy_lints/Cargo.toml +++ b/clippy_lints/Cargo.toml @@ -30,8 +30,7 @@ url = { version = "2.2", features = ["serde"] } [features] deny-warnings = ["clippy_utils/deny-warnings"] # build clippy with internal lints enabled, off by default -internal-lints = ["clippy_utils/internal"] -metadata-collector-lint = ["serde_json", "clippy_utils/internal"] +internal = ["clippy_utils/internal", "serde_json"] [package.metadata.rust-analyzer] # This crate uses #[feature(rustc_private)] diff --git a/clippy_lints/src/lib.register_lints.rs b/clippy_lints/src/lib.register_lints.rs index f9241d943b2cd..832178c2db5e5 100644 --- a/clippy_lints/src/lib.register_lints.rs +++ b/clippy_lints/src/lib.register_lints.rs @@ -3,33 +3,33 @@ // Manual edits will be overwritten. store.register_lints(&[ - #[cfg(feature = "internal-lints")] + #[cfg(feature = "internal")] utils::internal_lints::CLIPPY_LINTS_INTERNAL, - #[cfg(feature = "internal-lints")] + #[cfg(feature = "internal")] utils::internal_lints::COLLAPSIBLE_SPAN_LINT_CALLS, - #[cfg(feature = "internal-lints")] + #[cfg(feature = "internal")] utils::internal_lints::COMPILER_LINT_FUNCTIONS, - #[cfg(feature = "internal-lints")] + #[cfg(feature = "internal")] utils::internal_lints::DEFAULT_LINT, - #[cfg(feature = "internal-lints")] + #[cfg(feature = "internal")] utils::internal_lints::IF_CHAIN_STYLE, - #[cfg(feature = "internal-lints")] + #[cfg(feature = "internal")] utils::internal_lints::INTERNING_DEFINED_SYMBOL, - #[cfg(feature = "internal-lints")] + #[cfg(feature = "internal")] utils::internal_lints::INVALID_CLIPPY_VERSION_ATTRIBUTE, - #[cfg(feature = "internal-lints")] + #[cfg(feature = "internal")] utils::internal_lints::INVALID_PATHS, - #[cfg(feature = "internal-lints")] + #[cfg(feature = "internal")] utils::internal_lints::LINT_WITHOUT_LINT_PASS, - #[cfg(feature = "internal-lints")] + #[cfg(feature = "internal")] utils::internal_lints::MATCH_TYPE_ON_DIAGNOSTIC_ITEM, - #[cfg(feature = "internal-lints")] + #[cfg(feature = "internal")] utils::internal_lints::MISSING_CLIPPY_VERSION_ATTRIBUTE, - #[cfg(feature = "internal-lints")] + #[cfg(feature = "internal")] utils::internal_lints::OUTER_EXPN_EXPN_DATA, - #[cfg(feature = "internal-lints")] + #[cfg(feature = "internal")] utils::internal_lints::PRODUCE_ICE, - #[cfg(feature = "internal-lints")] + #[cfg(feature = "internal")] utils::internal_lints::UNNECESSARY_SYMBOL_STR, absurd_extreme_comparisons::ABSURD_EXTREME_COMPARISONS, approx_const::APPROX_CONSTANT, diff --git a/clippy_lints/src/lib.rs b/clippy_lints/src/lib.rs index c31acb5f4ef84..0d765c2bcde1b 100644 --- a/clippy_lints/src/lib.rs +++ b/clippy_lints/src/lib.rs @@ -153,12 +153,9 @@ macro_rules! declare_clippy_lint { }; } -#[cfg(feature = "metadata-collector-lint")] +#[cfg(feature = "internal")] mod deprecated_lints; -#[cfg_attr( - any(feature = "internal-lints", feature = "metadata-collector-lint"), - allow(clippy::missing_clippy_version_attribute) -)] +#[cfg_attr(feature = "internal", allow(clippy::missing_clippy_version_attribute))] mod utils; // begin lints modules, do not remove this comment, it’s used in `update_lints` @@ -472,7 +469,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf: include!("lib.register_restriction.rs"); include!("lib.register_pedantic.rs"); - #[cfg(feature = "internal-lints")] + #[cfg(feature = "internal")] include!("lib.register_internal.rs"); include!("lib.register_all.rs"); @@ -484,7 +481,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf: include!("lib.register_cargo.rs"); include!("lib.register_nursery.rs"); - #[cfg(feature = "metadata-collector-lint")] + #[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())); @@ -493,7 +490,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf: } // all the internal lints - #[cfg(feature = "internal-lints")] + #[cfg(feature = "internal")] { store.register_early_pass(|| Box::new(utils::internal_lints::ClippyLintsInternal)); store.register_early_pass(|| Box::new(utils::internal_lints::ProduceIce)); diff --git a/clippy_lints/src/utils/conf.rs b/clippy_lints/src/utils/conf.rs index 9c83d30eb9cc1..4e1c538c1c20a 100644 --- a/clippy_lints/src/utils/conf.rs +++ b/clippy_lints/src/utils/conf.rs @@ -113,7 +113,7 @@ macro_rules! define_Conf { } } - #[cfg(feature = "metadata-collector-lint")] + #[cfg(feature = "internal")] pub mod metadata { use crate::utils::internal_lints::metadata_collector::ClippyConfiguration; diff --git a/clippy_lints/src/utils/internal_lints.rs b/clippy_lints/src/utils/internal_lints.rs index 165004e5b413b..67faca70d5cd6 100644 --- a/clippy_lints/src/utils/internal_lints.rs +++ b/clippy_lints/src/utils/internal_lints.rs @@ -35,7 +35,7 @@ use rustc_typeck::hir_ty_to_ty; use std::borrow::{Borrow, Cow}; -#[cfg(feature = "metadata-collector-lint")] +#[cfg(feature = "internal")] pub mod metadata_collector; declare_clippy_lint! { diff --git a/clippy_lints/src/utils/internal_lints/metadata_collector.rs b/clippy_lints/src/utils/internal_lints/metadata_collector.rs index 7707eebd6223e..02f5d45cc18f4 100644 --- a/clippy_lints/src/utils/internal_lints/metadata_collector.rs +++ b/clippy_lints/src/utils/internal_lints/metadata_collector.rs @@ -1,8 +1,7 @@ //! This lint is used to collect metadata about clippy lints. This metadata is exported as a json //! file and then used to generate the [clippy lint list](https://rust-lang.github.io/rust-clippy/master/index.html) //! -//! This module and therefor the entire lint is guarded by a feature flag called -//! `metadata-collector-lint` +//! This module and therefore the entire lint is guarded by a feature flag called `internal` //! //! The module transforms all lint names to ascii lowercase to ensure that we don't have mismatches //! during any comparison or mapping. (Please take care of this, it's not fun to spend time on such diff --git a/clippy_lints/src/utils/mod.rs b/clippy_lints/src/utils/mod.rs index b67448e3a5740..dc385ebacba66 100644 --- a/clippy_lints/src/utils/mod.rs +++ b/clippy_lints/src/utils/mod.rs @@ -1,5 +1,5 @@ pub mod author; pub mod conf; pub mod inspector; -#[cfg(any(feature = "internal-lints", feature = "metadata-collector-lint"))] +#[cfg(feature = "internal")] pub mod internal_lints; diff --git a/tests/compile-test.rs b/tests/compile-test.rs index d602d2042ee7f..762b67fc5854d 100644 --- a/tests/compile-test.rs +++ b/tests/compile-test.rs @@ -15,7 +15,7 @@ use std::path::{Path, PathBuf}; mod cargo; // whether to run internal tests or not -const RUN_INTERNAL_TESTS: bool = cfg!(feature = "internal-lints"); +const RUN_INTERNAL_TESTS: bool = cfg!(feature = "internal"); /// All crates used in UI tests are listed here static TEST_DEPENDENCIES: &[&str] = &[ diff --git a/tests/dogfood.rs b/tests/dogfood.rs index a37cdfed126f6..6f7de9c67a9b7 100644 --- a/tests/dogfood.rs +++ b/tests/dogfood.rs @@ -42,8 +42,8 @@ fn dogfood_clippy() { .args(&["-D", "clippy::pedantic"]) .arg("-Cdebuginfo=0"); // disable debuginfo to generate less data in the target dir - // internal lints only exist if we build with the internal-lints feature - if cfg!(feature = "internal-lints") { + // internal lints only exist if we build with the internal feature + if cfg!(feature = "internal") { command.args(&["-D", "clippy::internal"]); } @@ -180,7 +180,7 @@ fn dogfood_subprojects() { #[test] #[ignore] -#[cfg(feature = "metadata-collector-lint")] +#[cfg(feature = "internal")] fn run_metadata_collection_lint() { use std::fs::File; use std::time::SystemTime; @@ -233,8 +233,8 @@ fn run_clippy_for_project(project: &str) { .args(&["-D", "clippy::pedantic"]) .arg("-Cdebuginfo=0"); // disable debuginfo to generate less data in the target dir - // internal lints only exist if we build with the internal-lints feature - if cfg!(feature = "internal-lints") { + // internal lints only exist if we build with the internal feature + if cfg!(feature = "internal") { command.args(&["-D", "clippy::internal"]); }