Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 8dfdca9

Browse files
authored
Merge pull request rust-lang#3094 from otavio/avoid-unwrap-or
Replace `.unwrap_or` with `.map_or` in few places
2 parents a0d1f17 + 6d7fef0 commit 8dfdca9

File tree

4 files changed

+7
-13
lines changed

4 files changed

+7
-13
lines changed

src/bin/main.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,9 +156,7 @@ fn make_opts() -> Options {
156156
}
157157

158158
fn is_nightly() -> bool {
159-
option_env!("CFG_RELEASE_CHANNEL")
160-
.map(|c| c == "nightly" || c == "dev")
161-
.unwrap_or(false)
159+
option_env!("CFG_RELEASE_CHANNEL").map_or(false, |c| c == "nightly" || c == "dev")
162160
}
163161

164162
// Returned i32 is an exit code

src/closures.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -345,9 +345,9 @@ pub fn rewrite_last_closure(
345345

346346
// When overflowing the closure which consists of a single control flow expression,
347347
// force to use block if its condition uses multi line.
348-
let is_multi_lined_cond = rewrite_cond(context, body, body_shape)
349-
.map(|cond| cond.contains('\n') || cond.len() > body_shape.width)
350-
.unwrap_or(false);
348+
let is_multi_lined_cond = rewrite_cond(context, body, body_shape).map_or(false, |cond| {
349+
cond.contains('\n') || cond.len() > body_shape.width
350+
});
351351
if is_multi_lined_cond {
352352
return rewrite_closure_with_block(body, &prefix, context, body_shape);
353353
}

src/config/config_type.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,7 @@ impl ConfigType for IgnoreList {
7272
/// nightly compiler when installed from crates.io, default to nightly mode.
7373
macro_rules! is_nightly_channel {
7474
() => {
75-
option_env!("CFG_RELEASE_CHANNEL")
76-
.map(|c| c == "nightly" || c == "dev")
77-
.unwrap_or(true)
75+
option_env!("CFG_RELEASE_CHANNEL").map_or(true, |c| c == "nightly" || c == "dev")
7876
};
7977
}
8078

src/expr.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -273,11 +273,9 @@ pub fn format_expr(
273273

274274
format!(
275275
"{}{}{}",
276-
lhs.map(|lhs| space_if(needs_space_before_range(context, lhs)))
277-
.unwrap_or(""),
276+
lhs.map_or("", |lhs| space_if(needs_space_before_range(context, lhs))),
278277
delim,
279-
rhs.map(|rhs| space_if(needs_space_after_range(rhs)))
280-
.unwrap_or(""),
278+
rhs.map_or("", |rhs| space_if(needs_space_after_range(rhs))),
281279
)
282280
};
283281

0 commit comments

Comments
 (0)