Skip to content

Commit 340bb19

Browse files
committed
Auto merge of rust-lang#121078 - oli-obk:rollup-p11zsav, r=oli-obk
Rollup of 13 pull requests Successful merges: - rust-lang#116387 (Additional doc links and explanation of `Wake`.) - rust-lang#118738 (Netbsd10 update) - rust-lang#118890 (Clarify the lifetimes of allocations returned by the `Allocator` trait) - rust-lang#120498 (Uplift `TypeVisitableExt` into `rustc_type_ir`) - rust-lang#120530 (Be less confident when `dyn` suggestion is not checked for object safety) - rust-lang#120915 (Fix suggestion span for `?Sized` when param type has default) - rust-lang#121015 (Optimize `delayed_bug` handling.) - rust-lang#121024 (implement `Default` for `AsciiChar`) - rust-lang#121039 (Correctly compute adjustment casts in GVN) - rust-lang#121045 (Fix two UI tests with incorrect directive / invalid revision) - rust-lang#121049 (Do not point at `#[allow(_)]` as the reason for compat lint triggering) - rust-lang#121071 (Use fewer delayed bugs.) - rust-lang#121073 (Fix typos in `OneLock` doc) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 81b757c + 96635da commit 340bb19

File tree

93 files changed

+966
-589
lines changed

Some content is hidden

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

93 files changed

+966
-589
lines changed

compiler/rustc_ast_lowering/src/expr.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -323,9 +323,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
323323
)
324324
}
325325
ExprKind::Yield(opt_expr) => self.lower_expr_yield(e.span, opt_expr.as_deref()),
326-
ExprKind::Err => {
327-
hir::ExprKind::Err(self.dcx().span_delayed_bug(e.span, "lowered ExprKind::Err"))
328-
}
326+
ExprKind::Err => hir::ExprKind::Err(self.dcx().has_errors().unwrap()),
329327
ExprKind::Try(sub_expr) => self.lower_expr_try(e.span, sub_expr),
330328

331329
ExprKind::Paren(_) | ExprKind::ForLoop { .. } => {

compiler/rustc_ast_lowering/src/item.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1068,7 +1068,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
10681068
fn lower_block_expr_opt(&mut self, span: Span, block: Option<&Block>) -> hir::Expr<'hir> {
10691069
match block {
10701070
Some(block) => self.lower_block_expr(block),
1071-
None => self.expr_err(span, self.dcx().span_delayed_bug(span, "no block")),
1071+
None => self.expr_err(span, self.dcx().has_errors().unwrap()),
10721072
}
10731073
}
10741074

