Skip to content

Commit a186d9f

Browse files
committed
Don't filter lints in code generation functions
1 parent 98c30fe commit a186d9f

File tree

1 file changed

+22
-30
lines changed

1 file changed

+22
-30
lines changed

clippy_dev/src/lib.rs

Lines changed: 22 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -94,13 +94,7 @@ impl Lint {
9494
#[must_use]
9595
pub fn gen_lint_group_list<'a>(lints: impl Iterator<Item = &'a Lint>) -> Vec<String> {
9696
lints
97-
.filter_map(|l| {
98-
if l.deprecation.is_some() {
99-
None
100-
} else {
101-
Some(format!(" LintId::of(&{}::{}),", l.module, l.name.to_uppercase()))
102-
}
103-
})
97+
.map(|l| format!(" LintId::of(&{}::{}),", l.module, l.name.to_uppercase()))
10498
.sorted()
10599
.collect::<Vec<String>>()
106100
}
@@ -120,32 +114,28 @@ pub fn gen_modules_list<'a>(lints: impl Iterator<Item = &'a Lint>) -> Vec<String
120114
#[must_use]
121115
pub fn gen_changelog_lint_list<'a>(lints: impl Iterator<Item = &'a Lint>) -> Vec<String> {
122116
lints
123-
.sorted_by_key(|l| l.name.clone())
124-
.filter_map(|l| {
125-
if l.group.starts_with("internal") {
126-
None
127-
} else {
128-
Some(format!("[`{}`]: {}#{}", l.name, DOCS_LINK, l.name))
129-
}
130-
})
117+
.sorted_by_key(|l| &l.name)
118+
.map(|l| format!("[`{}`]: {}#{}", l.name, DOCS_LINK, l.name))
131119
.collect()
132120
}
133121

134122
/// Generates the `register_removed` code in `./clippy_lints/src/lib.rs`.
135123
#[must_use]
136124
pub fn gen_deprecated<'a>(lints: impl Iterator<Item = &'a Lint>) -> Vec<String> {
137125
lints
138-
.filter_map(|l| {
139-
l.clone().deprecation.map(|depr_text| {
140-
vec![
141-
" store.register_removed(".to_string(),
142-
format!(" \"clippy::{}\",", l.name),
143-
format!(" \"{}\",", depr_text),
144-
" );".to_string(),
145-
]
146-
})
126+
.flat_map(|l| {
127+
l.deprecation
128+
.clone()
129+
.map(|depr_text| {
130+
vec![
131+
" store.register_removed(".to_string(),
132+
format!(" \"clippy::{}\",", l.name),
133+
format!(" \"{}\",", depr_text),
134+
" );".to_string(),
135+
]
136+
})
137+
.expect("only deprecated lints should be passed")
147138
})
148-
.flatten()
149139
.collect::<Vec<String>>()
150140
}
151141

@@ -458,7 +448,6 @@ fn test_gen_changelog_lint_list() {
458448
let lints = vec![
459449
Lint::new("should_assert_eq", "group1", "abc", None, "module_name"),
460450
Lint::new("should_assert_eq2", "group2", "abc", None, "module_name"),
461-
Lint::new("incorrect_internal", "internal_style", "abc", None, "module_name"),
462451
];
463452
let expected = vec![
464453
format!("[`should_assert_eq`]: {}#should_assert_eq", DOCS_LINK.to_string()),
@@ -484,7 +473,6 @@ fn test_gen_deprecated() {
484473
Some("will be removed"),
485474
"module_name",
486475
),
487-
Lint::new("should_assert_eq2", "group2", "abc", None, "module_name"),
488476
];
489477
let expected: Vec<String> = vec![
490478
" store.register_removed(",
@@ -502,13 +490,18 @@ fn test_gen_deprecated() {
502490
assert_eq!(expected, gen_deprecated(lints.iter()));
503491
}
504492

493+
#[test]
494+
#[should_panic]
495+
fn test_gen_deprecated_fail() {
496+
let lints = vec![Lint::new("should_assert_eq2", "group2", "abc", None, "module_name")];
497+
let _ = gen_deprecated(lints.iter());
498+
}
499+
505500
#[test]
506501
fn test_gen_modules_list() {
507502
let lints = vec![
508503
Lint::new("should_assert_eq", "group1", "abc", None, "module_name"),
509-
Lint::new("should_assert_eq2", "group2", "abc", Some("abc"), "deprecated"),
510504
Lint::new("incorrect_stuff", "group3", "abc", None, "another_module"),
511-
Lint::new("incorrect_internal", "internal_style", "abc", None, "module_name"),
512505
];
513506
let expected = vec![
514507
"pub mod another_module;".to_string(),
@@ -522,7 +515,6 @@ fn test_gen_lint_group_list() {
522515
let lints = vec![
523516
Lint::new("abc", "group1", "abc", None, "module_name"),
524517
Lint::new("should_assert_eq", "group1", "abc", None, "module_name"),
525-
Lint::new("should_assert_eq2", "group2", "abc", Some("abc"), "deprecated"),
526518
Lint::new("internal", "internal_style", "abc", None, "module_name"),
527519
];
528520
let expected = vec![

0 commit comments

Comments
 (0)