Skip to content

Commit ad0cc6c

Browse files
authored
Unrolled build for rust-lang#121071
Rollup merge of rust-lang#121071 - nnethercote:fewer-delayed-bugs, r=oli-obk Use fewer delayed bugs. For some cases where it's clear that an error has already occurred, e.g.: - there's a comment stating exactly that, or - things like HIR lowering, where we are lowering an error kind The commit also tweaks some comments around delayed bug sites. r? `@oli-obk`
2 parents 81b757c + 05849e8 commit ad0cc6c

File tree

23 files changed

+88
-90
lines changed

23 files changed

+88
-90
lines changed

compiler/rustc_ast_lowering/src/expr.rs

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

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

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

+8-12
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_expand/src/mbe/diagnostics.rs

+4-4
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/mod.rs

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

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

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

compiler/rustc_hir_typeck/src/cast.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -139,10 +139,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
139139
| ty::Never
140140
| ty::Dynamic(_, _, ty::DynStar)
141141
| ty::Error(_) => {
142-
let reported = self
142+
let guar = self
143143
.dcx()
144144
.span_delayed_bug(span, format!("`{t:?}` should be sized but is not?"));
145-
return Err(reported);
145+
return Err(guar);
146146
}
147147
})
148148
}

compiler/rustc_hir_typeck/src/writeback.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -221,8 +221,8 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
221221
if base_ty.is_none() {
222222
// When encountering `return [0][0]` outside of a `fn` body we can encounter a base
223223
// that isn't in the type table. We assume more relevant errors have already been
224-
// emitted, so we delay an ICE if none have. (#64638)
225-
self.tcx().dcx().span_delayed_bug(e.span, format!("bad base: `{base:?}`"));
224+
// emitted. (#64638)
225+
assert!(self.tcx().dcx().has_errors().is_some(), "bad base: `{base:?}`");
226226
}
227227
if let Some(base_ty) = base_ty
228228
&& let ty::Ref(_, base_ty_inner, _) = *base_ty.kind()

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

+6-8
Original file line numberDiff line numberDiff line change
@@ -802,14 +802,12 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> {
802802
}
803803

