Skip to content

Commit 3fdacb5

Browse files
committed
clippy: replace flat_map with filter_map
BasePattern::as_identifier returns an Option; when iterating we can filter out the Nones with `filter_map`. We were instead using `flat_map`, which is much more general: it turns the Options into iterators (which will yield 0 or 1 items) and then yields everything from the iterators. This is potentially slower and more complicated to read.
1 parent 2c7b1fb commit 3fdacb5

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ explicit_deref_methods = "warn"
7373
explicit_into_iter_loop = "warn"
7474
explicit_iter_loop = "warn"
7575
filter_map_next = "warn"
76-
flat_map_option = "allow"
76+
flat_map_option = "warn"
7777
float_cmp = "warn"
7878
fn_params_excessive_bools = "warn"
7979
from_iter_instead_of_collect = "warn"

src/pattern.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ impl BasePattern {
259259

260260
/// Get an iterator over all identifiers inside the pattern.
261261
pub fn identifiers(&self) -> impl Iterator<Item = &Identifier> {
262-
self.pre_order_iter().flat_map(BasePattern::as_identifier)
262+
self.pre_order_iter().filter_map(BasePattern::as_identifier)
263263
}
264264

265265
/// Check if all `identifiers` are contained inside the pattern.

0 commit comments

Comments
 (0)