replaced some unwrap_or with unwrap_or_else

This commit is contained in:
klensy 2021-02-23 23:56:04 +03:00
parent 446d4533e8
commit 5ff1be197e
6 changed files with 11 additions and 11 deletions

View File

@ -2082,7 +2082,7 @@ fn add_upstream_rust_crates<'a, B: ArchiveBuilder<'a>>(
let filestem = cratepath.file_stem().unwrap().to_str().unwrap();
cmd.link_rust_dylib(
Symbol::intern(&unlib(&sess.target, filestem)),
parent.unwrap_or(Path::new("")),
parent.unwrap_or_else(|| Path::new("")),
);
}
}

View File

@ -159,7 +159,7 @@ fn check_panic_str<'tcx>(
Some(v) if v.len() == 1 => "panic message contains a brace",
_ => "panic message contains braces",
};
cx.struct_span_lint(NON_FMT_PANIC, brace_spans.unwrap_or(vec![span]), |lint| {
cx.struct_span_lint(NON_FMT_PANIC, brace_spans.unwrap_or_else(|| vec![span]), |lint| {
let mut l = lint.build(msg);
l.note("this message is not used as a format string, but will be in Rust 2021");
if span.contains(arg.span) {

View File

@ -378,14 +378,14 @@ fn add_query_description_impl(
let t = &(t.0).0;
quote! { #t }
})
.unwrap_or(quote! { _ });
.unwrap_or_else(|| quote! { _ });
let value = args
.as_ref()
.map(|t| {
let t = &(t.1).0;
quote! { #t }
})
.unwrap_or(quote! { _ });
.unwrap_or_else(|| quote! { _ });
// expr is a `Block`, meaning that `{ #expr }` gets expanded
// to `{ { stmts... } }`, which triggers the `unused_braces` lint.
quote! {

View File

@ -473,9 +473,9 @@ impl<'a> SessionDiagnosticDeriveBuilder<'a> {
.map(
|applicability_idx| quote!(#binding.#applicability_idx),
)
.unwrap_or(quote!(
rustc_errors::Applicability::Unspecified
));
.unwrap_or_else(|| {
quote!(rustc_errors::Applicability::Unspecified)
});
return Ok((span, applicability));
}
throw_span_err!(

View File

@ -169,7 +169,7 @@ pub fn get_or_default_sysroot() -> PathBuf {
// Check if sysroot is found using env::args().next(), and if is not found,
// use env::current_exe() to imply sysroot.
from_env_args_next().unwrap_or(from_current_exe())
from_env_args_next().unwrap_or_else(|| from_current_exe())
}
// The name of the directory rustc expects libraries to be located.

View File

@ -348,9 +348,9 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
let min_list_wb = min_list
.iter()
.map(|captured_place| {
let locatable = captured_place.info.path_expr_id.unwrap_or(
self.tcx().hir().local_def_id_to_hir_id(closure_def_id.expect_local()),
);
let locatable = captured_place.info.path_expr_id.unwrap_or_else(|| {
self.tcx().hir().local_def_id_to_hir_id(closure_def_id.expect_local())
});
self.resolve(captured_place.clone(), &locatable)
})