Skip to content

Commit 5ff1be1

Browse files
committed
replaced some unwrap_or with unwrap_or_else
1 parent 446d453 commit 5ff1be1

File tree

6 files changed

+11
-11
lines changed

6 files changed

+11
-11
lines changed

compiler/rustc_codegen_ssa/src/back/link.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2082,7 +2082,7 @@ fn add_upstream_rust_crates<'a, B: ArchiveBuilder<'a>>(
20822082
let filestem = cratepath.file_stem().unwrap().to_str().unwrap();
20832083
cmd.link_rust_dylib(
20842084
Symbol::intern(&unlib(&sess.target, filestem)),
2085-
parent.unwrap_or(Path::new("")),
2085+
parent.unwrap_or_else(|| Path::new("")),
20862086
);
20872087
}
20882088
}

compiler/rustc_lint/src/non_fmt_panic.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ fn check_panic_str<'tcx>(
159159
Some(v) if v.len() == 1 => "panic message contains a brace",
160160
_ => "panic message contains braces",
161161
};
162-
cx.struct_span_lint(NON_FMT_PANIC, brace_spans.unwrap_or(vec![span]), |lint| {
162+
cx.struct_span_lint(NON_FMT_PANIC, brace_spans.unwrap_or_else(|| vec![span]), |lint| {
163163
let mut l = lint.build(msg);
164164
l.note("this message is not used as a format string, but will be in Rust 2021");
165165
if span.contains(arg.span) {

compiler/rustc_macros/src/query.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -378,14 +378,14 @@ fn add_query_description_impl(
378378
let t = &(t.0).0;
379379
quote! { #t }
380380
})
381-
.unwrap_or(quote! { _ });
381+
.unwrap_or_else(|| quote! { _ });
382382
let value = args
383383
.as_ref()
384384
.map(|t| {
385385
let t = &(t.1).0;
386386
quote! { #t }
387387
})
388-
.unwrap_or(quote! { _ });
388+
.unwrap_or_else(|| quote! { _ });
389389
// expr is a `Block`, meaning that `{ #expr }` gets expanded
390390
// to `{ { stmts... } }`, which triggers the `unused_braces` lint.
391391
quote! {

compiler/rustc_macros/src/session_diagnostic.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -473,9 +473,9 @@ impl<'a> SessionDiagnosticDeriveBuilder<'a> {
473473
.map(
474474
|applicability_idx| quote!(#binding.#applicability_idx),
475475
)
476-
.unwrap_or(quote!(
477-
rustc_errors::Applicability::Unspecified
478-
));
476+
.unwrap_or_else(|| {
477+
quote!(rustc_errors::Applicability::Unspecified)
478+
});
479479
return Ok((span, applicability));
480480
}
481481
throw_span_err!(

compiler/rustc_session/src/filesearch.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ pub fn get_or_default_sysroot() -> PathBuf {
169169

170170
// Check if sysroot is found using env::args().next(), and if is not found,
171171
// use env::current_exe() to imply sysroot.
172-
from_env_args_next().unwrap_or(from_current_exe())
172+
from_env_args_next().unwrap_or_else(|| from_current_exe())
173173
}
174174

175175
// The name of the directory rustc expects libraries to be located.

compiler/rustc_typeck/src/check/writeback.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -348,9 +348,9 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
348348
let min_list_wb = min_list
349349
.iter()
350350
.map(|captured_place| {
351-
let locatable = captured_place.info.path_expr_id.unwrap_or(
352-
self.tcx().hir().local_def_id_to_hir_id(closure_def_id.expect_local()),
353-
);
351+
let locatable = captured_place.info.path_expr_id.unwrap_or_else(|| {
352+
self.tcx().hir().local_def_id_to_hir_id(closure_def_id.expect_local())
353+
});
354354

355355
self.resolve(captured_place.clone(), &locatable)
356356
})

0 commit comments

Comments
 (0)