Skip to content

Commit 2838b04

Browse files
committed
add internal-lints feature to enable clippys internal lints (off by default)
1 parent 68cf94f commit 2838b04

25 files changed

+84
-26
lines changed

.github/workflows/clippy_bors.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,10 @@ jobs:
132132
run: cargo build --features deny-warnings
133133

134134
- name: Test
135-
run: cargo test --features deny-warnings
135+
run: cargo test --features deny-warnings --features internal-lints
136136

137137
- name: Test clippy_lints
138-
run: cargo test --features deny-warnings
138+
run: cargo test --features deny-warnings --features internal-lints
139139
working-directory: clippy_lints
140140

141141
- name: Test rustc_tools_util

Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ path = "src/driver.rs"
3232
clippy_lints = { version = "0.0.212", path = "clippy_lints" }
3333
# end automatic update
3434
semver = "0.11"
35-
rustc_tools_util = { version = "0.2.0", path = "rustc_tools_util"}
35+
rustc_tools_util = { version = "0.2.0", path = "rustc_tools_util" }
3636
tempfile = { version = "3.1.0", optional = true }
3737

3838
[dev-dependencies]
@@ -49,8 +49,9 @@ derive-new = "0.5"
4949
rustc-workspace-hack = "1.0.0"
5050

5151
[build-dependencies]
52-
rustc_tools_util = { version = "0.2.0", path = "rustc_tools_util"}
52+
rustc_tools_util = { version = "0.2.0", path = "rustc_tools_util" }
5353

5454
[features]
5555
deny-warnings = []
5656
integration = ["tempfile"]
57+
internal-lints = ["clippy_lints/internal-lints"]

clippy_lints/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,5 @@ syn = { version = "1", features = ["full"] }
3636

3737
[features]
3838
deny-warnings = []
39+
# build clippy with internal lints enabled, off by default
40+
internal-lints = []

