Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 6d1bf73

Browse files
committed
Auto merge of rust-lang#111778 - Dylan-DPC:rollup-107ig9h, r=Dylan-DPC
Rollup of 10 pull requests Successful merges: - rust-lang#111491 (Dont check `must_use` on nested `impl Future` from fn) - rust-lang#111606 (very minor cleanups) - rust-lang#111619 (Add timings for MIR passes to profiling report) - rust-lang#111652 (Better diagnostic for `use Self::..`) - rust-lang#111665 (Add more tests for the offset_of macro) - rust-lang#111708 (Give a more useful location for where a span_bug was delayed) - rust-lang#111715 (Fix doc comment for `ConstParamTy` derive) - rust-lang#111723 (style: do not overwrite obligations) - rust-lang#111743 (Improve cgu merging debug output) - rust-lang#111762 (fix: emit error when fragment is `MethodReceiverExpr` and items is empty) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 25f084d + 94ca44a commit 6d1bf73

File tree

31 files changed

+461
-54
lines changed

31 files changed

+461
-54
lines changed

compiler/rustc_driver_impl/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1250,7 +1250,8 @@ pub fn install_ice_hook(bug_report_url: &'static str, extra_info: fn(&Handler))
12501250
#[cfg(windows)]
12511251
if let Some(msg) = info.payload().downcast_ref::<String>() {
12521252
if msg.starts_with("failed printing to stdout: ") && msg.ends_with("(os error 232)") {
1253-
early_error_no_abort(ErrorOutputType::default(), msg.as_str());
1253+
// the error code is already going to be reported when the panic unwinds up the stack
1254+
let _ = early_error_no_abort(ErrorOutputType::default(), msg.as_str());
12541255
return;
12551256
}
12561257
};

compiler/rustc_errors/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1740,7 +1740,7 @@ impl DelayedDiagnostic {
17401740
}
17411741

17421742
fn decorate(mut self) -> Diagnostic {
1743-
self.inner.note(format!("delayed at {}", self.note));
1743+
self.inner.note(format!("delayed at {}\n{}", self.inner.emitted_at, self.note));
17441744
self.inner
17451745
}
17461746
}

