Skip to content

Rollup of 8 pull requests #82550

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 19 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
c28f2a8
Stabilize str_split_once
jhpratt Feb 9, 2021
4c70372
Make ItemKind::ExternCrate looks like hir::ItemKind::ExternCrate to m…
GuillaumeGomez Feb 15, 2021
5ff1be1
replaced some unwrap_or with unwrap_or_else
klensy Feb 23, 2021
c75c4a5
replaced some map_or with map_or_else
klensy Feb 23, 2021
6d5c0c1
Consider inexpensive inlining criteria first
tmiasko Feb 24, 2021
08b1e80
fix review
klensy Feb 25, 2021
fb24a10
Properly account for non-shorthand pattern field in unused variable lint
estebank Feb 25, 2021
9d3739d
Set codegen thread names
wesleywiser Feb 18, 2021
c47903f
Add optional woff2 versions of FiraSans.
jsha Feb 26, 2021
ad7ed13
Embed woff2 files in rustdoc binary.
jsha Feb 26, 2021
b0dc39e
Revert "Update normalize.css to 8.0.1"
GuillaumeGomez Feb 26, 2021
36aa36b
Rollup merge of #80845 - GuillaumeGomez:item-kind-transition, r=jyn514
GuillaumeGomez Feb 26, 2021
99d4d41
Rollup merge of #81940 - jhpratt:stabilize-str_split_once, r=m-ou-se
GuillaumeGomez Feb 26, 2021
72aa8b1
Rollup merge of #82456 - klensy:or-else, r=estebank
GuillaumeGomez Feb 26, 2021
dd9ef93
Rollup merge of #82491 - tmiasko:i, r=lcnr
GuillaumeGomez Feb 26, 2021
c21341b
Rollup merge of #82506 - estebank:unused_variable_lint, r=lcnr
GuillaumeGomez Feb 26, 2021
0d7f5a0
Rollup merge of #82535 - wesleywiser:wip_codegen_thread_names, r=nagisa
GuillaumeGomez Feb 26, 2021
97efb53
Rollup merge of #82545 - jsha:woff2, r=GuillaumeGomez
GuillaumeGomez Feb 26, 2021
4afd98c
Rollup merge of #82549 - rust-lang:revert-82313-update-normalize-css,…
GuillaumeGomez Feb 26, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
replaced some map_or with map_or_else
  • Loading branch information
