Skip to content

Commit 08b1e80

Browse files
committed
fix review
1 parent c75c4a5 commit 08b1e80

File tree

9 files changed

+66
-72
lines changed

9 files changed

+66
-72
lines changed

compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2372,7 +2372,7 @@ fn compute_type_parameters(cx: &CodegenCx<'ll, 'tcx>, ty: Ty<'tcx>) -> &'ll DIAr
23722372
fn get_parameter_names(cx: &CodegenCx<'_, '_>, generics: &ty::Generics) -> Vec<Symbol> {
23732373
let mut names = generics
23742374
.parent
2375-
.map_or_else(|| vec![], |def_id| get_parameter_names(cx, cx.tcx.generics_of(def_id)));
2375+
.map_or_else(Vec::new, |def_id| get_parameter_names(cx, cx.tcx.generics_of(def_id)));
23762376
names.extend(generics.params.iter().map(|param| param.name));
23772377
names
23782378
}

compiler/rustc_codegen_llvm/src/debuginfo/mod.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -481,10 +481,9 @@ impl DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> {
481481
}
482482

483483
fn get_parameter_names(cx: &CodegenCx<'_, '_>, generics: &ty::Generics) -> Vec<Symbol> {
484-
let mut names = generics.parent.map_or_else(
485-
|| vec![],
486-
|def_id| get_parameter_names(cx, cx.tcx.generics_of(def_id)),
487-
);
484+
let mut names = generics.parent.map_or_else(Vec::new, |def_id| {
485+
get_parameter_names(cx, cx.tcx.generics_of(def_id))
486+
});
488487
names.extend(generics.params.iter().map(|param| param.name));
489488
names
490489
}

compiler/rustc_codegen_llvm/src/metadata.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ fn search_meta_section<'a>(
6666
let mut name_buf = None;
6767
let name_len = llvm::LLVMRustGetSectionName(si.llsi, &mut name_buf);
6868
let name = name_buf.map_or_else(
69-
|| String::new(), // We got a NULL ptr, ignore `name_len`.
69+
String::new, // We got a NULL ptr, ignore `name_len`.
7070
|buf| {
7171
String::from_utf8(
7272
slice::from_raw_parts(buf.as_ptr() as *const u8, name_len as usize)

compiler/rustc_mir/src/const_eval/eval_queries.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ fn eval_body_using_ecx<'mir, 'tcx>(
5050

5151
let name =
5252
with_no_trimmed_paths(|| ty::tls::with(|tcx| tcx.def_path_str(cid.instance.def_id())));
53-
let prom = cid.promoted.map_or_else(|| String::new(), |p| format!("::promoted[{:?}]", p));
53+
let prom = cid.promoted.map_or_else(String::new, |p| format!("::promoted[{:?}]", p));
5454
trace!("eval_body_using_ecx: pushing stack frame for global: {}{}", name, prom);
5555

5656
ecx.push_stack_frame(

compiler/rustc_parse/src/parser/diagnostics.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ impl<'a> Parser<'a> {
223223
fn tokens_to_string(tokens: &[TokenType]) -> String {
224224
let mut i = tokens.iter();
225225
// This might be a sign we need a connect method on `Iterator`.
226-
let b = i.next().map_or_else(|| String::new(), |t| t.to_string());
226+
let b = i.next().map_or_else(String::new, |t| t.to_string());
227227
i.enumerate().fold(b, |mut b, (i, a)| {
228228
if tokens.len() > 2 && i == tokens.len() - 2 {
229229
b.push_str(", or ");

compiler/rustc_resolve/src/late/lifetimes.rs

+54-57
Original file line numberDiff line numberDiff line change
@@ -1971,68 +1971,65 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
19711971
// Therefore, we would compute `object_lifetime_defaults` to a
19721972
// vector like `['x, 'static]`. Note that the vector only
19731973
// includes type parameters.
1974-
let object_lifetime_defaults = type_def_id.map_or_else(
1975-
|| vec![],
1976-
|def_id| {
1977-
let in_body = {
1978-
let mut scope = self.scope;
1979-
loop {
1980-
match *scope {
1981-
Scope::Root => break false,
1982-
1983-
Scope::Body { .. } => break true,
1984-
1985-
Scope::Binder { s, .. }
1986-
| Scope::Elision { s, .. }
1987-
| Scope::ObjectLifetimeDefault { s, .. } => {
1988-
scope = s;
1989-
}
1974+
let object_lifetime_defaults = type_def_id.map_or_else(Vec::new, |def_id| {
1975+
let in_body = {
1976+
let mut scope = self.scope;
1977+
loop {
1978+
match *scope {
1979+
Scope::Root => break false,
1980+
1981+
Scope::Body { .. } => break true,
1982+
1983+
Scope::Binder { s, .. }
1984+
| Scope::Elision { s, .. }
1985+
| Scope::ObjectLifetimeDefault { s, .. } => {
1986+
scope = s;
19901987
}
19911988
}
1992-
};
1989+
}
1990+
};
19931991

1994-
let map = &self.map;
1995-
let unsubst = if let Some(def_id) = def_id.as_local() {
1996-
let id = self.tcx.hir().local_def_id_to_hir_id(def_id);
1997-
&map.object_lifetime_defaults[&id]
1998-
} else {
1999-
let tcx = self.tcx;
2000-
self.xcrate_object_lifetime_defaults.entry(def_id).or_insert_with(|| {
2001-
tcx.generics_of(def_id)
2002-
.params
2003-
.iter()
2004-
.filter_map(|param| match param.kind {
2005-
GenericParamDefKind::Type { object_lifetime_default, .. } => {
2006-
Some(object_lifetime_default)
2007-
}
2008-
GenericParamDefKind::Lifetime | GenericParamDefKind::Const => None,
2009-
})
2010-
.collect()
2011-
})
2012-
};
2013-
debug!("visit_segment_args: unsubst={:?}", unsubst);
2014-
unsubst
2015-
.iter()
2016-
.map(|set| match *set {
2017-
Set1::Empty => {
2018-
if in_body {
2019-
None
2020-
} else {
2021-
Some(Region::Static)
1992+
let map = &self.map;
1993+
let unsubst = if let Some(def_id) = def_id.as_local() {
1994+
let id = self.tcx.hir().local_def_id_to_hir_id(def_id);
1995+
&map.object_lifetime_defaults[&id]
1996+
} else {
1997+
let tcx = self.tcx;
1998+
self.xcrate_object_lifetime_defaults.entry(def_id).or_insert_with(|| {
1999+
tcx.generics_of(def_id)
2000+
.params
2001+
.iter()
2002+
.filter_map(|param| match param.kind {
2003+
GenericParamDefKind::Type { object_lifetime_default, .. } => {
2004+
Some(object_lifetime_default)
20222005
}
2006+
GenericParamDefKind::Lifetime | GenericParamDefKind::Const => None,
2007+
})
2008+
.collect()
2009+
})
2010+
};
2011+
debug!("visit_segment_args: unsubst={:?}", unsubst);
2012+
unsubst
2013+
.iter()
2014+
.map(|set| match *set {
2015+
Set1::Empty => {
2016+
if in_body {
2017+
None
2018+
} else {
2019+
Some(Region::Static)
20232020
}
2024-
Set1::One(r) => {
2025-
let lifetimes = generic_args.args.iter().filter_map(|arg| match arg {
2026-
GenericArg::Lifetime(lt) => Some(lt),
2027-
_ => None,
2028-
});
2029-
r.subst(lifetimes, map)
2030-
}
2031-
Set1::Many => None,
2032-
})
2033-
.collect()
2034-
},
2035-
);
2021+
}
2022+
Set1::One(r) => {
2023+
let lifetimes = generic_args.args.iter().filter_map(|arg| match arg {
2024+
GenericArg::Lifetime(lt) => Some(lt),
2025+
_ => None,
2026+
});
2027+
r.subst(lifetimes, map)
2028+
}
2029+
Set1::Many => None,
2030+
})
2031+
.collect()
2032+
});
20362033

20372034
debug!("visit_segment_args: object_lifetime_defaults={:?}", object_lifetime_defaults);
20382035

compiler/rustc_session/src/filesearch.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ pub fn get_or_default_sysroot() -> PathBuf {
169169

170170
// Check if sysroot is found using env::args().next(), and if is not found,
171171
// use env::current_exe() to imply sysroot.
172-
from_env_args_next().unwrap_or_else(|| from_current_exe())
172+
from_env_args_next().unwrap_or_else(from_current_exe)
173173
}
174174

175175
// The name of the directory rustc expects libraries to be located.

compiler/rustc_trait_selection/src/traits/specialize/mod.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ fn report_negative_positive_conflict(
349349
E0751,
350350
"found both positive and negative implementation of trait `{}`{}:",
351351
overlap.trait_desc,
352-
overlap.self_desc.clone().map_or_else(|| String::new(), |ty| format!(" for type `{}`", ty))
352+
overlap.self_desc.clone().map_or_else(String::new, |ty| format!(" for type `{}`", ty))
353353
);
354354

355355
match tcx.span_of_impl(negative_impl_def_id) {
@@ -400,7 +400,7 @@ fn report_conflicting_impls(
400400
overlap
401401
.self_desc
402402
.clone()
403-
.map_or_else(|| String::new(), |ty| { format!(" for type `{}`", ty) }),
403+
.map_or_else(String::new, |ty| { format!(" for type `{}`", ty) }),
404404
match used_to_be_allowed {
405405
Some(FutureCompatOverlapErrorKind::Issue33140) => " (E0119)",
406406
_ => "",
@@ -418,9 +418,7 @@ fn report_conflicting_impls(
418418
impl_span,
419419
format!(
420420
"conflicting implementation{}",
421-
overlap
422-
.self_desc
423-
.map_or_else(|| String::new(), |ty| format!(" for `{}`", ty))
421+
overlap.self_desc.map_or_else(String::new, |ty| format!(" for `{}`", ty))
424422
),
425423
);
426424
}

compiler/rustc_typeck/src/check/method/probe.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1695,7 +1695,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
16951695
} else {
16961696
self.fcx
16971697
.associated_item(def_id, name, Namespace::ValueNS)
1698-
.map_or_else(|| Vec::new(), |x| vec![x])
1698+
.map_or_else(Vec::new, |x| vec![x])
16991699
}
17001700
} else {
17011701
self.tcx.associated_items(def_id).in_definition_order().copied().collect()

0 commit comments

Comments
 (0)