804804
// Errors in earlier passes can yield error variables without
805-
// resolution errors here; delay ICE in favor of those errors.
806-
self.tcx().dcx().span_delayed_bug(
807-
self.var_infos[node_idx].origin.span(),
808-
format!(
809-
"collect_error_for_expanding_node() could not find \
810-
error for var {node_idx:?} in universe {node_universe:?}, lower_bounds={lower_bounds:#?}, \
811-
upper_bounds={upper_bounds:#?}"
812-
),
805+
// resolution errors here; ICE if no errors have been emitted yet.
806+
assert!(
807+
self.tcx().dcx().has_errors().is_some(),
808+
"collect_error_for_expanding_node() could not find error for var {node_idx:?} in \
809+
universe {node_universe:?}, lower_bounds={lower_bounds:#?}, \
810+
upper_bounds={upper_bounds:#?}",
813811
);
814812
}
815813

compiler/rustc_infer/src/infer/outlives/obligations.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -300,9 +300,9 @@ where
300300
self.components_must_outlive(origin, subcomponents, region, category);
301301
}
302302
Component::UnresolvedInferenceVariable(v) => {
303-
// ignore this, we presume it will yield an error
304-
// later, since if a type variable is not resolved by
305-
// this point it never will be
303+
// Ignore this, we presume it will yield an error later,
304+
// since if a type variable is not resolved by this point
305+
// it never will be.
306306
self.tcx.dcx().span_delayed_bug(
307307
origin.span(),
308308
format!("unresolved inference variable in outlives: {v:?}"),

compiler/rustc_infer/src/infer/outlives/verify.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -172,13 +172,13 @@ impl<'cx, 'tcx> VerifyBoundCx<'cx, 'tcx> {
172172
self.bound_from_components(components, visited)
173173
}
174174
Component::UnresolvedInferenceVariable(v) => {
175-
// ignore this, we presume it will yield an error
176-
// later, since if a type variable is not resolved by
177-
// this point it never will be
175+
// Ignore this, we presume it will yield an error later, since
176+
// if a type variable is not resolved by this point it never
177+
// will be.
178178
self.tcx
179179
.dcx()
180180
.delayed_bug(format!("unresolved inference variable in outlives: {v:?}"));
181-
// add a bound that never holds
181+
// Add a bound that never holds.
182182
VerifyBound::AnyBound(vec![])
183183
}
184184
}

compiler/rustc_lint/src/early.rs

+6-7
Original file line numberDiff line numberDiff line change
@@ -431,14 +431,13 @@ pub fn check_ast_node_inner<'a, T: EarlyLintPass>(
431431
// If not, that means that we somehow buffered a lint for a node id
432432
// that was not lint-checked (perhaps it doesn't exist?). This is a bug.
433433
for (id, lints) in cx.context.buffered.map {
434-
for early_lint in lints {
435-
sess.dcx().span_delayed_bug(
436-
early_lint.span,
437-
format!(
438-
"failed to process buffered lint here (dummy = {})",
439-
id == ast::DUMMY_NODE_ID
440-
),
434+
if !lints.is_empty() {
435+
assert!(
436+
sess.dcx().has_errors().is_some(),
437+
"failed to process buffered lint here (dummy = {})",
438+
id == ast::DUMMY_NODE_ID
441439
);
440+
break;
442441
}
443442
}
444443
}

compiler/rustc_mir_build/src/check_unsafety.rs

+14-8
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ struct UnsafetyVisitor<'a, 'tcx> {
3333
body_target_features: &'tcx [Symbol],
3434
/// When inside the LHS of an assignment to a field, this is the type
3535
/// of the LHS and the span of the assignment expression.
36-
assignment_info: Option<(Ty<'tcx>, Span)>,
36+
assignment_info: Option<Ty<'tcx>>,
3737
in_union_destructure: bool,
3838
param_env: ParamEnv<'tcx>,
3939
inside_adt: bool,
@@ -473,10 +473,15 @@ impl<'a, 'tcx> Visitor<'a, 'tcx> for UnsafetyVisitor<'a, 'tcx> {
473473
if let ty::Adt(adt_def, _) = lhs.ty.kind()
474474
&& adt_def.is_union()
475475
{
476-
if let Some((assigned_ty, assignment_span)) = self.assignment_info {
476+
if let Some(assigned_ty) = self.assignment_info {
477477
if assigned_ty.needs_drop(self.tcx, self.param_env) {
478-
// This would be unsafe, but should be outright impossible since we reject such unions.
479-
self.tcx.dcx().span_delayed_bug(assignment_span, format!("union fields that need dropping should be impossible: {assigned_ty}"));
478+
// This would be unsafe, but should be outright impossible since we
479+
// reject such unions.
480+
assert!(
481+
self.tcx.dcx().has_errors().is_some(),
482+
"union fields that need dropping should be impossible: \
483+
{assigned_ty}"
484+
);
480485
}
481486
} else {
482487
self.requires_unsafe(expr.span, AccessToUnionField);
@@ -492,14 +497,15 @@ impl<'a, 'tcx> Visitor<'a, 'tcx> for UnsafetyVisitor<'a, 'tcx> {
492497
self.requires_unsafe(expr.span, MutationOfLayoutConstrainedField);
493498
}
494499

495-
// Second, check for accesses to union fields
496-
// don't have any special handling for AssignOp since it causes a read *and* write to lhs
500+
// Second, check for accesses to union fields. Don't have any
501+
// special handling for AssignOp since it causes a read *and*
502+
// write to lhs.
497503
if matches!(expr.kind, ExprKind::Assign { .. }) {
498-
self.assignment_info = Some((lhs.ty, expr.span));
504+
self.assignment_info = Some(lhs.ty);
499505
visit::walk_expr(self, lhs);
500506
self.assignment_info = None;
501507
visit::walk_expr(self, &self.thir()[rhs]);
502-
return; // we have already visited everything by now
508+
return; // We have already visited everything by now.
503509
}
504510
}
505511
ExprKind::Borrow { borrow_kind, arg } => {

compiler/rustc_mir_build/src/thir/pattern/const_to_pat.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,7 @@ impl<'tcx> ConstToPat<'tcx> {
153153
// a hard error when we don't have a valtree or when we find something in
154154
// the valtree that is not structural; then this can all be made a lot simpler.
155155

156-
let structural =
157-
traits::search_for_structural_match_violation(self.span, self.tcx(), cv.ty());
156+
let structural = traits::search_for_structural_match_violation(self.tcx(), cv.ty());
158157
debug!(
159158
"search_for_structural_match_violation cv.ty: {:?} returned: {:?}",
160159
cv.ty(),

compiler/rustc_mir_transform/src/check_unsafety.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -243,10 +243,11 @@ impl<'tcx> Visitor<'tcx> for UnsafetyChecker<'_, 'tcx> {
243243
// old value is being dropped.
244244
let assigned_ty = place.ty(&self.body.local_decls, self.tcx).ty;
245245
if assigned_ty.needs_drop(self.tcx, self.param_env) {
246-
// This would be unsafe, but should be outright impossible since we reject such unions.
247-
self.tcx.dcx().span_delayed_bug(
248-
self.source_info.span,
249-
format!("union fields that need dropping should be impossible: {assigned_ty}")
246+
// This would be unsafe, but should be outright impossible since we reject
247+
// such unions.
248+
assert!(
249+
self.tcx.dcx().has_errors().is_some(),
250+
"union fields that need dropping should be impossible: {assigned_ty}"
250251
);
251252
}
252253
} else {

compiler/rustc_mir_transform/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ fn mir_const_qualif(tcx: TyCtxt<'_>, def: LocalDefId) -> ConstQualifs {
265265
let body = &tcx.mir_const(def).borrow();
266266

267267
if body.return_ty().references_error() {
268-
tcx.dcx().span_delayed_bug(body.span, "mir_const_qualif: MIR had errors");
268+
assert!(tcx.dcx().has_errors().is_some(), "mir_const_qualif: MIR had errors");
269269
return Default::default();
270270
}
271271

compiler/rustc_query_system/src/query/plumbing.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -429,16 +429,16 @@ where
429429
let formatter = query.format_value();
430430
if old_hash != new_hash {
431431
// We have an inconsistency. This can happen if one of the two
432-
// results is tainted by errors. In this case, delay a bug to
433-
// ensure compilation is doomed.
434-
qcx.dep_context().sess().dcx().delayed_bug(format!(
432+
// results is tainted by errors.
433+
assert!(
434+
qcx.dep_context().sess().dcx().has_errors().is_some(),
435435
"Computed query value for {:?}({:?}) is inconsistent with fed value,\n\
436436
computed={:#?}\nfed={:#?}",
437437
query.dep_kind(),
438438
key,
439439
formatter(&result),
440440
formatter(&cached_result),
441-
));
441+
);
442442
}
443443
}
444444
}

compiler/rustc_trait_selection/src/traits/const_evaluatable.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,10 @@ pub fn is_const_evaluatable<'tcx>(
6262

6363
match unexpanded_ct.kind() {
6464
ty::ConstKind::Expr(_) => {
65-
// FIXME(generic_const_exprs): we have a `ConstKind::Expr` which is fully concrete, but
66-
// currently it is not possible to evaluate `ConstKind::Expr` so we are unable to tell if it
67-
// is evaluatable or not. For now we just ICE until this is implemented.
65+
// FIXME(generic_const_exprs): we have a `ConstKind::Expr` which is fully concrete,
66+
// but currently it is not possible to evaluate `ConstKind::Expr` so we are unable
67+
// to tell if it is evaluatable or not. For now we just ICE until this is
68+
// implemented.
6869
Err(NotConstEvaluatable::Error(tcx.dcx().span_delayed_bug(
6970
span,
7071
"evaluating `ConstKind::Expr` is not currently supported",

compiler/rustc_trait_selection/src/traits/error_reporting/type_err_ctxt_ext.rs

+8-4
Original file line numberDiff line numberDiff line change
@@ -236,9 +236,9 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
236236
}
237237
}
238238

239-
// It could be that we don't report an error because we have seen an `ErrorReported` from another source.
240-
// We should probably be able to fix most of these, but some are delayed bugs that get a proper error
241-
// after this function.
239+
// It could be that we don't report an error because we have seen an `ErrorReported` from
240+
// another source. We should probably be able to fix most of these, but some are delayed
241+
// bugs that get a proper error after this function.
242242
reported.unwrap_or_else(|| self.dcx().delayed_bug("failed to report fulfillment errors"))
243243
}
244244

@@ -519,7 +519,11 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
519519
trait_ref,
520520
span,
521521
) {
522-
GetSafeTransmuteErrorAndReason::Silent => return self.dcx().span_delayed_bug(span, "silent safe transmute error"),
522+
GetSafeTransmuteErrorAndReason::Silent => {
523+
return self.dcx().span_delayed_bug(
524+
span, "silent safe transmute error"
525+
);
526+
}
523527
GetSafeTransmuteErrorAndReason::Error {
524528
err_msg,
525529
safe_transmute_explanation,

compiler/rustc_trait_selection/src/traits/object_safety.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -555,7 +555,7 @@ fn virtual_call_violations_for_method<'tcx>(
555555

556556
// NOTE: This check happens last, because it results in a lint, and not a
557557
// hard error.
558-
if tcx.predicates_of(method.def_id).predicates.iter().any(|&(pred, span)| {
558+
if tcx.predicates_of(method.def_id).predicates.iter().any(|&(pred, _span)| {
559559
// dyn Trait is okay:
560560
//
561561
// trait Trait {
@@ -594,7 +594,10 @@ fn virtual_call_violations_for_method<'tcx>(
594594
// would already have reported an error at the definition of the
595595
// auto trait.
596596
if pred_trait_ref.args.len() != 1 {
597-
tcx.dcx().span_delayed_bug(span, "auto traits cannot have generic parameters");
597+
assert!(
598+
tcx.dcx().has_errors().is_some(),
599+
"auto traits cannot have generic parameters"
600+
);
598601
}
599602
return false;
600603
}

0 commit comments

Comments
 (0)