compiler/rustc_ast_lowering/src/lib.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1285,9 +1285,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
12851285
fn lower_ty_direct(&mut self, t: &Ty, itctx: ImplTraitContext) -> hir::Ty<'hir> {
12861286
let kind = match &t.kind {
12871287
TyKind::Infer => hir::TyKind::Infer,
1288-
TyKind::Err => {
1289-
hir::TyKind::Err(self.dcx().span_delayed_bug(t.span, "TyKind::Err lowered"))
1290-
}
1288+
TyKind::Err => hir::TyKind::Err(self.dcx().has_errors().unwrap()),
12911289
// Lower the anonymous structs or unions in a nested lowering context.
12921290
//
12931291
// ```

compiler/rustc_const_eval/src/transform/validate.rs

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -117,18 +117,14 @@ struct CfgChecker<'a, 'tcx> {
117117
impl<'a, 'tcx> CfgChecker<'a, 'tcx> {
118118
#[track_caller]
119119
fn fail(&self, location: Location, msg: impl AsRef<str>) {
120-
let span = self.body.source_info(location).span;
121-
// We use `span_delayed_bug` as we might see broken MIR when other errors have already
122-
// occurred.
123-
self.tcx.dcx().span_delayed_bug(
124-
span,
125-
format!(
126-
"broken MIR in {:?} ({}) at {:?}:\n{}",
127-
self.body.source.instance,
128-
self.when,
129-
location,
130-
msg.as_ref()
131-
),
120+
// We might see broken MIR when other errors have already occurred.
121+
assert!(
122+
self.tcx.dcx().has_errors().is_some(),
123+
"broken MIR in {:?} ({}) at {:?}:\n{}",
124+
self.body.source.instance,
125+
self.when,
126+
location,
127+
msg.as_ref(),
132128
);
133129
}
134130

compiler/rustc_errors/src/lib.rs

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1315,6 +1315,9 @@ impl DiagCtxtInner {
13151315
self.future_breakage_diagnostics.push(diagnostic.clone());
13161316
}
13171317

1318+
// Note that because this comes before the `match` below,
1319+
// `-Zeagerly-emit-delayed-bugs` continues to work even after we've
1320+
// issued an error and stopped recording new delayed bugs.
13181321
if diagnostic.level == DelayedBug && self.flags.eagerly_emit_delayed_bugs {
13191322
diagnostic.level = Error;
13201323
}
@@ -1326,18 +1329,20 @@ impl DiagCtxtInner {
13261329
diagnostic.level = Bug;
13271330
}
13281331
DelayedBug => {
1329-
// FIXME(eddyb) this should check for `has_errors` and stop pushing
1330-
// once *any* errors were emitted (and truncate `delayed_bugs`
1331-
// when an error is first emitted, also), but maybe there's a case
1332-
// in which that's not sound? otherwise this is really inefficient.
1333-
let backtrace = std::backtrace::Backtrace::capture();
1334-
// This `unchecked_error_guaranteed` is valid. It is where the
1335-
// `ErrorGuaranteed` for delayed bugs originates.
1336-
#[allow(deprecated)]
1337-
let guar = ErrorGuaranteed::unchecked_error_guaranteed();
1338-
self.delayed_bugs
1339-
.push((DelayedDiagnostic::with_backtrace(diagnostic, backtrace), guar));
1340-
return Some(guar);
1332+
// If we have already emitted at least one error, we don't need
1333+
// to record the delayed bug, because it'll never be used.
1334+
return if let Some(guar) = self.has_errors_or_lint_errors() {
1335+
Some(guar)
1336+
} else {
1337+
let backtrace = std::backtrace::Backtrace::capture();
1338+
// This `unchecked_error_guaranteed` is valid. It is where the
1339+
// `ErrorGuaranteed` for delayed bugs originates.
1340+
#[allow(deprecated)]
1341+
let guar = ErrorGuaranteed::unchecked_error_guaranteed();
1342+
self.delayed_bugs
1343+
.push((DelayedDiagnostic::with_backtrace(diagnostic, backtrace), guar));
1344+
Some(guar)
1345+
};
13411346
}
13421347
Warning if !self.flags.can_emit_warnings => {
13431348
if diagnostic.has_future_breakage() {
@@ -1403,6 +1408,16 @@ impl DiagCtxtInner {
14031408
}
14041409

14051410
if is_error {
1411+
// If we have any delayed bugs recorded, we can discard them
1412+
// because they won't be used. (This should only occur if there
1413+
// have been no errors previously emitted, because we don't add
1414+
// new delayed bugs once the first error is emitted.)
1415+
if !self.delayed_bugs.is_empty() {
1416+
assert_eq!(self.lint_err_guars.len() + self.err_guars.len(), 0);
1417+
self.delayed_bugs.clear();
1418+
self.delayed_bugs.shrink_to_fit();
1419+
}
1420+
14061421
// This `unchecked_error_guaranteed` is valid. It is where the
14071422
// `ErrorGuaranteed` for errors and lint errors originates.
14081423
#[allow(deprecated)]

compiler/rustc_expand/src/mbe/diagnostics.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@ pub(super) fn failed_to_match_macro<'cx>(
3434
if try_success_result.is_ok() {
3535
// Nonterminal parser recovery might turn failed matches into successful ones,
3636
// but for that it must have emitted an error already
37-
tracker
38-
.cx
39-
.dcx()
40-
.span_delayed_bug(sp, "Macro matching returned a success on the second try");
37+
assert!(
38+
tracker.cx.dcx().has_errors().is_some(),
39+
"Macro matching returned a success on the second try"
40+
);
4141
}
4242

4343
if let Some(result) = tracker.result {

compiler/rustc_hir_analysis/src/astconv/lint.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
243243
tcx.node_span_lint(BARE_TRAIT_OBJECTS, self_ty.hir_id, self_ty.span, msg, |lint| {
244244
if self_ty.span.can_be_used_for_suggestions() {
245245
lint.multipart_suggestion_verbose(
246-
"use `dyn`",
246+
"if this is an object-safe trait, use `dyn`",
247247
sugg,
248248
Applicability::MachineApplicable,
249249
);

compiler/rustc_hir_analysis/src/astconv/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -758,8 +758,8 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
758758
// since we should have emitten an error for them earlier, and they will
759759
// not be well-formed!
760760
if polarity == ty::ImplPolarity::Negative {
761-
self.tcx().dcx().span_delayed_bug(
762-
binding.span,
761+
assert!(
762+
self.tcx().dcx().has_errors().is_some(),
763763
"negative trait bounds should not have bindings",
764764
);
765765
continue;

compiler/rustc_hir_analysis/src/check/wfcheck.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1865,13 +1865,13 @@ fn check_variances_for_type_defn<'tcx>(
18651865
let hir_param = &hir_generics.params[index];
18661866

18671867
if ty_param.def_id != hir_param.def_id.into() {
1868-
// valid programs always have lifetimes before types in the generic parameter list
1868+
// Valid programs always have lifetimes before types in the generic parameter list.
18691869
// ty_generics are normalized to be in this required order, and variances are built
18701870
// from ty generics, not from hir generics. but we need hir generics to get
1871-
// a span out
1871+
// a span out.
18721872
//
1873-
// if they aren't in the same order, then the user has written invalid code, and already
1874-
// got an error about it (or I'm wrong about this)
1873+
// If they aren't in the same order, then the user has written invalid code, and already
1874+
// got an error about it (or I'm wrong about this).
18751875
tcx.dcx().span_delayed_bug(
18761876
hir_param.span,
18771877
"hir generics and ty generics in different order",

compiler/rustc_hir_analysis/src/coherence/unsafety.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ pub(super) fn check_item(
8585

8686
(_, _, Unsafety::Unsafe, Negative) => {
8787
// Reported in AST validation
88-
tcx.dcx().span_delayed_bug(tcx.def_span(def_id), "unsafe negative impl");
88+
assert!(tcx.dcx().has_errors().is_some(), "unsafe negative impl");
8989
Ok(())
9090
}
9191
(_, _, Unsafety::Normal, Negative)

0 commit comments

Comments
 (0)