Skip to content

Commit 0fc8f4a

Browse files
committed
clippy: turn on map_unwrap_or lint
Style. This one looks a bit scary because it's not obvious what the right order of parameters to `map_or` is, but actually it's fine -- the first parameter is an object and the second is a function, and they only look the same because of Rust's pattern syntax.
1 parent bd22858 commit 0fc8f4a

File tree

3 files changed

+4
-6
lines changed

3 files changed

+4
-6
lines changed

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ manual_let_else = "warn"
107107
manual_ok_or = "warn"
108108
manual_string_new = "warn"
109109
many_single_char_names = "warn"
110-
map_unwrap_or = "allow"
110+
map_unwrap_or = "warn"
111111
match_wild_err_arm = "warn"
112112
match_wildcard_for_single_variants = "allow"
113113
maybe_infinite_iter = "warn"

src/compile.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -617,8 +617,7 @@ impl Match {
617617
.pattern()
618618
.as_variable()
619619
.cloned()
620-
.map(Pattern::Identifier)
621-
.unwrap_or(Pattern::Ignore),
620+
.map_or(Pattern::Ignore, Pattern::Identifier),
622621
);
623622
let left = self.left().expression().compile(scope)?;
624623
scope.pop_scope();
@@ -629,8 +628,7 @@ impl Match {
629628
.pattern()
630629
.as_variable()
631630
.cloned()
632-
.map(Pattern::Identifier)
633-
.unwrap_or(Pattern::Ignore),
631+
.map_or(Pattern::Ignore, Pattern::Identifier),
634632
);
635633
let right = self.right().expression().compile(scope)?;
636634
scope.pop_scope();

src/error.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ impl fmt::Display for RichError {
233233
writeln!(f, "{:width$} |", " ", width = line_num_width)?;
234234

235235
let mut lines = file.lines().skip(start_line_index).peekable();
236-
let start_line_len = lines.peek().map(|l| l.len()).unwrap_or(0);
236+
let start_line_len = lines.peek().map_or(0, |l| l.len());
237237

238238
for (relative_line_index, line_str) in lines.take(n_spanned_lines).enumerate() {
239239
let line_num = start_line_index + relative_line_index + 1;

0 commit comments

Comments
 (0)