From 5ff1be197eaa8a014718b26b1fcbe0ced33b6e1a Mon Sep 17 00:00:00 2001 From: klensy Date: Tue, 23 Feb 2021 23:56:04 +0300 Subject: [PATCH] replaced some unwrap_or with unwrap_or_else --- compiler/rustc_codegen_ssa/src/back/link.rs | 2 +- compiler/rustc_lint/src/non_fmt_panic.rs | 2 +- compiler/rustc_macros/src/query.rs | 4 ++-- compiler/rustc_macros/src/session_diagnostic.rs | 6 +++--- compiler/rustc_session/src/filesearch.rs | 2 +- compiler/rustc_typeck/src/check/writeback.rs | 6 +++--- 6 files changed, 11 insertions(+), 11 deletions(-) diff --git a/compiler/rustc_codegen_ssa/src/back/link.rs b/compiler/rustc_codegen_ssa/src/back/link.rs index b93a579df15..531edd28c23 100644 --- a/compiler/rustc_codegen_ssa/src/back/link.rs +++ b/compiler/rustc_codegen_ssa/src/back/link.rs @@ -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("")), ); } } diff --git a/compiler/rustc_lint/src/non_fmt_panic.rs b/compiler/rustc_lint/src/non_fmt_panic.rs index e98297b692c..1a6d968cdb5 100644 --- a/compiler/rustc_lint/src/non_fmt_panic.rs +++ b/compiler/rustc_lint/src/non_fmt_panic.rs @@ -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) { diff --git a/compiler/rustc_macros/src/query.rs b/compiler/rustc_macros/src/query.rs index 3e67525567f..763f13d17ef 100644 --- a/compiler/rustc_macros/src/query.rs +++ b/compiler/rustc_macros/src/query.rs @@ -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! { diff --git a/compiler/rustc_macros/src/session_diagnostic.rs b/compiler/rustc_macros/src/session_diagnostic.rs index 5c061a9d3c7..8a0fce209b7 100644 --- a/compiler/rustc_macros/src/session_diagnostic.rs +++ b/compiler/rustc_macros/src/session_diagnostic.rs @@ -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!( diff --git a/compiler/rustc_session/src/filesearch.rs b/compiler/rustc_session/src/filesearch.rs index 47f14fa6b7a..72daf666c99 100644 --- a/compiler/rustc_session/src/filesearch.rs +++ b/compiler/rustc_session/src/filesearch.rs @@ -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. diff --git a/compiler/rustc_typeck/src/check/writeback.rs b/compiler/rustc_typeck/src/check/writeback.rs index 4f785982150..af82a3bb4f5 100644 --- a/compiler/rustc_typeck/src/check/writeback.rs +++ b/compiler/rustc_typeck/src/check/writeback.rs @@ -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) })