Skip to content

Commit de36d42

Browse files
committed
More refactoring
1 parent 20836d3 commit de36d42

File tree

1 file changed

+12
-18
lines changed

1 file changed

+12
-18
lines changed

clippy_dev/src/lib.rs

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -58,37 +58,31 @@ impl Lint {
5858
}
5959

6060
pub fn gather_all() -> impl Iterator<Item=Lint> {
61-
let mut lints = vec![];
62-
for dir_entry in lint_files() {
63-
lints.append(&mut gather_from_file(&dir_entry).collect());
64-
}
65-
lints.into_iter()
61+
lint_files().flat_map(gather_from_file)
6662
}
6763

68-
fn gather_from_file(dir_entry: &fs::DirEntry) -> impl Iterator<Item=Lint> {
64+
fn gather_from_file(dir_entry: fs::DirEntry) -> impl Iterator<Item=Lint> {
6965
let mut file = fs::File::open(dir_entry.path()).unwrap();
7066
let mut content = String::new();
7167
file.read_to_string(&mut content).unwrap();
7268
parse_contents(&content, dir_entry.path().file_stem().unwrap().to_str().unwrap())
7369
}
7470

7571
fn parse_contents(content: &str, filename: &str) -> impl Iterator<Item=Lint> {
76-
let mut lints: Vec<Lint> = DEC_CLIPPY_LINT_RE
77-
.captures_iter(&content)
78-
.map(|m| Lint::new(&m["name"], &m["cat"], &m["desc"], None, filename))
79-
.collect();
80-
let mut deprecated = DEC_DEPRECATED_LINT_RE
81-
.captures_iter(&content)
82-
.map(|m| Lint::new( &m["name"], "Deprecated", &m["desc"], Some(&m["desc"]), filename))
83-
.collect();
84-
lints.append(&mut deprecated);
85-
lints.into_iter()
72+
let lints = DEC_CLIPPY_LINT_RE
73+
.captures_iter(content)
74+
.map(|m| Lint::new(&m["name"], &m["cat"], &m["desc"], None, filename));
75+
let deprecated = DEC_DEPRECATED_LINT_RE
76+
.captures_iter(content)
77+
.map(|m| Lint::new( &m["name"], "Deprecated", &m["desc"], Some(&m["desc"]), filename));
78+
// Removing the `.collect::<Vec<Lint>>().into_iter()` causes some lifetime issues due to the map
79+
lints.chain(deprecated).collect::<Vec<Lint>>().into_iter()
8680
}
8781

8882
/// Collects all .rs files in the `clippy_lints/src` directory
8983
fn lint_files() -> impl Iterator<Item=fs::DirEntry> {
90-
let paths = fs::read_dir("../clippy_lints/src").unwrap();
91-
paths
84+
fs::read_dir("../clippy_lints/src")
85+
.unwrap()
9286
.filter_map(|f| f.ok())
9387
.filter(|f| f.path().extension() == Some(OsStr::new("rs")))
9488
}

0 commit comments

Comments
 (0)