Make Lint::by_lint_group take impl Iterator as argument

This commit is contained in:
flip1995 2020-02-11 11:07:38 +01:00
parent 41d90d3b8e
commit 560559bafe
No known key found for this signature in database
GPG key ID: 693086869D506637
2 changed files with 5 additions and 8 deletions

View file

@ -63,11 +63,8 @@ impl Lint {
/// Returns the lints in a `HashMap`, grouped by the different lint groups
#[must_use]
pub fn by_lint_group(lints: &[Self]) -> HashMap<String, Vec<Self>> {
lints
.iter()
.map(|lint| (lint.group.to_string(), lint.clone()))
.into_group_map()
pub fn by_lint_group(lints: impl Iterator<Item = Self>) -> HashMap<String, Vec<Self>> {
lints.map(|lint| (lint.group.to_string(), lint)).into_group_map()
}
#[must_use]
@ -449,7 +446,7 @@ fn test_by_lint_group() {
"group2".to_string(),
vec![Lint::new("should_assert_eq2", "group2", "abc", None, "module_name")],
);
assert_eq!(expected, Lint::by_lint_group(&lints));
assert_eq!(expected, Lint::by_lint_group(lints.into_iter()));
}
#[test]

View file

@ -136,7 +136,7 @@ fn print_lints() {
let lint_list = gather_all();
let usable_lints: Vec<Lint> = Lint::usable_lints(lint_list).collect();
let lint_count = usable_lints.len();
let grouped_by_lint_group = Lint::by_lint_group(&usable_lints);
let grouped_by_lint_group = Lint::by_lint_group(usable_lints.into_iter());
for (lint_group, mut lints) in grouped_by_lint_group {
if lint_group == "Deprecated" {
@ -267,7 +267,7 @@ fn update_lints(update_mode: UpdateMode) {
.changed;
// Generate the list of lints for all other lint groups
for (lint_group, lints) in Lint::by_lint_group(&usable_lints) {
for (lint_group, lints) in Lint::by_lint_group(usable_lints.into_iter()) {
file_change |= replace_region_in_file(
Path::new("clippy_lints/src/lib.rs"),
&format!("store.register_group\\(true, \"clippy::{}\"", lint_group),