1
Fork 0

Auto merge of #55014 - ljedrz:lazyboye_unwraps, r=matthewjasper

Prefer unwrap_or_else to unwrap_or in case of function calls/allocations

The contents of `unwrap_or` are evaluated eagerly, so it's not a good pick in case of function calls and allocations. This PR also changes a few `unwrap_or`s with `unwrap_or_default`.

An added bonus is that in some cases this change also reveals if the object it's called on is an `Option` or a `Result` (based on whether the closure takes an argument).
This commit is contained in:
bors 2018-10-20 11:22:48 +00:00
commit ca2639e82e
35 changed files with 57 additions and 54 deletions

View file

@ -128,7 +128,7 @@ impl<'a> DiagnosticBuilder<'a> {
message: &str,
span: Option<S>,
) -> &mut Self {
let span = span.map(|s| s.into()).unwrap_or(MultiSpan::new());
let span = span.map(|s| s.into()).unwrap_or_else(|| MultiSpan::new());
self.diagnostic.sub(level, message, span, None);
self
}