diff options
| author | Philipp Hansch <dev@phansch.net> | 2018-09-05 20:32:26 +0200 |
|---|---|---|
| committer | Philipp Hansch <dev@phansch.net> | 2018-09-06 07:15:31 +0200 |
| commit | de36d42e80864f40fb3075dc4e3389cfa0c113b2 (patch) | |
| tree | 7a57c2193eccdd9ebbef9961c127a4c9d7a8f32e /clippy_dev/src | |
| parent | 20836d3003050d4abd313eb9fda4dc8bb6bc7f9c (diff) | |
| download | rust-de36d42e80864f40fb3075dc4e3389cfa0c113b2.tar.gz rust-de36d42e80864f40fb3075dc4e3389cfa0c113b2.zip | |
More refactoring
Diffstat (limited to 'clippy_dev/src')
| -rw-r--r-- | clippy_dev/src/lib.rs | 30 |
1 files changed, 12 insertions, 18 deletions
diff --git a/clippy_dev/src/lib.rs b/clippy_dev/src/lib.rs index c499934346e..998efb142cc 100644 --- a/clippy_dev/src/lib.rs +++ b/clippy_dev/src/lib.rs @@ -58,14 +58,10 @@ impl Lint { } pub fn gather_all() -> impl Iterator<Item=Lint> { - let mut lints = vec![]; - for dir_entry in lint_files() { - lints.append(&mut gather_from_file(&dir_entry).collect()); - } - lints.into_iter() + lint_files().flat_map(gather_from_file) } -fn gather_from_file(dir_entry: &fs::DirEntry) -> impl Iterator<Item=Lint> { +fn gather_from_file(dir_entry: fs::DirEntry) -> impl Iterator<Item=Lint> { let mut file = fs::File::open(dir_entry.path()).unwrap(); let mut content = String::new(); file.read_to_string(&mut content).unwrap(); @@ -73,22 +69,20 @@ fn gather_from_file(dir_entry: &fs::DirEntry) -> impl Iterator<Item=Lint> { } fn parse_contents(content: &str, filename: &str) -> impl Iterator<Item=Lint> { - let mut lints: Vec<Lint> = DEC_CLIPPY_LINT_RE - .captures_iter(&content) - .map(|m| Lint::new(&m["name"], &m["cat"], &m["desc"], None, filename)) - .collect(); - let mut deprecated = DEC_DEPRECATED_LINT_RE - .captures_iter(&content) - .map(|m| Lint::new( &m["name"], "Deprecated", &m["desc"], Some(&m["desc"]), filename)) - .collect(); - lints.append(&mut deprecated); - lints.into_iter() + let lints = DEC_CLIPPY_LINT_RE + .captures_iter(content) + .map(|m| Lint::new(&m["name"], &m["cat"], &m["desc"], None, filename)); + let deprecated = DEC_DEPRECATED_LINT_RE + .captures_iter(content) + .map(|m| Lint::new( &m["name"], "Deprecated", &m["desc"], Some(&m["desc"]), filename)); + // Removing the `.collect::<Vec<Lint>>().into_iter()` causes some lifetime issues due to the map + lints.chain(deprecated).collect::<Vec<Lint>>().into_iter() } /// Collects all .rs files in the `clippy_lints/src` directory fn lint_files() -> impl Iterator<Item=fs::DirEntry> { - let paths = fs::read_dir("../clippy_lints/src").unwrap(); - paths + fs::read_dir("../clippy_lints/src") + .unwrap() .filter_map(|f| f.ok()) .filter(|f| f.path().extension() == Some(OsStr::new("rs"))) } |
