1
Fork 0

Auto merge of #7780 - mikerite:update_lints_mod_revert, r=llogiq

Revert `update_lints` module list generating code

This commit reverts the module list generation code to what it was
before the change to `include!` it and generates better output.

changelog: none
This commit is contained in:
bors 2021-10-07 05:00:53 +00:00
commit 01ea06acb7
2 changed files with 10 additions and 17 deletions

View file

@ -1,6 +1,6 @@
use itertools::Itertools; use itertools::Itertools;
use regex::Regex; use regex::Regex;
use std::collections::{BTreeSet, HashMap}; use std::collections::HashMap;
use std::ffi::OsStr; use std::ffi::OsStr;
use std::fs; use std::fs;
use std::lazy::SyncLazy; use std::lazy::SyncLazy;
@ -105,7 +105,7 @@ pub fn run(update_mode: UpdateMode) {
"end lints modules", "end lints modules",
false, false,
update_mode == UpdateMode::Change, update_mode == UpdateMode::Change,
|| vec![gen_modules_list(usable_lints.iter())], || gen_modules_list(usable_lints.iter()),
) )
.changed; .changed;
@ -262,14 +262,13 @@ fn gen_lint_group_list<'a>(group_name: &str, lints: impl Iterator<Item = &'a Lin
/// Generates the module declarations for `lints` /// Generates the module declarations for `lints`
#[must_use] #[must_use]
fn gen_modules_list<'a>(lints: impl Iterator<Item = &'a Lint>) -> String { fn gen_modules_list<'a>(lints: impl Iterator<Item = &'a Lint>) -> Vec<String> {
let module_names: BTreeSet<_> = lints.map(|l| &l.module).collect(); lints
.map(|l| &l.module)
let mut output = GENERATED_FILE_COMMENT.to_string(); .unique()
for name in module_names { .map(|module| format!("mod {};", module))
output.push_str(&format!("mod {};\n", name)); .sorted()
} .collect::<Vec<String>>()
output
} }
/// Generates the list of lint links at the bottom of the CHANGELOG /// Generates the list of lint links at the bottom of the CHANGELOG
@ -677,8 +676,7 @@ mod tests {
Lint::new("should_assert_eq", "group1", "abc", None, "module_name"), Lint::new("should_assert_eq", "group1", "abc", None, "module_name"),
Lint::new("incorrect_stuff", "group3", "abc", None, "another_module"), Lint::new("incorrect_stuff", "group3", "abc", None, "another_module"),
]; ];
let expected = let expected = vec!["mod another_module;".to_string(), "mod module_name;".to_string()];
GENERATED_FILE_COMMENT.to_string() + &["mod another_module;", "mod module_name;"].join("\n") + "\n";
assert_eq!(expected, gen_modules_list(lints.iter())); assert_eq!(expected, gen_modules_list(lints.iter()));
} }

View file

@ -156,10 +156,6 @@ mod deprecated_lints;
mod utils; mod utils;
// begin lints modules, do not remove this comment, its used in `update_lints` // begin lints modules, do not remove this comment, its used in `update_lints`
// This file was generated by `cargo dev update_lints`.
// Use that command to update this file and do not edit by hand.
// Manual edits will be overwritten.
mod absurd_extreme_comparisons; mod absurd_extreme_comparisons;
mod approx_const; mod approx_const;
mod arithmetic; mod arithmetic;
@ -390,7 +386,6 @@ mod wildcard_imports;
mod write; mod write;
mod zero_div_zero; mod zero_div_zero;
mod zero_sized_map_values; mod zero_sized_map_values;
// end lints modules, do not remove this comment, its used in `update_lints` // end lints modules, do not remove this comment, its used in `update_lints`
pub use crate::utils::conf::Conf; pub use crate::utils::conf::Conf;