未验证 提交 fa70398d 编写于 作者: Y Yuki Okushi 提交者: GitHub

Rollup merge of #83526 - klensy:lazy-too, r=petrochenkov

lazily calls some fns

Replaced some fn's with it's lazy variants.
......@@ -493,7 +493,7 @@ fn line_from_source_file(
h_end: usize,
) -> DiagnosticSpanLine {
DiagnosticSpanLine {
text: sf.get_line(index).map_or(String::new(), |l| l.into_owned()),
text: sf.get_line(index).map_or_else(String::new, |l| l.into_owned()),
highlight_start: h_start,
highlight_end: h_end,
}
......
......@@ -216,9 +216,10 @@ pub fn generates_cgu_internal_copy(&self, tcx: TyCtxt<'tcx>) -> bool {
// drops of `Option::None` before LTO. We also respect the intent of
// `#[inline]` on `Drop::drop` implementations.
return ty.ty_adt_def().map_or(true, |adt_def| {
adt_def.destructor(tcx).map_or(adt_def.is_enum(), |dtor| {
tcx.codegen_fn_attrs(dtor.did).requests_inline()
})
adt_def.destructor(tcx).map_or_else(
|| adt_def.is_enum(),
|dtor| tcx.codegen_fn_attrs(dtor.did).requests_inline(),
)
});
}
tcx.codegen_fn_attrs(self.def_id()).requests_inline()
......
......@@ -525,7 +525,7 @@ pub fn store_diagnostics_for_anon_node(
) {
let mut current_diagnostics = self.current_diagnostics.borrow_mut();
let x = current_diagnostics.entry(dep_node_index).or_insert(Vec::new());
let x = current_diagnostics.entry(dep_node_index).or_default();
x.extend(Into::<Vec<_>>::into(diagnostics));
}
......
......@@ -157,7 +157,7 @@ fn compile_all_suggestions(
debug!("Collected {:?}: {:?}", fr, outlived_fr);
// Add to set of constraints for final help note.
self.constraints_to_add.entry(fr).or_insert(Vec::new()).push(outlived_fr);
self.constraints_to_add.entry(fr).or_default().push(outlived_fr);
}
/// Emit an intermediate note on the given `Diagnostic` if the involved regions are
......
......@@ -2327,7 +2327,7 @@ fn resolve_expr(&mut self, expr: &'ast Expr, parent: Option<&'ast Expr>) {
ExprKind::Call(ref callee, ref arguments) => {
self.resolve_expr(callee, Some(expr));
let const_args = self.r.legacy_const_generic_args(callee).unwrap_or(Vec::new());
let const_args = self.r.legacy_const_generic_args(callee).unwrap_or_default();
for (idx, argument) in arguments.iter().enumerate() {
// Constant arguments need to be treated as AnonConst since
// that is how they will be later lowered to HIR.
......
......@@ -184,7 +184,7 @@ pub(crate) fn smart_resolve_report_errors(
PathResult::Module(ModuleOrUniformRoot::Module(module)) => module.res(),
_ => None,
}
.map_or(String::new(), |res| format!("{} ", res.descr()));
.map_or_else(String::new, |res| format!("{} ", res.descr()));
(mod_prefix, format!("`{}`", Segment::names_to_string(mod_path)))
};
(
......@@ -1042,10 +1042,10 @@ fn smart_resolve_context_dependent_help(
if let Some(span) = self.def_span(def_id) {
err.span_label(span, &format!("`{}` defined here", path_str));
}
let fields =
self.r.field_names.get(&def_id).map_or("/* fields */".to_string(), |fields| {
vec!["_"; fields.len()].join(", ")
});
let fields = self.r.field_names.get(&def_id).map_or_else(
|| "/* fields */".to_string(),
|fields| vec!["_"; fields.len()].join(", "),
);
err.span_suggestion(
span,
"use the tuple variant pattern syntax instead",
......
......@@ -4,7 +4,7 @@
#[cfg(not(unix))]
pub fn get_exit_code(status: ExitStatus) -> Result<i32, String> {
status.code().ok_or("received no exit code from child process".into())
status.code().ok_or_else(|| "received no exit code from child process".into())
}
#[cfg(unix)]
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册