|
1 | 1 | use itertools::Itertools; |
2 | 2 | use regex::Regex; |
3 | | -use std::collections::{BTreeSet, HashMap}; |
| 3 | +use std::collections::HashMap; |
4 | 4 | use std::ffi::OsStr; |
5 | 5 | use std::fs; |
6 | 6 | use std::lazy::SyncLazy; |
@@ -105,7 +105,7 @@ pub fn run(update_mode: UpdateMode) { |
105 | 105 | "end lints modules", |
106 | 106 | false, |
107 | 107 | update_mode == UpdateMode::Change, |
108 | | - || vec![gen_modules_list(usable_lints.iter())], |
| 108 | + || gen_modules_list(usable_lints.iter()), |
109 | 109 | ) |
110 | 110 | .changed; |
111 | 111 |
|
@@ -262,14 +262,13 @@ fn gen_lint_group_list<'a>(group_name: &str, lints: impl Iterator<Item = &'a Lin |
262 | 262 |
|
263 | 263 | /// Generates the module declarations for `lints` |
264 | 264 | #[must_use] |
265 | | -fn gen_modules_list<'a>(lints: impl Iterator<Item = &'a Lint>) -> String { |
266 | | - let module_names: BTreeSet<_> = lints.map(|l| &l.module).collect(); |
267 | | - |
268 | | - let mut output = GENERATED_FILE_COMMENT.to_string(); |
269 | | - for name in module_names { |
270 | | - output.push_str(&format!("mod {};\n", name)); |
271 | | - } |
272 | | - output |
| 265 | +fn gen_modules_list<'a>(lints: impl Iterator<Item = &'a Lint>) -> Vec<String> { |
| 266 | + lints |
| 267 | + .map(|l| &l.module) |
| 268 | + .unique() |
| 269 | + .map(|module| format!("mod {};", module)) |
| 270 | + .sorted() |
| 271 | + .collect::<Vec<String>>() |
273 | 272 | } |
274 | 273 |
|
275 | 274 | /// Generates the list of lint links at the bottom of the CHANGELOG |
@@ -677,8 +676,7 @@ mod tests { |
677 | 676 | Lint::new("should_assert_eq", "group1", "abc", None, "module_name"), |
678 | 677 | Lint::new("incorrect_stuff", "group3", "abc", None, "another_module"), |
679 | 678 | ]; |
680 | | - let expected = |
681 | | - GENERATED_FILE_COMMENT.to_string() + &["mod another_module;", "mod module_name;"].join("\n") + "\n"; |
| 679 | + let expected = vec!["mod another_module;".to_string(), "mod module_name;".to_string()]; |
682 | 680 | assert_eq!(expected, gen_modules_list(lints.iter())); |
683 | 681 | } |
684 | 682 |
|
|
0 commit comments