Merge pull request #3094 from otavio/avoid-unwrap-or

Replace `.unwrap_or` with `.map_or` in few places
This commit is contained in:
Seiichi Uchida 2018-10-14 21:02:39 +09:00 committed by GitHub
commit 8dfdca9390
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 7 additions and 13 deletions

View File

@ -156,9 +156,7 @@ fn make_opts() -> Options {
} }
fn is_nightly() -> bool { fn is_nightly() -> bool {
option_env!("CFG_RELEASE_CHANNEL") option_env!("CFG_RELEASE_CHANNEL").map_or(false, |c| c == "nightly" || c == "dev")
.map(|c| c == "nightly" || c == "dev")
.unwrap_or(false)
} }
// Returned i32 is an exit code // Returned i32 is an exit code

View File

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

View File

@ -72,9 +72,7 @@ impl ConfigType for IgnoreList {
/// nightly compiler when installed from crates.io, default to nightly mode. /// nightly compiler when installed from crates.io, default to nightly mode.
macro_rules! is_nightly_channel { macro_rules! is_nightly_channel {
() => { () => {
option_env!("CFG_RELEASE_CHANNEL") option_env!("CFG_RELEASE_CHANNEL").map_or(true, |c| c == "nightly" || c == "dev")
.map(|c| c == "nightly" || c == "dev")
.unwrap_or(true)
}; };
} }

View File

@ -273,11 +273,9 @@ pub fn format_expr(
format!( format!(
"{}{}{}", "{}{}{}",
lhs.map(|lhs| space_if(needs_space_before_range(context, lhs))) lhs.map_or("", |lhs| space_if(needs_space_before_range(context, lhs))),
.unwrap_or(""),
delim, delim,
rhs.map(|rhs| space_if(needs_space_after_range(rhs))) rhs.map_or("", |rhs| space_if(needs_space_after_range(rhs))),
.unwrap_or(""),
) )
}; };