Skip to content

Commit 9c09c1f

Browse files
committed
Auto merge of rust-lang#82552 - GuillaumeGomez:rollup-8dn1ztn, r=GuillaumeGomez
Rollup of 8 pull requests Successful merges: - rust-lang#81940 (Stabilize str_split_once) - rust-lang#82165 (Reword labels on E0308 involving async fn return type) - rust-lang#82456 (Replaced some unwrap_or and map_or with lazy variants) - rust-lang#82491 (Consider inexpensive inlining criteria first) - rust-lang#82506 (Properly account for non-shorthand pattern field in unused variable lint) - rust-lang#82535 (Set codegen thread names) - rust-lang#82545 (rustdoc: add optional woff2 versions of FiraSans.) - rust-lang#82549 (Revert "Update normalize.css to 8.0.1") Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents cecdb18 + 0da9b47 commit 9c09c1f

File tree

53 files changed

+382
-247
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+382
-247
lines changed

compiler/rustc_codegen_cranelift/src/lib.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
associated_type_bounds,
66
never_type,
77
try_blocks,
8-
hash_drain_filter,
9-
str_split_once
8+
hash_drain_filter
109
)]
1110
#![warn(rust_2018_idioms)]
1211
#![warn(unused_lifetimes)]

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(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-3
Original file line numberDiff line numberDiff line change
@@ -481,9 +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
485-
.parent
486-
.map_or(vec![], |def_id| get_parameter_names(cx, cx.tcx.generics_of(def_id)));
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+
});
487487
names.extend(generics.params.iter().map(|param| param.name));
488488
names
489489
}

compiler/rustc_codegen_llvm/src/metadata.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ fn search_meta_section<'a>(
6565
while llvm::LLVMIsSectionIteratorAtEnd(of.llof, si.llsi) == False {
6666
let mut name_buf = None;
6767
let name_len = llvm::LLVMRustGetSectionName(si.llsi, &mut name_buf);
68-
let name = name_buf.map_or(
69-
String::new(), // We got a NULL ptr, ignore `name_len`.
68+
let name = name_buf.map_or_else(
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_codegen_ssa/src/back/link.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2082,7 +2082,7 @@ fn add_upstream_rust_crates<'a, B: ArchiveBuilder<'a>>(
20822082
let filestem = cratepath.file_stem().unwrap().to_str().unwrap();
20832083
cmd.link_rust_dylib(
20842084
Symbol::intern(&unlib(&sess.target, filestem)),
2085-
parent.unwrap_or(Path::new("")),
2085+
parent.unwrap_or_else(|| Path::new("")),
20862086
);
20872087
}
20882088
}

compiler/rustc_codegen_ssa/src/back/write.rs

+77-47
Original file line numberDiff line numberDiff line change
@@ -712,6 +712,33 @@ impl<B: WriteBackendMethods> WorkItem<B> {
712712
}
713713
}
714714
}
715+
716+
/// Generate a short description of this work item suitable for use as a thread name.
717+
fn short_description(&self) -> String {
718+
// `pthread_setname()` on *nix is limited to 15 characters and longer names are ignored.
719+
// Use very short descriptions in this case to maximize the space available for the module name.
720+
// Windows does not have that limitation so use slightly more descriptive names there.
721+
match self {
722+
WorkItem::Optimize(m) => {
723+
#[cfg(windows)]
724+
return format!("optimize module {}", m.name);
725+
#[cfg(not(windows))]
726+
return format!("opt {}", m.name);
727+
}
728+
WorkItem::CopyPostLtoArtifacts(m) => {
729+
#[cfg(windows)]
730+
return format!("copy LTO artifacts for {}", m.name);
731+
#[cfg(not(windows))]
732+
return format!("copy {}", m.name);
733+
}
734+
WorkItem::LTO(m) => {
735+
#[cfg(windows)]
736+
return format!("LTO module {}", m.name());
737+
#[cfg(not(windows))]
738+
return format!("LTO {}", m.name());
739+
}
740+
}
741+
}
715742
}
716743

