apply clippy::or_fun_call
This commit is contained in:
@@ -317,7 +317,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
|
||||
let name = if bx.sess().fewer_names() {
|
||||
None
|
||||
} else {
|
||||
Some(match whole_local_var.or(fallback_var.clone()) {
|
||||
Some(match whole_local_var.or_else(|| fallback_var.clone()) {
|
||||
Some(var) if var.name != sym::empty => var.name.to_string(),
|
||||
_ => format!("{local:?}"),
|
||||
})
|
||||
|
||||
@@ -205,7 +205,7 @@ fn prefix_and_suffix<'tcx>(
|
||||
let mut end = String::new();
|
||||
match asm_binary_format {
|
||||
BinaryFormat::Elf => {
|
||||
let section = link_section.unwrap_or(format!(".text.{asm_name}"));
|
||||
let section = link_section.unwrap_or_else(|| format!(".text.{asm_name}"));
|
||||
|
||||
let progbits = match is_arm {
|
||||
true => "%progbits",
|
||||
@@ -239,7 +239,7 @@ fn prefix_and_suffix<'tcx>(
|
||||
}
|
||||
}
|
||||
BinaryFormat::MachO => {
|
||||
let section = link_section.unwrap_or("__TEXT,__text".to_string());
|
||||
let section = link_section.unwrap_or_else(|| "__TEXT,__text".to_string());
|
||||
writeln!(begin, ".pushsection {},regular,pure_instructions", section).unwrap();
|
||||
writeln!(begin, ".balign {align_bytes}").unwrap();
|
||||
write_linkage(&mut begin).unwrap();
|
||||
@@ -256,7 +256,7 @@ fn prefix_and_suffix<'tcx>(
|
||||
}
|
||||
}
|
||||
BinaryFormat::Coff => {
|
||||
let section = link_section.unwrap_or(format!(".text.{asm_name}"));
|
||||
let section = link_section.unwrap_or_else(|| format!(".text.{asm_name}"));
|
||||
writeln!(begin, ".pushsection {},\"xr\"", section).unwrap();
|
||||
writeln!(begin, ".balign {align_bytes}").unwrap();
|
||||
write_linkage(&mut begin).unwrap();
|
||||
@@ -273,7 +273,7 @@ fn prefix_and_suffix<'tcx>(
|
||||
}
|
||||
}
|
||||
BinaryFormat::Wasm => {
|
||||
let section = link_section.unwrap_or(format!(".text.{asm_name}"));
|
||||
let section = link_section.unwrap_or_else(|| format!(".text.{asm_name}"));
|
||||
|
||||
writeln!(begin, ".section {section},\"\",@").unwrap();
|
||||
// wasm functions cannot be aligned, so skip
|
||||
|
||||
@@ -706,7 +706,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
.sess
|
||||
.source_map()
|
||||
.span_to_snippet(lhs_expr.span)
|
||||
.unwrap_or("_".to_string()),
|
||||
.unwrap_or_else(|_| "_".to_string()),
|
||||
};
|
||||
|
||||
if op.span().can_be_used_for_suggestions() {
|
||||
|
||||
@@ -1196,7 +1196,7 @@ impl CrateError {
|
||||
.opts
|
||||
.crate_name
|
||||
.clone()
|
||||
.unwrap_or("<unknown>".to_string()),
|
||||
.unwrap_or_else(|| "<unknown>".to_string()),
|
||||
is_nightly_build: sess.is_nightly_build(),
|
||||
profiler_runtime: Symbol::intern(&sess.opts.unstable_opts.profiler_runtime),
|
||||
locator_triple: locator.triple,
|
||||
@@ -1217,7 +1217,11 @@ impl CrateError {
|
||||
crate_name,
|
||||
add_info: String::new(),
|
||||
missing_core,
|
||||
current_crate: sess.opts.crate_name.clone().unwrap_or("<unknown>".to_string()),
|
||||
current_crate: sess
|
||||
.opts
|
||||
.crate_name
|
||||
.clone()
|
||||
.unwrap_or_else(|| "<unknown>".to_string()),
|
||||
is_nightly_build: sess.is_nightly_build(),
|
||||
profiler_runtime: Symbol::intern(&sess.opts.unstable_opts.profiler_runtime),
|
||||
locator_triple: sess.opts.target_triple.clone(),
|
||||
|
||||
@@ -705,7 +705,7 @@ impl<'tcx> Collector<'tcx> {
|
||||
.map_or(import_name_type, |ord| Some(PeImportNameType::Ordinal(ord)));
|
||||
|
||||
DllImport {
|
||||
name: codegen_fn_attrs.link_name.unwrap_or(self.tcx.item_name(item)),
|
||||
name: codegen_fn_attrs.link_name.unwrap_or_else(|| self.tcx.item_name(item)),
|
||||
import_name_type,
|
||||
calling_convention,
|
||||
span,
|
||||
|
||||
@@ -1575,7 +1575,7 @@ rustc_queries! {
|
||||
query vtable_allocation(key: (Ty<'tcx>, Option<ty::ExistentialTraitRef<'tcx>>)) -> mir::interpret::AllocId {
|
||||
desc { |tcx| "vtable const allocation for <{} as {}>",
|
||||
key.0,
|
||||
key.1.map(|trait_ref| format!("{trait_ref}")).unwrap_or("_".to_owned())
|
||||
key.1.map(|trait_ref| format!("{trait_ref}")).unwrap_or_else(|| "_".to_owned())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -53,11 +53,11 @@ impl<'tcx> ExportableItemCollector<'tcx> {
|
||||
let is_pub = visibilities.is_directly_public(def_id);
|
||||
|
||||
if has_attr && !is_pub {
|
||||
let vis = visibilities.effective_vis(def_id).cloned().unwrap_or(
|
||||
let vis = visibilities.effective_vis(def_id).cloned().unwrap_or_else(|| {
|
||||
EffectiveVisibility::from_vis(Visibility::Restricted(
|
||||
self.tcx.parent_module_from_def_id(def_id).to_local_def_id(),
|
||||
)),
|
||||
);
|
||||
))
|
||||
});
|
||||
let vis = vis.at_level(Level::Direct);
|
||||
let span = self.tcx.def_span(def_id);
|
||||
|
||||
|
||||
@@ -209,10 +209,9 @@ pub fn get_or_default_sysroot() -> PathBuf {
|
||||
//
|
||||
// use `parent` twice to chop off the file name and then also the
|
||||
// directory containing the dll
|
||||
let dir = dll.parent().and_then(|p| p.parent()).ok_or(format!(
|
||||
"Could not move 2 levels upper using `parent()` on {}",
|
||||
dll.display()
|
||||
))?;
|
||||
let dir = dll.parent().and_then(|p| p.parent()).ok_or_else(|| {
|
||||
format!("Could not move 2 levels upper using `parent()` on {}", dll.display())
|
||||
})?;
|
||||
|
||||
// if `dir` points to target's dir, move up to the sysroot
|
||||
let mut sysroot_dir = if dir.ends_with(crate::config::host_tuple()) {
|
||||
@@ -265,5 +264,6 @@ pub fn get_or_default_sysroot() -> PathBuf {
|
||||
rustlib_path.exists().then_some(p)
|
||||
}
|
||||
|
||||
from_env_args_next().unwrap_or(default_from_rustc_driver_dll().expect("Failed finding sysroot"))
|
||||
from_env_args_next()
|
||||
.unwrap_or_else(|| default_from_rustc_driver_dll().expect("Failed finding sysroot"))
|
||||
}
|
||||
|
||||
@@ -891,7 +891,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
|
||||
(b'a'..=b'z')
|
||||
.map(|c| format!("'{}", c as char))
|
||||
.find(|candidate| !used_names.iter().any(|e| e.as_str() == candidate))
|
||||
.unwrap_or("'lt".to_string())
|
||||
.unwrap_or_else(|| "'lt".to_string())
|
||||
};
|
||||
|
||||
let mut visitor = LifetimeReplaceVisitor {
|
||||
|
||||
@@ -224,7 +224,7 @@ impl<'a, 'b, 'tcx> AssocTypeNormalizer<'a, 'b, 'tcx> {
|
||||
)
|
||||
.ok()
|
||||
.flatten()
|
||||
.unwrap_or(proj.to_term(infcx.tcx));
|
||||
.unwrap_or_else(|| proj.to_term(infcx.tcx));
|
||||
|
||||
PlaceholderReplacer::replace_placeholders(
|
||||
infcx,
|
||||
|
||||
@@ -896,10 +896,9 @@ fn variant_info_for_coroutine<'tcx>(
|
||||
variant_size = variant_size.max(offset + field_layout.size);
|
||||
FieldInfo {
|
||||
kind: FieldKind::CoroutineLocal,
|
||||
name: field_name.unwrap_or(Symbol::intern(&format!(
|
||||
".coroutine_field{}",
|
||||
local.as_usize()
|
||||
))),
|
||||
name: field_name.unwrap_or_else(|| {
|
||||
Symbol::intern(&format!(".coroutine_field{}", local.as_usize()))
|
||||
}),
|
||||
offset: offset.bytes(),
|
||||
size: field_layout.size.bytes(),
|
||||
align: field_layout.align.abi.bytes(),
|
||||
|
||||
@@ -2368,7 +2368,8 @@ impl<'test> TestCx<'test> {
|
||||
// Real paths into the libstd/libcore
|
||||
let rust_src_dir = &self.config.sysroot_base.join("lib/rustlib/src/rust");
|
||||
rust_src_dir.try_exists().expect(&*format!("{} should exists", rust_src_dir));
|
||||
let rust_src_dir = rust_src_dir.read_link_utf8().unwrap_or(rust_src_dir.to_path_buf());
|
||||
let rust_src_dir =
|
||||
rust_src_dir.read_link_utf8().unwrap_or_else(|_| rust_src_dir.to_path_buf());
|
||||
normalize_path(&rust_src_dir.join("library"), "$SRC_DIR_REAL");
|
||||
|
||||
// eg.
|
||||
|
||||
@@ -357,9 +357,9 @@ impl<'test> TestCx<'test> {
|
||||
// Add this line to the current subview.
|
||||
subviews
|
||||
.last_mut()
|
||||
.ok_or(format!(
|
||||
"unexpected subview line outside of a subview on line {line_num}"
|
||||
))?
|
||||
.ok_or_else(|| {
|
||||
format!("unexpected subview line outside of a subview on line {line_num}")
|
||||
})?
|
||||
.push(line);
|
||||
} else {
|
||||
// This line is not part of a subview, so sort and print any
|
||||
|
||||
Reference in New Issue
Block a user