Skip to content

Commit 44908a2

Browse files
committed
add internal-lints feature to enable clippys internal lints (off by default)
1 parent bd13a35 commit 44908a2

25 files changed

+84
-26
lines changed

.github/workflows/clippy_bors.yml

+2-2
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

+3-2
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

+2
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

+22-6
Original file line numberDiff line numberDiff line change
@@ -902,14 +902,23 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
902902
&unwrap_in_result::UNWRAP_IN_RESULT,
903903
&use_self::USE_SELF,
904904
&useless_conversion::USELESS_CONVERSION,
905+
#[cfg(feature = "internal-lints")]
905906
&utils::internal_lints::CLIPPY_LINTS_INTERNAL,
907+
#[cfg(feature = "internal-lints")]
906908
&utils::internal_lints::COLLAPSIBLE_SPAN_LINT_CALLS,
909+
#[cfg(feature = "internal-lints")]
907910
&utils::internal_lints::COMPILER_LINT_FUNCTIONS,
911+
#[cfg(feature = "internal-lints")]
908912
&utils::internal_lints::DEFAULT_LINT,
913+
#[cfg(feature = "internal-lints")]
909914
&utils::internal_lints::INVALID_PATHS,
915+
#[cfg(feature = "internal-lints")]
910916
&utils::internal_lints::LINT_WITHOUT_LINT_PASS,
917+
#[cfg(feature = "internal-lints")]
911918
&utils::internal_lints::MATCH_TYPE_ON_DIAGNOSTIC_ITEM,
919+
#[cfg(feature = "internal-lints")]
912920
&utils::internal_lints::OUTER_EXPN_EXPN_DATA,
921+
#[cfg(feature = "internal-lints")]
913922
&utils::internal_lints::PRODUCE_ICE,
914923
&vec::USELESS_VEC,
915924
&vec_resize_to_zero::VEC_RESIZE_TO_ZERO,
@@ -931,11 +940,14 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
931940