compiler/rustc_expand/src/expand.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -722,7 +722,11 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
722722
});
723723
}
724724
};
725-
if fragment_kind == AstFragmentKind::Expr && items.is_empty() {
725+
if matches!(
726+
fragment_kind,
727+
AstFragmentKind::Expr | AstFragmentKind::MethodReceiverExpr
728+
) && items.is_empty()
729+
{
726730
self.cx.emit_err(RemoveExprNotSupported { span });
727731
fragment_kind.dummy(span)
728732
} else {

compiler/rustc_infer/src/infer/opaque_types.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -530,19 +530,18 @@ impl<'tcx> InferCtxt<'tcx> {
530530
// these are the same span, but not in cases like `-> (impl
531531
// Foo, impl Bar)`.
532532
let span = cause.span;
533-
534-
let mut obligations = vec![];
535533
let prev = self.inner.borrow_mut().opaque_types().register(
536534
OpaqueTypeKey { def_id, substs },
537535
OpaqueHiddenType { ty: hidden_ty, span },
538536
origin,
539537
);
540-
if let Some(prev) = prev {
541-
obligations = self
542-
.at(&cause, param_env)
538+
let mut obligations = if let Some(prev) = prev {
539+
self.at(&cause, param_env)
543540
.eq_exp(DefineOpaqueTypes::Yes, a_is_expected, prev, hidden_ty)?
544-
.obligations;
545-
}
541+
.obligations
542+
} else {
543+
Vec::new()
544+
};
546545

547546
let item_bounds = tcx.explicit_item_bounds(def_id);
548547

compiler/rustc_lint/src/unused.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,10 @@ impl<'tcx> LateLintPass<'tcx> for UnusedResults {
103103
&& let ty = cx.typeck_results().expr_ty(&await_expr)
104104
&& let ty::Alias(ty::Opaque, ty::AliasTy { def_id: future_def_id, .. }) = ty.kind()
105105
&& cx.tcx.ty_is_opaque_future(ty)
106-
// FIXME: This also includes non-async fns that return `impl Future`.
107106
&& let async_fn_def_id = cx.tcx.parent(*future_def_id)
107+
&& matches!(cx.tcx.def_kind(async_fn_def_id), DefKind::Fn | DefKind::AssocFn)
108+
// Check that this `impl Future` actually comes from an `async fn`
109+
&& cx.tcx.asyncness(async_fn_def_id).is_async()
108110
&& check_must_use_def(
109111
cx,
110112
async_fn_def_id,

compiler/rustc_middle/src/mir/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ impl<'tcx> HasLocalDecls<'tcx> for Body<'tcx> {
101101
/// pass will be named after the type, and it will consist of a main
102102
/// loop that goes over each available MIR and applies `run_pass`.
103103
pub trait MirPass<'tcx> {
104-
fn name(&self) -> &str {
104+
fn name(&self) -> &'static str {
105105
let name = std::any::type_name::<Self>();
106106
if let Some((_, tail)) = name.rsplit_once(':') { tail } else { name }
107107
}

compiler/rustc_mir_transform/src/dump_mir.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use rustc_session::config::OutputType;
1212
pub struct Marker(pub &'static str);
1313

1414
impl<'tcx> MirPass<'tcx> for Marker {
15-
fn name(&self) -> &str {
15+
fn name(&self) -> &'static str {
1616
self.0
1717
}
1818

compiler/rustc_mir_transform/src/pass_manager.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use crate::{validate, MirPass};
66

77
/// Just like `MirPass`, except it cannot mutate `Body`.
88
pub trait MirLint<'tcx> {
9-
fn name(&self) -> &str {
9+
fn name(&self) -> &'static str {
1010
let name = std::any::type_name::<Self>();
1111
if let Some((_, tail)) = name.rsplit_once(':') { tail } else { name }
1212
}
@@ -26,7 +26,7 @@ impl<'tcx, T> MirPass<'tcx> for Lint<T>
2626
where
2727
T: MirLint<'tcx>,
2828
{
29-
fn name(&self) -> &str {
29+
fn name(&self) -> &'static str {
3030
self.0.name()
3131
}
3232

@@ -49,7 +49,7 @@ impl<'tcx, T> MirPass<'tcx> for WithMinOptLevel<T>
4949
where
5050
T: MirPass<'tcx>,
5151
{
52-
fn name(&self) -> &str {
52+
fn name(&self) -> &'static str {
5353
self.1.name()
5454
}
5555

@@ -121,7 +121,7 @@ fn run_passes_inner<'tcx>(
121121
validate_body(tcx, body, format!("before pass {}", name));
122122
}
123123

124-
pass.run_pass(tcx, body);
124+
tcx.sess.time(name, || pass.run_pass(tcx, body));
125125

126126
if dump_enabled {
127127
dump_mir_for_pass(tcx, body, &name, true);

compiler/rustc_mir_transform/src/simplify.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ pub fn simplify_cfg<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
7474
}
7575

7676
impl<'tcx> MirPass<'tcx> for SimplifyCfg {
77-
fn name(&self) -> &str {
77+
fn name(&self) -> &'static str {
7878
&self.name()
7979
}
8080

compiler/rustc_monomorphize/src/partitioning/mod.rs

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -250,13 +250,13 @@ where
250250
cgu.create_size_estimate(tcx);
251251
}
252252

253-
debug_dump(tcx, "INITIAL PARTITIONING:", initial_partitioning.codegen_units.iter());
253+
debug_dump(tcx, "INITIAL PARTITIONING", &initial_partitioning.codegen_units);
254254

255255
// Merge until we have at most `max_cgu_count` codegen units.
256256
{
257257
let _prof_timer = tcx.prof.generic_activity("cgu_partitioning_merge_cgus");
258258
partitioner.merge_codegen_units(cx, &mut initial_partitioning);
259-
debug_dump(tcx, "POST MERGING:", initial_partitioning.codegen_units.iter());
259+
debug_dump(tcx, "POST MERGING", &initial_partitioning.codegen_units);
260260
}
261261

262262
// In the next step, we use the inlining map to determine which additional
@@ -272,7 +272,7 @@ where
272272
cgu.create_size_estimate(tcx);
273273
}
274274

275-
debug_dump(tcx, "POST INLINING:", post_inlining.codegen_units.iter());
275+
debug_dump(tcx, "POST INLINING", &post_inlining.codegen_units);
276276

277277
// Next we try to make as many symbols "internal" as possible, so LLVM has
278278
// more freedom to optimize.
@@ -322,6 +322,8 @@ where
322322

323323
result.sort_by(|a, b| a.name().as_str().cmp(b.name().as_str()));
324324

325+
debug_dump(tcx, "FINAL", &result);
326+
325327
result
326328
}
327329

@@ -346,33 +348,37 @@ struct PostInliningPartitioning<'tcx> {
346348
internalization_candidates: FxHashSet<MonoItem<'tcx>>,
347349
}
348350

349-
fn debug_dump<'a, 'tcx, I>(tcx: TyCtxt<'tcx>, label: &str, cgus: I)
350-
where
351-
I: Iterator<Item = &'a CodegenUnit<'tcx>>,
352-
'tcx: 'a,
353-
{
351+
fn debug_dump<'a, 'tcx: 'a>(tcx: TyCtxt<'tcx>, label: &str, cgus: &[CodegenUnit<'tcx>]) {
354352
let dump = move || {
355353
use std::fmt::Write;
356354

355+
let num_cgus = cgus.len();
356+
let max = cgus.iter().map(|cgu| cgu.size_estimate()).max().unwrap();
357+
let min = cgus.iter().map(|cgu| cgu.size_estimate()).min().unwrap();
358+
let ratio = max as f64 / min as f64;
359+
357360
let s = &mut String::new();
358-
let _ = writeln!(s, "{label}");
361+
let _ = writeln!(
362+
s,
363+
"{label} ({num_cgus} CodegenUnits, max={max}, min={min}, max/min={ratio:.1}):"
364+
);
359365
for cgu in cgus {
360366
let _ =
361-
writeln!(s, "CodegenUnit {} estimated size {} :", cgu.name(), cgu.size_estimate());
367+
writeln!(s, "CodegenUnit {} estimated size {}:", cgu.name(), cgu.size_estimate());
362368

363369
for (mono_item, linkage) in cgu.items() {
364370
let symbol_name = mono_item.symbol_name(tcx).name;
365371
let symbol_hash_start = symbol_name.rfind('h');
366372
let symbol_hash = symbol_hash_start.map_or("<no hash>", |i| &symbol_name[i..]);
367373

368-
let _ = writeln!(
374+
let _ = with_no_trimmed_paths!(writeln!(
369375
s,
370376
" - {} [{:?}] [{}] estimated size {}",
371377
mono_item,
372378
linkage,
373379
symbol_hash,
374380
mono_item.size_estimate(tcx)
375-
);
381+
));
376382
}
377383

378384
let _ = writeln!(s);

0 commit comments

Comments
 (0)