Skip to content

Commit

Permalink
Combine internal features in clippy_lints
Browse files Browse the repository at this point in the history
  • Loading branch information
camsteffen committed Jan 10, 2022
1 parent 16d8488 commit e2ce4f9
Show file tree
Hide file tree
Showing 14 changed files with 39 additions and 45 deletions.
2 changes: 1 addition & 1 deletion .cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/clippy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/clippy_bors.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
2 changes: 1 addition & 1 deletion clippy_dev/src/update_lints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down
3 changes: 1 addition & 2 deletions clippy_lints/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
28 changes: 14 additions & 14 deletions clippy_lints/src/lib.register_lints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
13 changes: 5 additions & 8 deletions clippy_lints/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down Expand Up @@ -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");
Expand All @@ -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()));
Expand All @@ -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));
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/utils/conf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/utils/internal_lints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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! {
Expand Down
3 changes: 1 addition & 2 deletions clippy_lints/src/utils/internal_lints/metadata_collector.rs
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/utils/mod.rs
Original file line number Diff line number Diff line change
@@ -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;
2 changes: 1 addition & 1 deletion tests/compile-test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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] = &[
Expand Down
10 changes: 5 additions & 5 deletions tests/dogfood.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"]);
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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"]);
}

Expand Down

0 comments on commit e2ce4f9

Please sign in to comment.