932941
store.register_late_pass(|| box await_holding_invalid::AwaitHolding);
933942
store.register_late_pass(|| box serde_api::SerdeAPI);
934-
store.register_late_pass(|| box utils::internal_lints::CompilerLintFunctions::new());
935-
store.register_late_pass(|| box utils::internal_lints::LintWithoutLintPass::default());
936-
store.register_late_pass(|| box utils::internal_lints::OuterExpnDataPass);
937-
store.register_late_pass(|| box utils::internal_lints::InvalidPaths);
938-
store.register_late_pass(|| box utils::inspector::DeepCodeInspector);
943+
#[cfg(feature = "internal-lints")]
944+
{
945+
store.register_late_pass(|| box utils::internal_lints::CompilerLintFunctions::new());
946+
store.register_late_pass(|| box utils::internal_lints::LintWithoutLintPass::default());
947+
store.register_late_pass(|| box utils::internal_lints::OuterExpnDataPass);
948+
store.register_late_pass(|| box utils::internal_lints::InvalidPaths);
949+
store.register_late_pass(|| box utils::inspector::DeepCodeInspector);
950+
}
939951
store.register_late_pass(|| box utils::author::Author);
940952
let vec_box_size_threshold = conf.vec_box_size_threshold;
941953
store.register_late_pass(move || box types::Types::new(vec_box_size_threshold));
@@ -1104,6 +1116,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
11041116
store.register_early_pass(|| box literal_representation::LiteralDigitGrouping);
11051117
let literal_representation_threshold = conf.literal_representation_threshold;
11061118
store.register_early_pass(move || box literal_representation::DecimalLiteralRepresentation::new(literal_representation_threshold));
1119+
#[cfg(feature = "internal-lints")]
11071120
store.register_early_pass(|| box utils::internal_lints::ClippyLintsInternal);
11081121
let enum_variant_name_threshold = conf.enum_variant_name_threshold;
11091122
store.register_early_pass(move || box enum_variants::EnumVariantNames::new(enum_variant_name_threshold));
@@ -1118,6 +1131,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
11181131
store.register_late_pass(move || box large_const_arrays::LargeConstArrays::new(array_size_threshold));
11191132
store.register_late_pass(|| box floating_point_arithmetic::FloatingPointArithmetic);
11201133
store.register_early_pass(|| box as_conversions::AsConversions);
1134+
#[cfg(feature = "internal-lints")]
11211135
store.register_early_pass(|| box utils::internal_lints::ProduceIce);
11221136
store.register_late_pass(|| box let_underscore::LetUnderscore);
11231137
store.register_late_pass(|| box atomic_ordering::AtomicOrdering);
@@ -1134,6 +1148,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
11341148
store.register_late_pass(|| box dereference::Dereferencing);
11351149
store.register_late_pass(|| box option_if_let_else::OptionIfLetElse);
11361150
store.register_late_pass(|| box future_not_send::FutureNotSend);
1151+
#[cfg(feature = "internal-lints")]
11371152
store.register_late_pass(|| box utils::internal_lints::CollapsibleCalls);
11381153
store.register_late_pass(|| box if_let_mutex::IfLetMutex);
11391154
store.register_late_pass(|| box mut_mutex_lock::MutMutexLock);
@@ -1161,6 +1176,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
11611176
store.register_late_pass(|| box float_equality_without_abs::FloatEqualityWithoutAbs);
11621177
store.register_late_pass(|| box async_yields_async::AsyncYieldsAsync);
11631178
store.register_late_pass(|| box manual_strip::ManualStrip);
1179+
#[cfg(feature = "internal-lints")]
11641180
store.register_late_pass(|| box utils::internal_lints::MatchTypeOnDiagItem);
11651181
let disallowed_methods = conf.disallowed_methods.iter().cloned().collect::<FxHashSet<_>>();
11661182
store.register_late_pass(move || box disallowed_method::DisallowedMethod::new(&disallowed_methods));
@@ -1295,7 +1311,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
12951311
LintId::of(&wildcard_imports::ENUM_GLOB_USE),
12961312
LintId::of(&wildcard_imports::WILDCARD_IMPORTS),
12971313
]);
1298-
1314+
#[cfg(feature = "internal-lints")]
12991315
store.register_group(true, "clippy::internal", Some("clippy_internal"), vec![
13001316
LintId::of(&utils::internal_lints::CLIPPY_LINTS_INTERNAL),
13011317
LintId::of(&utils::internal_lints::COLLAPSIBLE_SPAN_LINT_CALLS),

clippy_lints/src/utils/diagnostics.rs

+3-1
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

+1
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

+4
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"];
@@ -59,8 +60,10 @@ pub const INTO_ITERATOR: [&str; 5] = ["core", "iter", "traits", "collect", "Into
5960
pub const IO_READ: [&str; 3] = ["std", "io", "Read"];
6061
pub const IO_WRITE: [&str; 3] = ["std", "io", "Write"];
6162
pub const ITERATOR: [&str; 5] = ["core", "iter", "traits", "iterator", "Iterator"];
63+
#[cfg(feature = "internal-lints")]
6264
pub const LATE_CONTEXT: [&str; 2] = ["rustc_lint", "LateContext"];
6365
pub const LINKED_LIST: [&str; 4] = ["alloc", "collections", "linked_list", "LinkedList"];
66+
#[cfg(feature = "internal-lints")]
6467
pub const LINT: [&str; 2] = ["rustc_lint_defs", "Lint"];
6568
pub const MEM_DISCRIMINANT: [&str; 3] = ["core", "mem", "discriminant"];
6669
pub const MEM_FORGET: [&str; 3] = ["core", "mem", "forget"];
@@ -125,6 +128,7 @@ pub const STR_ENDS_WITH: [&str; 4] = ["core", "str", "<impl str>", "ends_with"];
125128
pub const STR_FROM_UTF8: [&str; 4] = ["core", "str", "converts", "from_utf8"];
126129
pub const STR_LEN: [&str; 4] = ["core", "str", "<impl str>", "len"];
127130
pub const STR_STARTS_WITH: [&str; 4] = ["core", "str", "<impl str>", "starts_with"];
131+
#[cfg(feature = "internal-lints")]
128132
pub const SYNTAX_CONTEXT: [&str; 3] = ["rustc_span", "hygiene", "SyntaxContext"];
129133
pub const TO_OWNED: [&str; 3] = ["alloc", "borrow", "ToOwned"];
130134
pub const TO_OWNED_METHOD: [&str; 4] = ["alloc", "borrow", "ToOwned", "to_owned"];

tests/compile-test.rs

+14-1
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

+33-14
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)