klensy committed Feb 23, 2021
commit c75c4a579bdea69fc9b93697aa2531daf82540fc
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2372,7 +2372,7 @@ fn compute_type_parameters(cx: &CodegenCx<'ll, 'tcx>, ty: Ty<'tcx>) -> &'ll DIAr
fn get_parameter_names(cx: &CodegenCx<'_, '_>, generics: &ty::Generics) -> Vec<Symbol> {
let mut names = generics
.parent
.map_or(vec![], |def_id| get_parameter_names(cx, cx.tcx.generics_of(def_id)));
.map_or_else(|| vec![], |def_id| get_parameter_names(cx, cx.tcx.generics_of(def_id)));
names.extend(generics.params.iter().map(|param| param.name));
names
}
Expand Down
7 changes: 4 additions & 3 deletions compiler/rustc_codegen_llvm/src/debuginfo/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -481,9 +481,10 @@ impl DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> {
}

fn get_parameter_names(cx: &CodegenCx<'_, '_>, generics: &ty::Generics) -> Vec<Symbol> {
let mut names = generics
.parent
.map_or(vec![], |def_id| get_parameter_names(cx, cx.tcx.generics_of(def_id)));
let mut names = generics.parent.map_or_else(
|| vec![],
|def_id| get_parameter_names(cx, cx.tcx.generics_of(def_id)),
);
names.extend(generics.params.iter().map(|param| param.name));
names
}
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_codegen_llvm/src/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ fn search_meta_section<'a>(
while llvm::LLVMIsSectionIteratorAtEnd(of.llof, si.llsi) == False {
let mut name_buf = None;
let name_len = llvm::LLVMRustGetSectionName(si.llsi, &mut name_buf);
let name = name_buf.map_or(
String::new(), // We got a NULL ptr, ignore `name_len`.
let name = name_buf.map_or_else(
|| String::new(), // We got a NULL ptr, ignore `name_len`.
|buf| {
String::from_utf8(
slice::from_raw_parts(buf.as_ptr() as *const u8, name_len as usize)
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_macros/src/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ fn add_query_description_impl(
};

let (tcx, desc) = modifiers.desc;
let tcx = tcx.as_ref().map_or(quote! { _ }, |t| quote! { #t });
let tcx = tcx.as_ref().map_or_else(|| quote! { _ }, |t| quote! { #t });

let desc = quote! {
#[allow(unused_variables)]
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_mir/src/const_eval/eval_queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ fn eval_body_using_ecx<'mir, 'tcx>(

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

ecx.push_stack_frame(
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_parse/src/parser/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ impl<'a> Parser<'a> {
fn tokens_to_string(tokens: &[TokenType]) -> String {
let mut i = tokens.iter();
// This might be a sign we need a connect method on `Iterator`.
let b = i.next().map_or(String::new(), |t| t.to_string());
let b = i.next().map_or_else(|| String::new(), |t| t.to_string());
i.enumerate().fold(b, |mut b, (i, a)| {
if tokens.len() > 2 && i == tokens.len() - 2 {
b.push_str(", or ");
Expand Down
111 changes: 57 additions & 54 deletions compiler/rustc_resolve/src/late/lifetimes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1971,65 +1971,68 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
// Therefore, we would compute `object_lifetime_defaults` to a
// vector like `['x, 'static]`. Note that the vector only
// includes type parameters.
let object_lifetime_defaults = type_def_id.map_or(vec![], |def_id| {
let in_body = {
let mut scope = self.scope;
loop {
match *scope {
Scope::Root => break false,

Scope::Body { .. } => break true,

Scope::Binder { s, .. }
| Scope::Elision { s, .. }
| Scope::ObjectLifetimeDefault { s, .. } => {
scope = s;
let object_lifetime_defaults = type_def_id.map_or_else(
|| vec![],
|def_id| {
let in_body = {
let mut scope = self.scope;
loop {
match *scope {
Scope::Root => break false,

Scope::Body { .. } => break true,

Scope::Binder { s, .. }
| Scope::Elision { s, .. }
| Scope::ObjectLifetimeDefault { s, .. } => {
scope = s;
}
}
}
}
};
};

let map = &self.map;
let unsubst = if let Some(def_id) = def_id.as_local() {
let id = self.tcx.hir().local_def_id_to_hir_id(def_id);
&map.object_lifetime_defaults[&id]
} else {
let tcx = self.tcx;
self.xcrate_object_lifetime_defaults.entry(def_id).or_insert_with(|| {
tcx.generics_of(def_id)
.params
.iter()
.filter_map(|param| match param.kind {
GenericParamDefKind::Type { object_lifetime_default, .. } => {
Some(object_lifetime_default)
let map = &self.map;
let unsubst = if let Some(def_id) = def_id.as_local() {
let id = self.tcx.hir().local_def_id_to_hir_id(def_id);
&map.object_lifetime_defaults[&id]
} else {
let tcx = self.tcx;
self.xcrate_object_lifetime_defaults.entry(def_id).or_insert_with(|| {
tcx.generics_of(def_id)
.params
.iter()
.filter_map(|param| match param.kind {
GenericParamDefKind::Type { object_lifetime_default, .. } => {
Some(object_lifetime_default)
}
GenericParamDefKind::Lifetime | GenericParamDefKind::Const => None,
})
.collect()
})
};
debug!("visit_segment_args: unsubst={:?}", unsubst);
unsubst
.iter()
.map(|set| match *set {
Set1::Empty => {
if in_body {
None
} else {
Some(Region::Static)
}
GenericParamDefKind::Lifetime | GenericParamDefKind::Const => None,
})
.collect()
})
};
debug!("visit_segment_args: unsubst={:?}", unsubst);
unsubst
.iter()
.map(|set| match *set {
Set1::Empty => {
if in_body {
None
} else {
Some(Region::Static)
}
}
Set1::One(r) => {
let lifetimes = generic_args.args.iter().filter_map(|arg| match arg {
GenericArg::Lifetime(lt) => Some(lt),
_ => None,
});
r.subst(lifetimes, map)
}
Set1::Many => None,
})
.collect()
});
Set1::One(r) => {
let lifetimes = generic_args.args.iter().filter_map(|arg| match arg {
GenericArg::Lifetime(lt) => Some(lt),
_ => None,
});
r.subst(lifetimes, map)
}
Set1::Many => None,
})
.collect()
},
);

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

Expand Down
11 changes: 8 additions & 3 deletions compiler/rustc_trait_selection/src/traits/specialize/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ fn report_negative_positive_conflict(
E0751,
"found both positive and negative implementation of trait `{}`{}:",
overlap.trait_desc,
overlap.self_desc.clone().map_or(String::new(), |ty| format!(" for type `{}`", ty))
overlap.self_desc.clone().map_or_else(|| String::new(), |ty| format!(" for type `{}`", ty))
);

match tcx.span_of_impl(negative_impl_def_id) {
Expand Down Expand Up @@ -397,7 +397,10 @@ fn report_conflicting_impls(
let msg = format!(
"conflicting implementations of trait `{}`{}:{}",
overlap.trait_desc,
overlap.self_desc.clone().map_or(String::new(), |ty| { format!(" for type `{}`", ty) }),
overlap
.self_desc
.clone()
.map_or_else(|| String::new(), |ty| { format!(" for type `{}`", ty) }),
match used_to_be_allowed {
Some(FutureCompatOverlapErrorKind::Issue33140) => " (E0119)",
_ => "",
Expand All @@ -415,7 +418,9 @@ fn report_conflicting_impls(
impl_span,
format!(
"conflicting implementation{}",
overlap.self_desc.map_or(String::new(), |ty| format!(" for `{}`", ty))
overlap
.self_desc
.map_or_else(|| String::new(), |ty| format!(" for `{}`", ty))
),
);
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_typeck/src/check/method/probe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1695,7 +1695,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
} else {
self.fcx
.associated_item(def_id, name, Namespace::ValueNS)
.map_or(Vec::new(), |x| vec![x])
.map_or_else(|| Vec::new(), |x| vec![x])
}
} else {
self.tcx.associated_items(def_id).in_definition_order().copied().collect()
Expand Down
5 changes: 4 additions & 1 deletion compiler/rustc_typeck/src/check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1062,7 +1062,10 @@ fn report_unexpected_variant_res(tcx: TyCtxt<'_>, res: Res, span: Span) {
E0533,
"expected unit struct, unit variant or constant, found {}{}",
res.descr(),
tcx.sess.source_map().span_to_snippet(span).map_or(String::new(), |s| format!(" `{}`", s)),
tcx.sess
.source_map()
.span_to_snippet(span)
.map_or_else(|_| String::new(), |s| format!(" `{}`", s)),
)
.emit();
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_typeck/src/check/pat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -879,7 +879,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let sm = tcx.sess.source_map();
let path_str = sm
.span_to_snippet(sm.span_until_char(pat.span, '('))
.map_or(String::new(), |s| format!(" `{}`", s.trim_end()));
.map_or_else(|_| String::new(), |s| format!(" `{}`", s.trim_end()));
let msg = format!(
"expected tuple struct or tuple variant, found {}{}",
res.descr(),
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_typeck/src/collect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2387,7 +2387,7 @@ fn compute_sig_of_foreign_fn_decl<'tcx>(
.sess
.source_map()
.span_to_snippet(ast_ty.span)
.map_or(String::new(), |s| format!(" `{}`", s));
.map_or_else(|_| String::new(), |s| format!(" `{}`", s));
tcx.sess
.struct_span_err(
ast_ty.span,
Expand Down