717744
enum WorkItemResult<B: WriteBackendMethods> {
@@ -1609,56 +1636,59 @@ fn start_executing_work<B: ExtraBackendMethods>(
16091636
pub struct WorkerFatalError;
16101637

16111638
fn spawn_work<B: ExtraBackendMethods>(cgcx: CodegenContext<B>, work: WorkItem<B>) {
1612-
thread::spawn(move || {
1613-
// Set up a destructor which will fire off a message that we're done as
1614-
// we exit.
1615-
struct Bomb<B: ExtraBackendMethods> {
1616-
coordinator_send: Sender<Box<dyn Any + Send>>,
1617-
result: Option<Result<WorkItemResult<B>, FatalError>>,
1618-
worker_id: usize,
1619-
}
1620-
impl<B: ExtraBackendMethods> Drop for Bomb<B> {
1621-
fn drop(&mut self) {
1622-
let worker_id = self.worker_id;
1623-
let msg = match self.result.take() {
1624-
Some(Ok(WorkItemResult::Compiled(m))) => {
1625-
Message::Done::<B> { result: Ok(m), worker_id }
1626-
}
1627-
Some(Ok(WorkItemResult::NeedsLink(m))) => {
1628-
Message::NeedsLink::<B> { module: m, worker_id }
1629-
}
1630-
Some(Ok(WorkItemResult::NeedsFatLTO(m))) => {
1631-
Message::NeedsFatLTO::<B> { result: m, worker_id }
1632-
}
1633-
Some(Ok(WorkItemResult::NeedsThinLTO(name, thin_buffer))) => {
1634-
Message::NeedsThinLTO::<B> { name, thin_buffer, worker_id }
1635-
}
1636-
Some(Err(FatalError)) => {
1637-
Message::Done::<B> { result: Err(Some(WorkerFatalError)), worker_id }
1638-
}
1639-
None => Message::Done::<B> { result: Err(None), worker_id },
1640-
};
1641-
drop(self.coordinator_send.send(Box::new(msg)));
1639+
let builder = thread::Builder::new().name(work.short_description());
1640+
builder
1641+
.spawn(move || {
1642+
// Set up a destructor which will fire off a message that we're done as
1643+
// we exit.
1644+
struct Bomb<B: ExtraBackendMethods> {
1645+
coordinator_send: Sender<Box<dyn Any + Send>>,
1646+
result: Option<Result<WorkItemResult<B>, FatalError>>,
1647+
worker_id: usize,
1648+
}
1649+
impl<B: ExtraBackendMethods> Drop for Bomb<B> {
1650+
fn drop(&mut self) {
1651+
let worker_id = self.worker_id;
1652+
let msg = match self.result.take() {
1653+
Some(Ok(WorkItemResult::Compiled(m))) => {
1654+
Message::Done::<B> { result: Ok(m), worker_id }
1655+
}
1656+
Some(Ok(WorkItemResult::NeedsLink(m))) => {
1657+
Message::NeedsLink::<B> { module: m, worker_id }
1658+
}
1659+
Some(Ok(WorkItemResult::NeedsFatLTO(m))) => {
1660+
Message::NeedsFatLTO::<B> { result: m, worker_id }
1661+
}
1662+
Some(Ok(WorkItemResult::NeedsThinLTO(name, thin_buffer))) => {
1663+
Message::NeedsThinLTO::<B> { name, thin_buffer, worker_id }
1664+
}
1665+
Some(Err(FatalError)) => {
1666+
Message::Done::<B> { result: Err(Some(WorkerFatalError)), worker_id }
1667+
}
1668+
None => Message::Done::<B> { result: Err(None), worker_id },
1669+
};
1670+
drop(self.coordinator_send.send(Box::new(msg)));
1671+
}
16421672
}
1643-
}
16441673

1645-
let mut bomb = Bomb::<B> {
1646-
coordinator_send: cgcx.coordinator_send.clone(),
1647-
result: None,
1648-
worker_id: cgcx.worker,
1649-
};
1674+
let mut bomb = Bomb::<B> {
1675+
coordinator_send: cgcx.coordinator_send.clone(),
1676+
result: None,
1677+
worker_id: cgcx.worker,
1678+
};
16501679

1651-
// Execute the work itself, and if it finishes successfully then flag
1652-
// ourselves as a success as well.
1653-
//
1654-
// Note that we ignore any `FatalError` coming out of `execute_work_item`,
1655-
// as a diagnostic was already sent off to the main thread - just
1656-
// surface that there was an error in this worker.
1657-
bomb.result = {
1658-
let _prof_timer = work.start_profiling(&cgcx);
1659-
Some(execute_work_item(&cgcx, work))
1660-
};
1661-
});
1680+
// Execute the work itself, and if it finishes successfully then flag
1681+
// ourselves as a success as well.
1682+
//
1683+
// Note that we ignore any `FatalError` coming out of `execute_work_item`,
1684+
// as a diagnostic was already sent off to the main thread - just
1685+
// surface that there was an error in this worker.
1686+
bomb.result = {
1687+
let _prof_timer = work.start_profiling(&cgcx);
1688+
Some(execute_work_item(&cgcx, work))
1689+
};
1690+
})
1691+
.expect("failed to spawn thread");
16621692
}
16631693

16641694
enum SharedEmitterMessage {

compiler/rustc_infer/src/infer/error_reporting/mod.rs

+11-2
Original file line numberDiff line numberDiff line change
@@ -1484,13 +1484,16 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
14841484
for (key, values) in types.iter() {
14851485
let count = values.len();
14861486
let kind = key.descr();
1487+
let mut returned_async_output_error = false;
14871488
for sp in values {
14881489
err.span_label(
14891490
*sp,
14901491
format!(
14911492
"{}{}{} {}{}",
1492-
if sp.is_desugaring(DesugaringKind::Async) {
1493-
"the `Output` of this `async fn`'s "
1493+
if sp.is_desugaring(DesugaringKind::Async)
1494+
&& !returned_async_output_error
1495+
{
1496+
"checked the `Output` of this `async fn`, "
14941497
} else if count == 1 {
14951498
"the "
14961499
} else {
@@ -1502,6 +1505,12 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
15021505
pluralize!(count),
15031506
),
15041507
);
1508+
if sp.is_desugaring(DesugaringKind::Async)
1509+
&& returned_async_output_error == false
1510+
{
1511+
err.note("while checking the return type of the `async fn`");
1512+
returned_async_output_error = true;
1513+
}
15051514
}
15061515
}
15071516
}

compiler/rustc_lint/src/non_fmt_panic.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ fn check_panic_str<'tcx>(
201201
Some(v) if v.len() == 1 => "panic message contains a brace",
202202
_ => "panic message contains braces",
203203
};
204-
cx.struct_span_lint(NON_FMT_PANIC, brace_spans.unwrap_or(vec![span]), |lint| {
204+
cx.struct_span_lint(NON_FMT_PANIC, brace_spans.unwrap_or_else(|| vec![span]), |lint| {
205205
let mut l = lint.build(msg);
206206
l.note("this message is not used as a format string, but will be in Rust 2021");
207207
if span.contains(arg.span) {

compiler/rustc_macros/src/query.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -378,14 +378,14 @@ fn add_query_description_impl(
378378
let t = &(t.0).0;
379379
quote! { #t }
380380
})
381-
.unwrap_or(quote! { _ });
381+
.unwrap_or_else(|| quote! { _ });
382382
let value = args
383383
.as_ref()
384384
.map(|t| {
385385
let t = &(t.1).0;
386386
quote! { #t }
387387
})
388-
.unwrap_or(quote! { _ });
388+
.unwrap_or_else(|| quote! { _ });
389389
// expr is a `Block`, meaning that `{ #expr }` gets expanded
390390
// to `{ { stmts... } }`, which triggers the `unused_braces` lint.
391391
quote! {
@@ -409,7 +409,7 @@ fn add_query_description_impl(
409409
};
410410

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

414414
let desc = quote! {
415415
#[allow(unused_variables)]

compiler/rustc_macros/src/session_diagnostic.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -473,9 +473,9 @@ impl<'a> SessionDiagnosticDeriveBuilder<'a> {
473473
.map(
474474
|applicability_idx| quote!(#binding.#applicability_idx),
475475
)
476-
.unwrap_or(quote!(
477-
rustc_errors::Applicability::Unspecified
478-
));
476+
.unwrap_or_else(|| {
477+
quote!(rustc_errors::Applicability::Unspecified)
478+
});
479479
return Ok((span, applicability));
480480
}
481481
throw_span_err!(

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(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_mir/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ Rust MIR: a lowered representation of Rust.
2828
#![feature(or_patterns)]
2929
#![feature(once_cell)]
3030
#![feature(control_flow_enum)]
31-
#![feature(str_split_once)]
3231
#![recursion_limit = "256"]
3332

3433
#[macro_use]

0 commit comments

Comments
 (0)