Skip to content

Commit 2da59b8

Browse files
committed
Auto merge of #118470 - nnethercote:cleanup-error-handlers, r=compiler-errors
Cleanup error handlers Mostly by making function naming more consistent. More to do after this, but this is enough for one PR. r? compiler-errors
2 parents bd3a221 + 61f9356 commit 2da59b8

File tree

170 files changed

+495
-517
lines changed

Some content is hidden

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

170 files changed

+495
-517
lines changed

compiler/rustc_abi/src/layout.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use crate::{
1414
pub trait LayoutCalculator {
1515
type TargetDataLayoutRef: Borrow<TargetDataLayout>;
1616

17-
fn delay_bug(&self, txt: String);
17+
fn delayed_bug(&self, txt: String);
1818
fn current_data_layout(&self) -> Self::TargetDataLayoutRef;
1919

2020
fn scalar_pair<FieldIdx: Idx, VariantIdx: Idx>(
@@ -792,7 +792,7 @@ pub trait LayoutCalculator {
792792
let only_variant = &variants[VariantIdx::new(0)];
793793
for field in only_variant {
794794
if field.is_unsized() {
795-
self.delay_bug("unsized field in union".to_string());
795+
self.delayed_bug("unsized field in union".to_string());
796796
}
797797

798798
align = align.max(field.align);
@@ -1038,7 +1038,7 @@ fn univariant<
10381038
for &i in &inverse_memory_index {
10391039
let field = &fields[i];
10401040
if !sized {
1041-
this.delay_bug(format!(
1041+
this.delayed_bug(format!(
10421042
"univariant: field #{} comes after unsized field",
10431043
offsets.len(),
10441044
));

compiler/rustc_ast_lowering/src/expr.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
327327
),
328328
ExprKind::Yield(opt_expr) => self.lower_expr_yield(e.span, opt_expr.as_deref()),
329329
ExprKind::Err => hir::ExprKind::Err(
330-
self.tcx.sess.delay_span_bug(e.span, "lowered ExprKind::Err"),
330+
self.tcx.sess.span_delayed_bug(e.span, "lowered ExprKind::Err"),
331331
),
332332
ExprKind::Try(sub_expr) => self.lower_expr_try(e.span, sub_expr),
333333

@@ -799,7 +799,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
799799
self.expr_ident_mut(span, task_context_ident, task_context_hid)
800800
} else {
801801
// Use of `await` outside of an async context, we cannot use `task_context` here.
802-
self.expr_err(span, self.tcx.sess.delay_span_bug(span, "no task_context hir id"))
802+
self.expr_err(span, self.tcx.sess.span_delayed_bug(span, "no task_context hir id"))
803803
};
804804
let new_unchecked = self.expr_call_lang_item_fn_mut(
805805
span,

compiler/rustc_ast_lowering/src/format.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ fn make_count<'hir>(
267267
ctx.expr(
268268
sp,
269269
hir::ExprKind::Err(
270-
ctx.tcx.sess.delay_span_bug(sp, "lowered bad format_args count"),
270+
ctx.tcx.sess.span_delayed_bug(sp, "lowered bad format_args count"),
271271
),
272272
)
273273
}
@@ -306,7 +306,7 @@ fn make_format_spec<'hir>(
306306
}
307307
Err(_) => ctx.expr(
308308
sp,
309-
hir::ExprKind::Err(ctx.tcx.sess.delay_span_bug(sp, "lowered bad format_args count")),
309+
hir::ExprKind::Err(ctx.tcx.sess.span_delayed_bug(sp, "lowered bad format_args count")),
310310
),
311311
};
312312
let &FormatOptions {

compiler/rustc_ast_lowering/src/item.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
256256
&ImplTraitContext::Disallowed(ImplTraitPosition::Generic),
257257
|this| match ty {
258258
None => {
259-
let guar = this.tcx.sess.delay_span_bug(
259+
let guar = this.tcx.sess.span_delayed_bug(
260260
span,
261261
"expected to lower type alias type, but it was missing",
262262
);
@@ -863,7 +863,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
863863
&ImplTraitContext::Disallowed(ImplTraitPosition::Generic),
864864
|this| match ty {
865865
None => {
866-
let guar = this.tcx.sess.delay_span_bug(
866+
let guar = this.tcx.sess.span_delayed_bug(
867867
i.span,
868868
"expected to lower associated type, but it was missing",
869869
);
@@ -996,7 +996,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
996996
fn lower_block_expr_opt(&mut self, span: Span, block: Option<&Block>) -> hir::Expr<'hir> {
997997
match block {
998998
Some(block) => self.lower_block_expr(block),
999-
None => self.expr_err(span, self.tcx.sess.delay_span_bug(span, "no block")),
999+
None => self.expr_err(span, self.tcx.sess.span_delayed_bug(span, "no block")),
10001000
}
10011001
}
10021002

@@ -1006,7 +1006,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
10061006
&[],
10071007
match expr {
10081008
Some(expr) => this.lower_expr_mut(expr),
1009-
None => this.expr_err(span, this.tcx.sess.delay_span_bug(span, "no block")),
1009+
None => this.expr_err(span, this.tcx.sess.span_delayed_bug(span, "no block")),
10101010
},
10111011
)
10121012
})

compiler/rustc_ast_lowering/src/lib.rs

+8-11
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ use rustc_data_structures::fx::FxHashMap;
5454
use rustc_data_structures::sorted_map::SortedMap;
5555
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
5656
use rustc_data_structures::sync::Lrc;
57-
use rustc_errors::{DiagnosticArgFromDisplay, Handler, StashKey};
57+
use rustc_errors::{DiagnosticArgFromDisplay, StashKey};
5858
use rustc_hir as hir;
5959
use rustc_hir::def::{DefKind, LifetimeRes, Namespace, PartialRes, PerNS, Res};
6060
use rustc_hir::def_id::{LocalDefId, CRATE_DEF_ID, LOCAL_CRATE};
@@ -763,10 +763,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
763763
self.resolver.get_import_res(id).present_items()
764764
}
765765

766-
fn diagnostic(&self) -> &Handler {
767-
self.tcx.sess.diagnostic()
768-
}
769-
770766
/// Reuses the span but adds information like the kind of the desugaring and features that are
771767
/// allowed inside this span.
772768
fn mark_span_with_reason(
@@ -1326,7 +1322,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
13261322
let kind = match &t.kind {
13271323
TyKind::Infer => hir::TyKind::Infer,
13281324
TyKind::Err => {
1329-
hir::TyKind::Err(self.tcx.sess.delay_span_bug(t.span, "TyKind::Err lowered"))
1325+
hir::TyKind::Err(self.tcx.sess.span_delayed_bug(t.span, "TyKind::Err lowered"))
13301326
}
13311327
// FIXME(unnamed_fields): IMPLEMENTATION IN PROGRESS
13321328
#[allow(rustc::untranslatable_diagnostic)]
@@ -1510,7 +1506,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
15101506
}
15111507
TyKind::MacCall(_) => panic!("`TyKind::MacCall` should have been expanded by now"),
15121508
TyKind::CVarArgs => {
1513-
let guar = self.tcx.sess.delay_span_bug(
1509+
let guar = self.tcx.sess.span_delayed_bug(
15141510
t.span,
15151511
"`TyKind::CVarArgs` should have been handled elsewhere",
15161512
);
@@ -1653,7 +1649,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
16531649
} else {
16541650
self.tcx
16551651
.sess
1656-
.delay_span_bug(lifetime.ident.span, "no def-id for fresh lifetime");
1652+
.span_delayed_bug(lifetime.ident.span, "no def-id for fresh lifetime");
16571653
continue;
16581654
}
16591655
}
@@ -2515,9 +2511,10 @@ impl<'hir> GenericArgsCtor<'hir> {
25152511
let hir_id = lcx.next_id();
25162512

25172513
let Some(host_param_id) = lcx.host_param_id else {
2518-
lcx.tcx
2519-
.sess
2520-
.delay_span_bug(span, "no host param id for call in const yet no errors reported");
2514+
lcx.tcx.sess.span_delayed_bug(
2515+
span,
2516+
"no host param id for call in const yet no errors reported",
2517+
);
25212518
return;
25222519
};
25232520

compiler/rustc_ast_lowering/src/path.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
139139

140140
// We should've returned in the for loop above.
141141

142-
self.diagnostic().span_bug(
142+
self.tcx.sess.diagnostic().span_bug(
143143
p.span,
144144
format!(
145145
"lower_qpath: no final extension segment in {}..{}",

compiler/rustc_ast_passes/src/feature_gate.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ impl<'a> PostExpansionVisitor<'a> {
102102
}
103103
Err(abi::AbiDisabled::Unrecognized) => {
104104
if self.sess.opts.pretty.map_or(true, |ppm| ppm.needs_hir()) {
105-
self.sess.parse_sess.span_diagnostic.delay_span_bug(
105+
self.sess.diagnostic().span_delayed_bug(
106106
span,
107107
format!(
108108
"unrecognized ABI not caught in lowering: {}",
@@ -627,7 +627,7 @@ fn maybe_stage_features(sess: &Session, features: &Features, krate: &ast::Crate)
627627
if all_stable {
628628
err.sugg = Some(attr.span);
629629
}
630-
sess.parse_sess.span_diagnostic.emit_err(err);
630+
sess.diagnostic().emit_err(err);
631631
}
632632
}
633633
}

compiler/rustc_attr/src/builtin.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -945,7 +945,7 @@ pub fn parse_repr_attr(sess: &Session, attr: &Attribute) -> Vec<ReprAttr> {
945945
assert!(attr.has_name(sym::repr), "expected `#[repr(..)]`, found: {attr:?}");
946946
use ReprAttr::*;
947947
let mut acc = Vec::new();
948-
let diagnostic = &sess.parse_sess.span_diagnostic;
948+
let diagnostic = sess.diagnostic();
949949

950950
if let Some(items) = attr.meta_item_list() {
951951
for item in items {
@@ -1060,9 +1060,9 @@ pub fn parse_repr_attr(sess: &Session, attr: &Attribute) -> Vec<ReprAttr> {
10601060
// Not a word we recognize. This will be caught and reported by
10611061
// the `check_mod_attrs` pass, but this pass doesn't always run
10621062
// (e.g. if we only pretty-print the source), so we have to gate
1063-
// the `delay_span_bug` call as follows:
1063+
// the `span_delayed_bug` call as follows:
10641064
if sess.opts.pretty.map_or(true, |pp| pp.needs_analysis()) {
1065-
diagnostic.delay_span_bug(item.span(), "unrecognized representation hint");
1065+
diagnostic.span_delayed_bug(item.span(), "unrecognized representation hint");
10661066
}
10671067
}
10681068
}

compiler/rustc_borrowck/src/diagnostics/bound_region_errors.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ fn try_extract_error_from_fulfill_cx<'tcx>(
385385
error_region: Option<ty::Region<'tcx>>,
386386
) -> Option<DiagnosticBuilder<'tcx, ErrorGuaranteed>> {
387387
// We generally shouldn't have errors here because the query was
388-
// already run, but there's no point using `delay_span_bug`
388+
// already run, but there's no point using `span_delayed_bug`
389389
// when we're going to emit an error here anyway.
390390
let _errors = ocx.select_all_or_error();
391391
let region_constraints = ocx.infcx.with_region_constraints(|r| r.clone());

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1135,7 +1135,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
11351135
});
11361136
} else {
11371137
issued_spans.var_subdiag(
1138-
Some(&self.infcx.tcx.sess.parse_sess.span_diagnostic),
1138+
Some(self.infcx.tcx.sess.diagnostic()),
11391139
&mut err,
11401140
Some(issued_borrow.kind),
11411141
|kind, var_span| {
@@ -1152,7 +1152,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
11521152
);
11531153

11541154
borrow_spans.var_subdiag(
1155-
Some(&self.infcx.tcx.sess.parse_sess.span_diagnostic),
1155+
Some(self.infcx.tcx.sess.diagnostic()),
11561156
&mut err,
11571157
Some(gen_borrow_kind),
11581158
|kind, var_span| {

compiler/rustc_borrowck/src/diagnostics/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
124124
let did = did.expect_local();
125125
if let Some((span, hir_place)) = self.infcx.tcx.closure_kind_origin(did) {
126126
diag.eager_subdiagnostic(
127-
&self.infcx.tcx.sess.parse_sess.span_diagnostic,
127+
self.infcx.tcx.sess.diagnostic(),
128128
OnClosureNote::InvokedTwice {
129129
place_name: &ty::place_to_string_for_capture(
130130
self.infcx.tcx,
@@ -146,7 +146,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
146146
let did = did.expect_local();
147147
if let Some((span, hir_place)) = self.infcx.tcx.closure_kind_origin(did) {
148148
diag.eager_subdiagnostic(
149-
&self.infcx.tcx.sess.parse_sess.span_diagnostic,
149+
self.infcx.tcx.sess.diagnostic(),
150150
OnClosureNote::MovedTwice {
151151
place_name: &ty::place_to_string_for_capture(self.infcx.tcx, hir_place),
152152
span: *span,
@@ -1119,7 +1119,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
11191119
&& self.infcx.can_eq(self.param_env, ty, self_ty)
11201120
{
11211121
err.eager_subdiagnostic(
1122-
&self.infcx.tcx.sess.parse_sess.span_diagnostic,
1122+
self.infcx.tcx.sess.diagnostic(),
11231123
CaptureReasonSuggest::FreshReborrow {
11241124
span: move_span.shrink_to_hi(),
11251125
},

compiler/rustc_borrowck/src/diagnostics/region_errors.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ impl<'tcx> RegionErrors<'tcx> {
8484
#[track_caller]
8585
pub fn push(&mut self, val: impl Into<RegionErrorKind<'tcx>>) {
8686
let val = val.into();
87-
self.1.sess.delay_span_bug(DUMMY_SP, format!("{val:?}"));
87+
self.1.sess.span_delayed_bug(DUMMY_SP, format!("{val:?}"));
8888
self.0.push(val);
8989
}
9090
pub fn is_empty(&self) -> bool {

compiler/rustc_borrowck/src/diagnostics/region_name.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -619,8 +619,8 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
619619
_,
620620
) => {
621621
// HIR lowering sometimes doesn't catch this in erroneous
622-
// programs, so we need to use delay_span_bug here. See #82126.
623-
self.infcx.tcx.sess.delay_span_bug(
622+
// programs, so we need to use span_delayed_bug here. See #82126.
623+
self.infcx.tcx.sess.span_delayed_bug(
624624
hir_arg.span(),
625625
format!("unmatched arg and hir arg: found {kind:?} vs {hir_arg:?}"),
626626
);

compiler/rustc_borrowck/src/lib.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -2130,11 +2130,11 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
21302130
&& !self.has_buffered_errors()
21312131
{
21322132
// rust-lang/rust#46908: In pure NLL mode this code path should be
2133-
// unreachable, but we use `delay_span_bug` because we can hit this when
2133+
// unreachable, but we use `span_delayed_bug` because we can hit this when
21342134
// dereferencing a non-Copy raw pointer *and* have `-Ztreat-err-as-bug`
21352135
// enabled. We don't want to ICE for that case, as other errors will have
21362136
// been emitted (#52262).
2137-
self.infcx.tcx.sess.delay_span_bug(
2137+
self.infcx.tcx.sess.span_delayed_bug(
21382138
span,
21392139
format!(
21402140
"Accessing `{place:?}` with the kind `{kind:?}` shouldn't be possible",
@@ -2428,7 +2428,7 @@ mod error {
24282428

24292429
pub fn buffer_error(&mut self, t: DiagnosticBuilder<'_, ErrorGuaranteed>) {
24302430
if let None = self.tainted_by_errors {
2431-
self.tainted_by_errors = Some(self.tcx.sess.delay_span_bug(
2431+
self.tainted_by_errors = Some(self.tcx.sess.span_delayed_bug(
24322432
t.span.clone_ignoring_labels(),
24332433
"diagnostic buffered but not emitted",
24342434
))

compiler/rustc_borrowck/src/nll.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ pub(crate) fn compute_regions<'cx, 'tcx>(
187187

188188
if !nll_errors.is_empty() {
189189
// Suppress unhelpful extra errors in `infer_opaque_types`.
190-
infcx.set_tainted_by_errors(infcx.tcx.sess.delay_span_bug(
190+
infcx.set_tainted_by_errors(infcx.tcx.sess.span_delayed_bug(
191191
body.span,
192192
"`compute_regions` tainted `infcx` with errors but did not emit any errors",
193193
));
@@ -280,7 +280,7 @@ pub(super) fn dump_annotation<'tcx>(
280280

281281
let def_span = tcx.def_span(body.source.def_id());
282282
let mut err = if let Some(closure_region_requirements) = closure_region_requirements {
283-
let mut err = tcx.sess.diagnostic().span_note_diag(def_span, "external requirements");
283+
let mut err = tcx.sess.diagnostic().struct_span_note(def_span, "external requirements");
284284

285285
regioncx.annotate(tcx, &mut err);
286286

@@ -299,7 +299,7 @@ pub(super) fn dump_annotation<'tcx>(
299299

300300
err
301301
} else {
302-
let mut err = tcx.sess.diagnostic().span_note_diag(def_span, "no external requirements");
302+
let mut err = tcx.sess.diagnostic().struct_span_note(def_span, "no external requirements");
303303
regioncx.annotate(tcx, &mut err);
304304

305305
err

compiler/rustc_borrowck/src/type_check/input_output.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
7777
if argument_index + 1 >= body.local_decls.len() {
7878
self.tcx()
7979
.sess
80-
.delay_span_bug(body.span, "found more normalized_input_ty than local_decls");
80+
.span_delayed_bug(body.span, "found more normalized_input_ty than local_decls");
8181
break;
8282
}
8383

@@ -101,10 +101,10 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
101101
);
102102

103103
// We will not have a universal_regions.yield_ty if we yield (by accident)
104-
// outside of a coroutine and return an `impl Trait`, so emit a delay_span_bug
104+
// outside of a coroutine and return an `impl Trait`, so emit a span_delayed_bug
105105
// because we don't want to panic in an assert here if we've already got errors.
106106
if body.yield_ty().is_some() != universal_regions.yield_ty.is_some() {
107-
self.tcx().sess.delay_span_bug(
107+
self.tcx().sess.span_delayed_bug(
108108
body.span,
109109
format!(
110110
"Expected body to have yield_ty ({:?}) iff we have a UR yield_ty ({:?})",

compiler/rustc_borrowck/src/type_check/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ pub(crate) fn type_check<'mir, 'tcx>(
225225
let mut hidden_type = infcx.resolve_vars_if_possible(decl.hidden_type);
226226
trace!("finalized opaque type {:?} to {:#?}", opaque_type_key, hidden_type.ty.kind());
227227
if hidden_type.has_non_region_infer() {
228-
let reported = infcx.tcx.sess.delay_span_bug(
228+
let reported = infcx.tcx.sess.span_delayed_bug(
229229
decl.hidden_type.span,
230230
format!("could not resolve {:#?}", hidden_type.ty.kind()),
231231
);
@@ -267,9 +267,9 @@ fn translate_outlives_facts(typeck: &mut TypeChecker<'_, '_>) {
267267
#[track_caller]
268268
fn mirbug(tcx: TyCtxt<'_>, span: Span, msg: String) {
269269
// We sometimes see MIR failures (notably predicate failures) due to
270-
// the fact that we check rvalue sized predicates here. So use `delay_span_bug`
270+
// the fact that we check rvalue sized predicates here. So use `span_delayed_bug`
271271
// to avoid reporting bugs in those cases.
272-
tcx.sess.diagnostic().delay_span_bug(span, msg);
272+
tcx.sess.diagnostic().span_delayed_bug(span, msg);
273273
}
274274

275275
enum FieldAccessError {
@@ -1068,7 +1068,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
10681068
);
10691069

10701070
if result.is_err() {
1071-
self.infcx.tcx.sess.delay_span_bug(
1071+
self.infcx.tcx.sess.span_delayed_bug(
10721072
self.body.span,
10731073
"failed re-defining predefined opaques in mir typeck",
10741074
);

compiler/rustc_builtin_macros/src/alloc_error_handler.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,7 @@ pub fn expand(
3131
{
3232
(item, true, ecx.with_def_site_ctxt(fn_kind.sig.span))
3333
} else {
34-
ecx.sess
35-
.parse_sess
36-
.span_diagnostic
37-
.emit_err(errors::AllocErrorMustBeFn { span: item.span() });
34+
ecx.sess.diagnostic().emit_err(errors::AllocErrorMustBeFn { span: item.span() });
3835
return vec![orig_item];
3936
};
4037

0 commit comments

Comments
 (0)