Skip to content

Commit 7dd11b8

Browse files
authored
Check config options in test suite (#15397)
Check that all configuration options reference existing lints. This was prompted by a discussion on a PR review in which a non-detected discrepancy was introduced. While adding and testing this test, references to two non-existing lints were removed. This test doesn't run as part of the rustc test suite. changelog: none
2 parents 85622ca + 07b04a2 commit 7dd11b8

File tree

3 files changed

+30
-4
lines changed

3 files changed

+30
-4
lines changed

book/src/lint_configuration.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -873,15 +873,13 @@ The minimum rust version that the project supports. Defaults to the `rust-versio
873873
* [`needless_borrow`](https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow)
874874
* [`non_std_lazy_statics`](https://rust-lang.github.io/rust-clippy/master/index.html#non_std_lazy_statics)
875875
* [`option_as_ref_deref`](https://rust-lang.github.io/rust-clippy/master/index.html#option_as_ref_deref)
876-
* [`option_map_unwrap_or`](https://rust-lang.github.io/rust-clippy/master/index.html#option_map_unwrap_or)
877876
* [`ptr_as_ptr`](https://rust-lang.github.io/rust-clippy/master/index.html#ptr_as_ptr)
878877
* [`question_mark`](https://rust-lang.github.io/rust-clippy/master/index.html#question_mark)
879878
* [`redundant_field_names`](https://rust-lang.github.io/rust-clippy/master/index.html#redundant_field_names)
880879
* [`redundant_static_lifetimes`](https://rust-lang.github.io/rust-clippy/master/index.html#redundant_static_lifetimes)
881880
* [`repeat_vec_with_capacity`](https://rust-lang.github.io/rust-clippy/master/index.html#repeat_vec_with_capacity)
882881
* [`same_item_push`](https://rust-lang.github.io/rust-clippy/master/index.html#same_item_push)
883882
* [`seek_from_current`](https://rust-lang.github.io/rust-clippy/master/index.html#seek_from_current)
884-
* [`seek_rewind`](https://rust-lang.github.io/rust-clippy/master/index.html#seek_rewind)
885883
* [`to_digit_is_some`](https://rust-lang.github.io/rust-clippy/master/index.html#to_digit_is_some)
886884
* [`transmute_ptr_to_ref`](https://rust-lang.github.io/rust-clippy/master/index.html#transmute_ptr_to_ref)
887885
* [`tuple_array_conversions`](https://rust-lang.github.io/rust-clippy/master/index.html#tuple_array_conversions)

clippy_config/src/conf.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -775,15 +775,13 @@ define_Conf! {
775775
needless_borrow,
776776
non_std_lazy_statics,
777777
option_as_ref_deref,
778-
option_map_unwrap_or,
779778
ptr_as_ptr,
780779
question_mark,
781780
redundant_field_names,
782781
redundant_static_lifetimes,
783782
repeat_vec_with_capacity,
784783
same_item_push,
785784
seek_from_current,
786-
seek_rewind,
787785
to_digit_is_some,
788786
transmute_ptr_to_ref,
789787
tuple_array_conversions,

tests/config-consistency.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#![feature(rustc_private)]
2+
3+
// This test checks that all lints defined in `clippy_config::conf` in `#[lints]`
4+
// attributes exist as Clippy lints.
5+
//
6+
// This test is a no-op if run as part of the compiler test suite
7+
// and will always succeed.
8+
9+
use std::collections::HashSet;
10+
11+
#[test]
12+
fn config_consistency() {
13+
if option_env!("RUSTC_TEST_SUITE").is_some() {
14+
return;
15+
}
16+
17+
let lint_names: HashSet<String> = clippy_lints::declared_lints::LINTS
18+
.iter()
19+
.map(|lint_info| lint_info.lint.name.strip_prefix("clippy::").unwrap().to_lowercase())
20+
.collect();
21+
for conf in clippy_config::get_configuration_metadata() {
22+
for lint in conf.lints {
23+
assert!(
24+
lint_names.contains(*lint),
25+
"Configuration option {} references lint `{lint}` which does not exist",
26+
conf.name
27+
);
28+
}
29+
}
30+
}

0 commit comments

Comments
 (0)