Skip to content

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

+2-1
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

+1-1
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

+5-1
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

+6-7
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

+3-1
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

+1-1
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

+1-1
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

+4-4
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

+1-1
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

+18-12
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);

compiler/rustc_parse/src/parser/diagnostics.rs

+1
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ impl<'a> DerefMut for SnapshotParser<'a> {
238238

239239
impl<'a> Parser<'a> {
240240
#[rustc_lint_diagnostics]
241+
#[track_caller]
241242
pub fn struct_span_err<S: Into<MultiSpan>>(
242243
&self,
243244
sp: S,

compiler/rustc_resolve/src/diagnostics.rs

+11-1
Original file line numberDiff line numberDiff line change
@@ -1832,7 +1832,17 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
18321832
}
18331833
(msg, None)
18341834
} else if ident.name == kw::SelfUpper {
1835-
("`Self` is only available in impls, traits, and type definitions".to_string(), None)
1835+
// As mentioned above, `opt_ns` being `None` indicates a module path in import.
1836+
// We can use this to improve a confusing error for, e.g. `use Self::Variant` in an
1837+
// impl
1838+
if opt_ns.is_none() {
1839+
("`Self` cannot be used in imports".to_string(), None)
1840+
} else {
1841+
(
1842+
"`Self` is only available in impls, traits, and type definitions".to_string(),
1843+
None,
1844+
)
1845+
}
18361846
} else if ident.name.as_str().chars().next().map_or(false, |c| c.is_ascii_uppercase()) {
18371847
// Check whether the name refers to an item in the value namespace.
18381848
let binding = if let Some(ribs) = ribs {

compiler/rustc_session/src/session.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1732,6 +1732,7 @@ fn early_error_handler(output: config::ErrorOutputType) -> rustc_errors::Handler
17321732

17331733
#[allow(rustc::untranslatable_diagnostic)]
17341734
#[allow(rustc::diagnostic_outside_of_impl)]
1735+
#[must_use = "ErrorGuaranteed must be returned from `run_compiler` in order to exit with a non-zero status code"]
17351736
pub fn early_error_no_abort(
17361737
output: config::ErrorOutputType,
17371738
msg: impl Into<DiagnosticMessage>,

library/core/src/marker.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -986,7 +986,7 @@ pub trait PointerLike {}
986986
#[rustc_on_unimplemented(message = "`{Self}` can't be used as a const parameter type")]
987987
pub trait ConstParamTy: StructuralEq {}
988988

989-
/// Derive macro generating an impl of the trait `Copy`.
989+
/// Derive macro generating an impl of the trait `ConstParamTy`.
990990
#[rustc_builtin_macro]
991991
#[unstable(feature = "adt_const_params", issue = "95174")]
992992
#[cfg(not(bootstrap))]

library/core/tests/mem.rs

+15
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,21 @@ fn offset_of() {
386386
// Layout of tuples is unstable
387387
assert!(offset_of!((u8, u16), 0) <= size_of::<(u8, u16)>() - 1);
388388
assert!(offset_of!((u8, u16), 1) <= size_of::<(u8, u16)>() - 2);
389+
390+
#[repr(C)]
391+
struct Generic<T> {
392+
x: u8,
393+
y: u32,
394+
z: T
395+
}
396+
397+
// Ensure that this type of generics works
398+
fn offs_of_z<T>() -> usize {
399+
offset_of!(Generic<T>, z)
400+
}
401+
402+
assert_eq!(offset_of!(Generic<u8>, z), 8);
403+
assert_eq!(offs_of_z::<u8>(), 8);
389404
}
390405

391406
#[test]

src/bootstrap/builder.rs

-1
Original file line numberDiff line numberDiff line change
@@ -942,7 +942,6 @@ impl<'a> Builder<'a> {
942942
self.run_step_descriptions(&Builder::get_step_descriptions(Kind::Doc), paths);
943943
}
944944

945-
/// NOTE: keep this in sync with `rustdoc::clean::utils::doc_rust_lang_org_channel`, or tests will fail on beta/stable.
946945
pub fn doc_rust_lang_org_channel(&self) -> String {
947946
let channel = match &*self.config.channel {
948947
"stable" => &self.version,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// edition:2021
2+
3+
use std::future::Future;
4+
5+
pub struct Manager;
6+
7+
impl Manager {
8+
#[must_use]
9+
pub async fn new() -> (Self, impl Future<Output = ()>) {
10+
(Manager, async {})
11+
}
12+
}
+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// edition:2021
2+
// aux-build:must-use-foreign.rs
3+
// check-pass
4+
5+
extern crate must_use_foreign;
6+
7+
use must_use_foreign::Manager;
8+
9+
async fn async_main() {
10+
Manager::new().await.1.await;
11+
}
12+
13+
fn main() {
14+
let _ = async_main();
15+
}

tests/ui/lint/unused/unused-async.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ async fn test() {
3333
foo().await; //~ ERROR unused output of future returned by `foo` that must be used
3434
bar(); //~ ERROR unused return value of `bar` that must be used
3535
//~^ ERROR unused implementer of `Future` that must be used
36-
bar().await; //~ ERROR unused output of future returned by `bar` that must be used
36+
bar().await; // ok, it's not an async fn
3737
baz(); //~ ERROR unused implementer of `Future` that must be used
3838
baz().await; // ok
3939
}

tests/ui/lint/unused/unused-async.stderr

+1-12
Original file line numberDiff line numberDiff line change
@@ -52,17 +52,6 @@ help: use `let _ = ...` to ignore the resulting value
5252
LL | let _ = bar();
5353
| +++++++
5454

55-
error: unused output of future returned by `bar` that must be used
56-
--> $DIR/unused-async.rs:36:5
57-
|
58-
LL | bar().await;
59-
| ^^^^^^^^^^^
60-
|
61-
help: use `let _ = ...` to ignore the resulting value
62-
|
63-
LL | let _ = bar().await;
64-
| +++++++
65-
6655
error: unused implementer of `Future` that must be used
6756
--> $DIR/unused-async.rs:37:5
6857
|
@@ -71,5 +60,5 @@ LL | baz();
7160
|
7261
= note: futures do nothing unless you `.await` or poll them
7362

74-
error: aborting due to 7 previous errors
63+
error: aborting due to 6 previous errors
7564

tests/ui/macros/issue-111749.rs

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
macro_rules! cbor_map {
2+
($key:expr) => {
3+
$key.signum();
4+
};
5+
}
6+
7+
fn main() {
8+
cbor_map! { #[test(test)] 4};
9+
//~^ ERROR removing an expression is not supported in this position
10+
//~| ERROR attribute must be of the form `#[test]`
11+
//~| WARNING this was previously accepted by the compiler but is being phased out
12+
}

tests/ui/macros/issue-111749.stderr

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
error: removing an expression is not supported in this position
2+
--> $DIR/issue-111749.rs:8:17
3+
|
4+
LL | cbor_map! { #[test(test)] 4};
5+
| ^^^^^^^^^^^^^
6+
7+
error: attribute must be of the form `#[test]`
8+
--> $DIR/issue-111749.rs:8:17
9+
|
10+
LL | cbor_map! { #[test(test)] 4};
11+
| ^^^^^^^^^^^^^
12+
|
13+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
14+
= note: for more information, see issue #57571 <https://github.com/rust-lang/rust/issues/57571>
15+
= note: `#[deny(ill_formed_attribute_input)]` on by default
16+
17+
error: aborting due to 2 previous errors
18+

0 commit comments

Comments
 (0)