Skip to content

Commit 229d199

Browse files
committed
lazily calls some fns
1 parent e423058 commit 229d199

File tree

7 files changed

+14
-13
lines changed

7 files changed

+14
-13
lines changed

compiler/rustc_errors/src/json.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,7 @@ impl DiagnosticSpanLine {
493493
h_end: usize,
494494
) -> DiagnosticSpanLine {
495495
DiagnosticSpanLine {
496-
text: sf.get_line(index).map_or(String::new(), |l| l.into_owned()),
496+
text: sf.get_line(index).map_or_else(String::new, |l| l.into_owned()),
497497
highlight_start: h_start,
498498
highlight_end: h_end,
499499
}

compiler/rustc_middle/src/ty/instance.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -216,9 +216,10 @@ impl<'tcx> InstanceDef<'tcx> {
216216
// drops of `Option::None` before LTO. We also respect the intent of
217217
// `#[inline]` on `Drop::drop` implementations.
218218
return ty.ty_adt_def().map_or(true, |adt_def| {
219-
adt_def.destructor(tcx).map_or(adt_def.is_enum(), |dtor| {
220-
tcx.codegen_fn_attrs(dtor.did).requests_inline()
221-
})
219+
adt_def.destructor(tcx).map_or_else(
220+
|| adt_def.is_enum(),
221+
|dtor| tcx.codegen_fn_attrs(dtor.did).requests_inline(),
222+
)
222223
});
223224
}
224225
tcx.codegen_fn_attrs(self.def_id()).requests_inline()

compiler/rustc_middle/src/ty/query/on_disk_cache.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,7 @@ impl<'sess> OnDiskCache<'sess> {
525525
) {
526526
let mut current_diagnostics = self.current_diagnostics.borrow_mut();
527527

528-
let x = current_diagnostics.entry(dep_node_index).or_insert(Vec::new());
528+
let x = current_diagnostics.entry(dep_node_index).or_default();
529529

530530
x.extend(Into::<Vec<_>>::into(diagnostics));
531531
}

compiler/rustc_mir/src/borrow_check/diagnostics/outlives_suggestion.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ impl OutlivesSuggestionBuilder {
157157
debug!("Collected {:?}: {:?}", fr, outlived_fr);
158158

159159
// Add to set of constraints for final help note.
160-
self.constraints_to_add.entry(fr).or_insert(Vec::new()).push(outlived_fr);
160+
self.constraints_to_add.entry(fr).or_default().push(outlived_fr);
161161
}
162162

163163
/// Emit an intermediate note on the given `Diagnostic` if the involved regions are

compiler/rustc_resolve/src/late.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2327,7 +2327,7 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
23272327

23282328
ExprKind::Call(ref callee, ref arguments) => {
23292329
self.resolve_expr(callee, Some(expr));
2330-
let const_args = self.r.legacy_const_generic_args(callee).unwrap_or(Vec::new());
2330+
let const_args = self.r.legacy_const_generic_args(callee).unwrap_or_default();
23312331
for (idx, argument) in arguments.iter().enumerate() {
23322332
// Constant arguments need to be treated as AnonConst since
23332333
// that is how they will be later lowered to HIR.

compiler/rustc_resolve/src/late/diagnostics.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
184184
PathResult::Module(ModuleOrUniformRoot::Module(module)) => module.res(),
185185
_ => None,
186186
}
187-
.map_or(String::new(), |res| format!("{} ", res.descr()));
187+
.map_or_else(String::new, |res| format!("{} ", res.descr()));
188188
(mod_prefix, format!("`{}`", Segment::names_to_string(mod_path)))
189189
};
190190
(
@@ -1042,10 +1042,10 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
10421042
if let Some(span) = self.def_span(def_id) {
10431043
err.span_label(span, &format!("`{}` defined here", path_str));
10441044
}
1045-
let fields =
1046-
self.r.field_names.get(&def_id).map_or("/* fields */".to_string(), |fields| {
1047-
vec!["_"; fields.len()].join(", ")
1048-
});
1045+
let fields = self.r.field_names.get(&def_id).map_or_else(
1046+
|| "/* fields */".to_string(),
1047+
|fields| vec!["_"; fields.len()].join(", "),
1048+
);
10491049
err.span_suggestion(
10501050
span,
10511051
"use the tuple variant pattern syntax instead",

library/test/src/helpers/exit_code.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::process::ExitStatus;
44

55
#[cfg(not(unix))]
66
pub fn get_exit_code(status: ExitStatus) -> Result<i32, String> {
7-
status.code().ok_or("received no exit code from child process".into())
7+
status.code().ok_or_else(|| "received no exit code from child process".into())
88
}
99

1010
#[cfg(unix)]

0 commit comments

Comments
 (0)