Skip to content

Commit 13f2619

Browse files
committed
add internal-lints feature to enable clippys internal lints (off by default)
1 parent d212c38 commit 13f2619

File tree

5 files changed

+32
-8
lines changed

5 files changed

+32
-8
lines changed

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
@@ -901,14 +901,23 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
901901
&unwrap_in_result::UNWRAP_IN_RESULT,
902902
&use_self::USE_SELF,
903903
&useless_conversion::USELESS_CONVERSION,
904+
#[cfg(feature = "internal-lints")]
904905
&utils::internal_lints::CLIPPY_LINTS_INTERNAL,
906+
#[cfg(feature = "internal-lints")]
905907
&utils::internal_lints::COLLAPSIBLE_SPAN_LINT_CALLS,
908+
#[cfg(feature = "internal-lints")]
906909
&utils::internal_lints::COMPILER_LINT_FUNCTIONS,
910+
#[cfg(feature = "internal-lints")]
907911
&utils::internal_lints::DEFAULT_LINT,
912+
#[cfg(feature = "internal-lints")]
908913
&utils::internal_lints::INVALID_PATHS,
914+
#[cfg(feature = "internal-lints")]
909915
&utils::internal_lints::LINT_WITHOUT_LINT_PASS,
916+
#[cfg(feature = "internal-lints")]
910917
&utils::internal_lints::MATCH_TYPE_ON_DIAGNOSTIC_ITEM,
918+
#[cfg(feature = "internal-lints")]
911919
&utils::internal_lints::OUTER_EXPN_EXPN_DATA,
920+
#[cfg(feature = "internal-lints")]
912921
&utils::internal_lints::PRODUCE_ICE,
913922
&vec::USELESS_VEC,
914923
&vec_resize_to_zero::VEC_RESIZE_TO_ZERO,
@@ -930,11 +939,14 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
930939

931940
store.register_late_pass(|| box await_holding_invalid::AwaitHolding);
932941
store.register_late_pass(|| box serde_api::SerdeAPI);
933-
store.register_late_pass(|| box utils::internal_lints::CompilerLintFunctions::new());
934-
store.register_late_pass(|| box utils::internal_lints::LintWithoutLintPass::default());
935-
store.register_late_pass(|| box utils::internal_lints::OuterExpnDataPass);
936-
store.register_late_pass(|| box utils::internal_lints::InvalidPaths);
937-
store.register_late_pass(|| box utils::inspector::DeepCodeInspector);
942+
#[cfg(feature = "internal-lints")]
943+
{
944+
store.register_late_pass(|| box utils::internal_lints::CompilerLintFunctions::new());
945+
store.register_late_pass(|| box utils::internal_lints::LintWithoutLintPass::default());
946+
store.register_late_pass(|| box utils::internal_lints::OuterExpnDataPass);
947+
store.register_late_pass(|| box utils::internal_lints::InvalidPaths);
948+
store.register_late_pass(|| box utils::inspector::DeepCodeInspector);
949+
}
938950
store.register_late_pass(|| box utils::author::Author);
939951
let vec_box_size_threshold = conf.vec_box_size_threshold;
940952
store.register_late_pass(move || box types::Types::new(vec_box_size_threshold));
@@ -1103,6 +1115,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
11031115
store.register_early_pass(|| box literal_representation::LiteralDigitGrouping);
11041116
let literal_representation_threshold = conf.literal_representation_threshold;
11051117
store.register_early_pass(move || box literal_representation::DecimalLiteralRepresentation::new(literal_representation_threshold));
1118+
#[cfg(feature = "internal-lints")]
11061119
store.register_early_pass(|| box utils::internal_lints::ClippyLintsInternal);
11071120
let enum_variant_name_threshold = conf.enum_variant_name_threshold;
11081121
store.register_early_pass(move || box enum_variants::EnumVariantNames::new(enum_variant_name_threshold));
@@ -1117,6 +1130,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
11171130
store.register_late_pass(move || box large_const_arrays::LargeConstArrays::new(array_size_threshold));
11181131
store.register_late_pass(|| box floating_point_arithmetic::FloatingPointArithmetic);
11191132
store.register_early_pass(|| box as_conversions::AsConversions);
1133+
#[cfg(feature = "internal-lints")]
11201134
store.register_early_pass(|| box utils::internal_lints::ProduceIce);
11211135
store.register_late_pass(|| box let_underscore::LetUnderscore);
11221136
store.register_late_pass(|| box atomic_ordering::AtomicOrdering);
@@ -1133,6 +1147,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
11331147
store.register_late_pass(|| box dereference::Dereferencing);
11341148
store.register_late_pass(|| box option_if_let_else::OptionIfLetElse);
11351149
store.register_late_pass(|| box future_not_send::FutureNotSend);
1150+
#[cfg(feature = "internal-lints")]
11361151
store.register_late_pass(|| box utils::internal_lints::CollapsibleCalls);
11371152
store.register_late_pass(|| box if_let_mutex::IfLetMutex);
11381153
store.register_late_pass(|| box mut_mutex_lock::MutMutexLock);
@@ -1160,6 +1175,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
11601175
store.register_late_pass(|| box float_equality_without_abs::FloatEqualityWithoutAbs);
11611176
store.register_late_pass(|| box async_yields_async::AsyncYieldsAsync);
11621177
store.register_late_pass(|| box manual_strip::ManualStrip);
1178+
#[cfg(feature = "internal-lints")]
11631179
store.register_late_pass(|| box utils::internal_lints::MatchTypeOnDiagItem);
11641180
let disallowed_methods = conf.disallowed_methods.iter().cloned().collect::<FxHashSet<_>>();
11651181
store.register_late_pass(move || box disallowed_method::DisallowedMethod::new(&disallowed_methods));
@@ -1293,7 +1309,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
12931309
LintId::of(&wildcard_imports::ENUM_GLOB_USE),
12941310
LintId::of(&wildcard_imports::WILDCARD_IMPORTS),
12951311
]);
1296-
1312+
#[cfg(feature = "internal-lints")]
12971313
store.register_group(true, "clippy::internal", Some("clippy_internal"), vec![
12981314
LintId::of(&utils::internal_lints::CLIPPY_LINTS_INTERNAL),
12991315
LintId::of(&utils::internal_lints::COLLAPSIBLE_SPAN_LINT_CALLS),

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"];
@@ -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"];

0 commit comments

Comments
 (0)