clippy_lints/src/lib.rs

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -904,14 +904,23 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
904904
&unwrap_in_result::UNWRAP_IN_RESULT,
905905
&use_self::USE_SELF,
906906
&useless_conversion::USELESS_CONVERSION,
907+
#[cfg(feature = "internal-lints")]
907908
&utils::internal_lints::CLIPPY_LINTS_INTERNAL,
909+
#[cfg(feature = "internal-lints")]
908910
&utils::internal_lints::COLLAPSIBLE_SPAN_LINT_CALLS,
911+
#[cfg(feature = "internal-lints")]
909912
&utils::internal_lints::COMPILER_LINT_FUNCTIONS,
913+
#[cfg(feature = "internal-lints")]
910914
&utils::internal_lints::DEFAULT_LINT,
915+
#[cfg(feature = "internal-lints")]
911916
&utils::internal_lints::INVALID_PATHS,
917+
#[cfg(feature = "internal-lints")]
912918
&utils::internal_lints::LINT_WITHOUT_LINT_PASS,
919+
#[cfg(feature = "internal-lints")]
913920
&utils::internal_lints::MATCH_TYPE_ON_DIAGNOSTIC_ITEM,
921+
#[cfg(feature = "internal-lints")]
914922
&utils::internal_lints::OUTER_EXPN_EXPN_DATA,
923+
#[cfg(feature = "internal-lints")]
915924
&utils::internal_lints::PRODUCE_ICE,
916925
&vec::USELESS_VEC,
917926
&vec_resize_to_zero::VEC_RESIZE_TO_ZERO,
@@ -932,11 +941,14 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
932941
// end register lints, do not remove this comment, it’s used in `update_lints`
933942
store.register_late_pass(|| box await_holding_invalid::AwaitHolding);
934943
store.register_late_pass(|| box serde_api::SerdeAPI);
935-
store.register_late_pass(|| box utils::internal_lints::CompilerLintFunctions::new());
936-
store.register_late_pass(|| box utils::internal_lints::LintWithoutLintPass::default());
937-
store.register_late_pass(|| box utils::internal_lints::OuterExpnDataPass);
938-
store.register_late_pass(|| box utils::internal_lints::InvalidPaths);
939-
store.register_late_pass(|| box utils::inspector::DeepCodeInspector);
944+
#[cfg(feature = "internal-lints")]
945+
{
946+
store.register_late_pass(|| box utils::internal_lints::CompilerLintFunctions::new());
947+
store.register_late_pass(|| box utils::internal_lints::LintWithoutLintPass::default());
948+
store.register_late_pass(|| box utils::internal_lints::OuterExpnDataPass);
949+
store.register_late_pass(|| box utils::internal_lints::InvalidPaths);
950+
store.register_late_pass(|| box utils::inspector::DeepCodeInspector);
951+
}
940952
store.register_late_pass(|| box utils::author::Author);
941953
let vec_box_size_threshold = conf.vec_box_size_threshold;
942954
store.register_late_pass(move || box types::Types::new(vec_box_size_threshold));
@@ -1122,6 +1134,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
11221134
store.register_early_pass(|| box literal_representation::LiteralDigitGrouping);
11231135
let literal_representation_threshold = conf.literal_representation_threshold;
11241136
store.register_early_pass(move || box literal_representation::DecimalLiteralRepresentation::new(literal_representation_threshold));
1137+
#[cfg(feature = "internal-lints")]
11251138
store.register_early_pass(|| box utils::internal_lints::ClippyLintsInternal);
11261139
let enum_variant_name_threshold = conf.enum_variant_name_threshold;
11271140
store.register_early_pass(move || box enum_variants::EnumVariantNames::new(enum_variant_name_threshold));
@@ -1136,6 +1149,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
11361149
store.register_late_pass(move || box large_const_arrays::LargeConstArrays::new(array_size_threshold));
11371150
store.register_late_pass(|| box floating_point_arithmetic::FloatingPointArithmetic);
11381151
store.register_early_pass(|| box as_conversions::AsConversions);
1152+
#[cfg(feature = "internal-lints")]
11391153
store.register_early_pass(|| box utils::internal_lints::ProduceIce);
11401154
store.register_late_pass(|| box let_underscore::LetUnderscore);
11411155
store.register_late_pass(|| box atomic_ordering::AtomicOrdering);
@@ -1152,6 +1166,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
11521166
store.register_late_pass(|| box dereference::Dereferencing);
11531167
store.register_late_pass(|| box option_if_let_else::OptionIfLetElse);
11541168
store.register_late_pass(|| box future_not_send::FutureNotSend);
1169+
#[cfg(feature = "internal-lints")]
11551170
store.register_late_pass(|| box utils::internal_lints::CollapsibleCalls);
11561171
store.register_late_pass(|| box if_let_mutex::IfLetMutex);
11571172
store.register_late_pass(|| box mut_mutex_lock::MutMutexLock);
@@ -1177,6 +1192,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
11771192
store.register_late_pass(|| box manual_ok_or::ManualOkOr);
11781193
store.register_late_pass(|| box float_equality_without_abs::FloatEqualityWithoutAbs);
11791194
store.register_late_pass(|| box async_yields_async::AsyncYieldsAsync);
1195+
#[cfg(feature = "internal-lints")]
11801196
store.register_late_pass(|| box utils::internal_lints::MatchTypeOnDiagItem);
11811197
let disallowed_methods = conf.disallowed_methods.iter().cloned().collect::<FxHashSet<_>>();
11821198
store.register_late_pass(move || box disallowed_method::DisallowedMethod::new(&disallowed_methods));
@@ -1317,7 +1333,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
13171333
LintId::of(&wildcard_imports::ENUM_GLOB_USE),
13181334
LintId::of(&wildcard_imports::WILDCARD_IMPORTS),
13191335
]);
1320-
1336+
#[cfg(feature = "internal-lints")]
13211337
store.register_group(true, "clippy::internal", Some("clippy_internal"), vec![
13221338
LintId::of(&utils::internal_lints::CLIPPY_LINTS_INTERNAL),
13231339
LintId::of(&utils::internal_lints::COLLAPSIBLE_SPAN_LINT_CALLS),

clippy_lints/src/utils/diagnostics.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,9 @@ pub fn span_lint_hir_and_then(
186186
/// |
187187
/// = note: `-D fold-any` implied by `-D warnings`
188188
/// ```
189-
#[allow(clippy::collapsible_span_lint_calls)]
189+
190+
#[allow(clippy::unknown_clippy_lints)]
191+
#[cfg_attr(feature = "internal-lints", allow(clippy::collapsible_span_lint_calls))]
190192
pub fn span_lint_and_sugg<'a, T: LintContext>(
191193
cx: &'a T,
192194
lint: &'static Lint,

clippy_lints/src/utils/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ pub mod eager_or_lazy;
1414
pub mod higher;
1515
mod hir_utils;
1616
pub mod inspector;
17+
#[cfg(feature = "internal-lints")]
1718
pub mod internal_lints;
1819
pub mod numeric_literal;
1920
pub mod paths;

clippy_lints/src/utils/paths.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ pub const DISPLAY_TRAIT: [&str; 3] = ["core", "fmt", "Display"];
3131
pub const DOUBLE_ENDED_ITERATOR: [&str; 4] = ["core", "iter", "traits", "DoubleEndedIterator"];
3232
pub const DROP: [&str; 3] = ["core", "mem", "drop"];
3333
pub const DURATION: [&str; 3] = ["core", "time", "Duration"];
34+
#[cfg(feature = "internal-lints")]
3435
pub const EARLY_CONTEXT: [&str; 2] = ["rustc_lint", "EarlyContext"];
3536
pub const EXIT: [&str; 3] = ["std", "process", "exit"];
3637
pub const F32_EPSILON: [&str; 4] = ["core", "f32", "<impl f32>", "EPSILON"];
@@ -61,8 +62,10 @@ pub const IO_WRITE: [&str; 3] = ["std", "io", "Write"];
6162
pub const IPADDR_V4: [&str; 4] = ["std", "net", "IpAddr", "V4"];
6263
pub const IPADDR_V6: [&str; 4] = ["std", "net", "IpAddr", "V6"];
6364
pub const ITERATOR: [&str; 5] = ["core", "iter", "traits", "iterator", "Iterator"];
65+
#[cfg(feature = "internal-lints")]
6466
pub const LATE_CONTEXT: [&str; 2] = ["rustc_lint", "LateContext"];
6567
pub const LINKED_LIST: [&str; 4] = ["alloc", "collections", "linked_list", "LinkedList"];
68+
#[cfg(feature = "internal-lints")]
6669
pub const LINT: [&str; 2] = ["rustc_lint_defs", "Lint"];
6770
pub const MEM_DISCRIMINANT: [&str; 3] = ["core", "mem", "discriminant"];
6871
pub const MEM_FORGET: [&str; 3] = ["core", "mem", "forget"];
@@ -133,6 +136,7 @@ pub const STR_ENDS_WITH: [&str; 4] = ["core", "str", "<impl str>", "ends_with"];
133136
pub const STR_FROM_UTF8: [&str; 4] = ["core", "str", "converts", "from_utf8"];
134137
pub const STR_LEN: [&str; 4] = ["core", "str", "<impl str>", "len"];
135138
pub const STR_STARTS_WITH: [&str; 4] = ["core", "str", "<impl str>", "starts_with"];
139+
#[cfg(feature = "internal-lints")]
136140
pub const SYNTAX_CONTEXT: [&str; 3] = ["rustc_span", "hygiene", "SyntaxContext"];
137141
pub const TO_OWNED: [&str; 3] = ["alloc", "borrow", "ToOwned"];
138142
pub const TO_OWNED_METHOD: [&str; 4] = ["alloc", "borrow", "ToOwned", "to_owned"];

tests/compile-test.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ use std::path::{Path, PathBuf};
1212

1313
mod cargo;
1414

15+
// whether to run internal tests or not
16+
const RUN_INTERNAL_TESTS: bool = cfg!(feature = "internal-lints");
17+
1518
fn host_lib() -> PathBuf {
1619
option_env!("HOST_LIBS").map_or(cargo::CARGO_TARGET_DIR.join(env!("PROFILE")), PathBuf::from)
1720
}
@@ -96,6 +99,16 @@ fn run_mode(cfg: &mut compiletest::Config) {
9699
compiletest::run_tests(&cfg);
97100
}
98101

102+
fn run_internal_tests(cfg: &mut compiletest::Config) {
103+
// only run internal tests with the internal-tests feature
104+
if !RUN_INTERNAL_TESTS {
105+
return;
106+
}
107+
cfg.mode = TestMode::Ui;
108+
cfg.src_base = Path::new("tests").join("ui-internal");
109+
compiletest::run_tests(&cfg);
110+
}
111+
99112
fn run_ui_toml(config: &mut compiletest::Config) {
100113
fn run_tests(config: &compiletest::Config, mut tests: Vec<tester::TestDescAndFn>) -> Result<bool, io::Error> {
101114
let mut result = true;
@@ -199,7 +212,6 @@ fn run_ui_cargo(config: &mut compiletest::Config) {
199212
Some("main.rs") => {},
200213
_ => continue,
201214
}
202-
203215
let paths = compiletest::common::TestPaths {
204216
file: file_path,
205217
base: config.src_base.clone(),
@@ -253,4 +265,5 @@ fn compile_test() {
253265
run_mode(&mut config);
254266
run_ui_toml(&mut config);
255267
run_ui_cargo(&mut config);
268+
run_internal_tests(&mut config);
256269
}

tests/dogfood.rs

Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,39 @@ fn dogfood_clippy() {
1818
}
1919
let root_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
2020

21-
let output = Command::new(&*CLIPPY_PATH)
22-
.current_dir(root_dir)
23-
.env("CLIPPY_DOGFOOD", "1")
24-
.env("CARGO_INCREMENTAL", "0")
25-
.arg("clippy-preview")
26-
.arg("--all-targets")
27-
.arg("--all-features")
28-
.arg("--")
29-
.args(&["-D", "clippy::all"])
30-
.args(&["-D", "clippy::internal"])
31-
.args(&["-D", "clippy::pedantic"])
32-
.arg("-Cdebuginfo=0") // disable debuginfo to generate less data in the target dir
33-
.output()
34-
.unwrap();
21+
let output = if cfg!(feature = "internal-lints") {
22+
// with internal lints and internal warnings
23+
Command::new(&*CLIPPY_PATH)
24+
.current_dir(root_dir)
25+
.env("CLIPPY_DOGFOOD", "1")
26+
.env("CARGO_INCREMENTAL", "0")
27+
.arg("clippy-preview")
28+
.arg("--all-targets")
29+
.arg("--all-features")
30+
.args(&["--features", "internal-lints"])
31+
.arg("--")
32+
.args(&["-D", "clippy::all"])
33+
.args(&["-D", "clippy::pedantic"])
34+
.args(&["-D", "clippy::internal"])
35+
.arg("-Cdebuginfo=0") // disable debuginfo to generate less data in the target dir
36+
.output()
37+
.unwrap()
38+
} else {
39+
// without internal lints or warnings
40+
Command::new(&*CLIPPY_PATH)
41+
.current_dir(root_dir)
42+
.env("CLIPPY_DOGFOOD", "1")
43+
.env("CARGO_INCREMENTAL", "0")
44+
.arg("clippy-preview")
45+
.arg("--all-targets")
46+
.arg("--all-features")
47+
.arg("--")
48+
.args(&["-D", "clippy::all"])
49+
.args(&["-D", "clippy::pedantic"])
50+
.arg("-Cdebuginfo=0") // disable debuginfo to generate less data in the target dir
51+
.output()
52+
.unwrap()
53+
};
3554
println!("status: {}", output.status);
3655
println!("stdout: {}", String::from_utf8_lossy(&output.stdout));
3756
println!("stderr: {}", String::from_utf8_lossy(&output.stderr));
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)