Skip to content

Commit 37b4edf

Browse files
committed
add internal-lints feature to enable clippys internal lints (off by default)
1 parent b1faa7f commit 37b4edf

File tree

5 files changed

+40
-1
lines changed

5 files changed

+40
-1
lines changed

Cargo.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ path = "src/driver.rs"
2929

3030
[dependencies]
3131
# begin automatic update
32-
clippy_lints = { version = "0.0.212", path = "clippy_lints" }
32+
clippy_lints = { version = "0.0.212", path = "clippy_lints"}
3333
# end automatic update
3434
semver = "0.11"
3535
rustc_tools_util = { version = "0.2.0", path = "rustc_tools_util"}
@@ -54,3 +54,4 @@ rustc_tools_util = { version = "0.2.0", path = "rustc_tools_util"}
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

+31
Original file line numberDiff line numberDiff line change
@@ -901,15 +901,34 @@ 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")]
907+
905908
&utils::internal_lints::COLLAPSIBLE_SPAN_LINT_CALLS,
909+
#[cfg(feature = "internal-lints")]
910+
906911
&utils::internal_lints::COMPILER_LINT_FUNCTIONS,
912+
#[cfg(feature = "internal-lints")]
913+
907914
&utils::internal_lints::DEFAULT_LINT,
915+
#[cfg(feature = "internal-lints")]
916+
908917
&utils::internal_lints::INVALID_PATHS,
918+
#[cfg(feature = "internal-lints")]
919+
909920
&utils::internal_lints::LINT_WITHOUT_LINT_PASS,
921+
#[cfg(feature = "internal-lints")]
922+
910923
&utils::internal_lints::MATCH_TYPE_ON_DIAGNOSTIC_ITEM,
924+
#[cfg(feature = "internal-lints")]
925+
911926
&utils::internal_lints::OUTER_EXPN_EXPN_DATA,
927+
#[cfg(feature = "internal-lints")]
928+
912929
&utils::internal_lints::PRODUCE_ICE,
930+
#[cfg(feature = "internal-lints")]
931+
913932
&vec::USELESS_VEC,
914933
&vec_resize_to_zero::VEC_RESIZE_TO_ZERO,
915934
&verbose_file_reads::VERBOSE_FILE_READS,
@@ -930,11 +949,14 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
930949

931950
store.register_late_pass(|| box await_holding_invalid::AwaitHolding);
932951
store.register_late_pass(|| box serde_api::SerdeAPI);
952+
#[cfg(feature = "internal-lints")]
953+
{
933954
store.register_late_pass(|| box utils::internal_lints::CompilerLintFunctions::new());
934955
store.register_late_pass(|| box utils::internal_lints::LintWithoutLintPass::default());
935956
store.register_late_pass(|| box utils::internal_lints::OuterExpnDataPass);
936957
store.register_late_pass(|| box utils::internal_lints::InvalidPaths);
937958
store.register_late_pass(|| box utils::inspector::DeepCodeInspector);
959+
}
938960
store.register_late_pass(|| box utils::author::Author);
939961
let vec_box_size_threshold = conf.vec_box_size_threshold;
940962
store.register_late_pass(move || box types::Types::new(vec_box_size_threshold));
@@ -1103,6 +1125,8 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
11031125
store.register_early_pass(|| box literal_representation::LiteralDigitGrouping);
11041126
let literal_representation_threshold = conf.literal_representation_threshold;
11051127
store.register_early_pass(move || box literal_representation::DecimalLiteralRepresentation::new(literal_representation_threshold));
1128+
#[cfg(feature = "internal-lints")]
1129+
11061130
store.register_early_pass(|| box utils::internal_lints::ClippyLintsInternal);
11071131
let enum_variant_name_threshold = conf.enum_variant_name_threshold;
11081132
store.register_early_pass(move || box enum_variants::EnumVariantNames::new(enum_variant_name_threshold));
@@ -1117,6 +1141,8 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
11171141
store.register_late_pass(move || box large_const_arrays::LargeConstArrays::new(array_size_threshold));
11181142
store.register_late_pass(|| box floating_point_arithmetic::FloatingPointArithmetic);
11191143
store.register_early_pass(|| box as_conversions::AsConversions);
1144+
#[cfg(feature = "internal-lints")]
1145+
11201146
store.register_early_pass(|| box utils::internal_lints::ProduceIce);
11211147
store.register_late_pass(|| box let_underscore::LetUnderscore);
11221148
store.register_late_pass(|| box atomic_ordering::AtomicOrdering);
@@ -1133,6 +1159,8 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
11331159
store.register_late_pass(|| box dereference::Dereferencing);
11341160
store.register_late_pass(|| box option_if_let_else::OptionIfLetElse);
11351161
store.register_late_pass(|| box future_not_send::FutureNotSend);
1162+
#[cfg(feature = "internal-lints")]
1163+
11361164
store.register_late_pass(|| box utils::internal_lints::CollapsibleCalls);
11371165
store.register_late_pass(|| box if_let_mutex::IfLetMutex);
11381166
store.register_late_pass(|| box mut_mutex_lock::MutMutexLock);
@@ -1160,6 +1188,8 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
11601188
store.register_late_pass(|| box float_equality_without_abs::FloatEqualityWithoutAbs);
11611189
store.register_late_pass(|| box async_yields_async::AsyncYieldsAsync);
11621190
store.register_late_pass(|| box manual_strip::ManualStrip);
1191+
#[cfg(feature = "internal-lints")]
1192+
11631193
store.register_late_pass(|| box utils::internal_lints::MatchTypeOnDiagItem);
11641194
let disallowed_methods = conf.disallowed_methods.iter().cloned().collect::<FxHashSet<_>>();
11651195
store.register_late_pass(move || box disallowed_method::DisallowedMethod::new(&disallowed_methods));
@@ -1293,6 +1323,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
12931323
LintId::of(&wildcard_imports::ENUM_GLOB_USE),
12941324
LintId::of(&wildcard_imports::WILDCARD_IMPORTS),
12951325
]);
1326+
#[cfg(feature = "internal-lints")]
12961327

12971328
store.register_group(true, "clippy::internal", Some("clippy_internal"), vec![
12981329
LintId::of(&utils::internal_lints::CLIPPY_LINTS_INTERNAL),

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

0 commit comments

Comments
 (0)