Skip to content

Commit

Permalink
Auto merge of rust-lang#118470 - nnethercote:cleanup-error-handlers, …
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
bors committed Dec 2, 2023
2 parents bd3a221 + 61f9356 commit 2da59b8
Show file tree
Hide file tree
Showing 170 changed files with 495 additions and 517 deletions.
6 changes: 3 additions & 3 deletions compiler/rustc_abi/src/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use crate::{
pub trait LayoutCalculator {
type TargetDataLayoutRef: Borrow<TargetDataLayout>;

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

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

align = align.max(field.align);
Expand Down Expand Up @@ -1038,7 +1038,7 @@ fn univariant<
for &i in &inverse_memory_index {
let field = &fields[i];
if !sized {
this.delay_bug(format!(
this.delayed_bug(format!(
"univariant: field #{} comes after unsized field",
offsets.len(),
));
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_ast_lowering/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
),
ExprKind::Yield(opt_expr) => self.lower_expr_yield(e.span, opt_expr.as_deref()),
ExprKind::Err => hir::ExprKind::Err(
self.tcx.sess.delay_span_bug(e.span, "lowered ExprKind::Err"),
self.tcx.sess.span_delayed_bug(e.span, "lowered ExprKind::Err"),
),
ExprKind::Try(sub_expr) => self.lower_expr_try(e.span, sub_expr),

Expand Down Expand Up @@ -799,7 +799,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
self.expr_ident_mut(span, task_context_ident, task_context_hid)
} else {
// Use of `await` outside of an async context, we cannot use `task_context` here.
self.expr_err(span, self.tcx.sess.delay_span_bug(span, "no task_context hir id"))
self.expr_err(span, self.tcx.sess.span_delayed_bug(span, "no task_context hir id"))
};
let new_unchecked = self.expr_call_lang_item_fn_mut(
span,
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_ast_lowering/src/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ fn make_count<'hir>(
ctx.expr(
sp,
hir::ExprKind::Err(
ctx.tcx.sess.delay_span_bug(sp, "lowered bad format_args count"),
ctx.tcx.sess.span_delayed_bug(sp, "lowered bad format_args count"),
),
)
}
Expand Down Expand Up @@ -306,7 +306,7 @@ fn make_format_spec<'hir>(
}
Err(_) => ctx.expr(
sp,
hir::ExprKind::Err(ctx.tcx.sess.delay_span_bug(sp, "lowered bad format_args count")),
hir::ExprKind::Err(ctx.tcx.sess.span_delayed_bug(sp, "lowered bad format_args count")),
),
};
let &FormatOptions {
Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_ast_lowering/src/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
&ImplTraitContext::Disallowed(ImplTraitPosition::Generic),
|this| match ty {
None => {
let guar = this.tcx.sess.delay_span_bug(
let guar = this.tcx.sess.span_delayed_bug(
span,
"expected to lower type alias type, but it was missing",
);
Expand Down Expand Up @@ -863,7 +863,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
&ImplTraitContext::Disallowed(ImplTraitPosition::Generic),
|this| match ty {
None => {
let guar = this.tcx.sess.delay_span_bug(
let guar = this.tcx.sess.span_delayed_bug(
i.span,
"expected to lower associated type, but it was missing",
);
Expand Down Expand Up @@ -996,7 +996,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
fn lower_block_expr_opt(&mut self, span: Span, block: Option<&Block>) -> hir::Expr<'hir> {
match block {
Some(block) => self.lower_block_expr(block),
None => self.expr_err(span, self.tcx.sess.delay_span_bug(span, "no block")),
None => self.expr_err(span, self.tcx.sess.span_delayed_bug(span, "no block")),
}
}

Expand All @@ -1006,7 +1006,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
&[],
match expr {
Some(expr) => this.lower_expr_mut(expr),
None => this.expr_err(span, this.tcx.sess.delay_span_bug(span, "no block")),
None => this.expr_err(span, this.tcx.sess.span_delayed_bug(span, "no block")),
},
)
})
Expand Down
19 changes: 8 additions & 11 deletions compiler/rustc_ast_lowering/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ use rustc_data_structures::fx::FxHashMap;
use rustc_data_structures::sorted_map::SortedMap;
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
use rustc_data_structures::sync::Lrc;
use rustc_errors::{DiagnosticArgFromDisplay, Handler, StashKey};
use rustc_errors::{DiagnosticArgFromDisplay, StashKey};
use rustc_hir as hir;
use rustc_hir::def::{DefKind, LifetimeRes, Namespace, PartialRes, PerNS, Res};
use rustc_hir::def_id::{LocalDefId, CRATE_DEF_ID, LOCAL_CRATE};
Expand Down Expand Up @@ -763,10 +763,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
self.resolver.get_import_res(id).present_items()
}

fn diagnostic(&self) -> &Handler {
self.tcx.sess.diagnostic()
}

/// Reuses the span but adds information like the kind of the desugaring and features that are
/// allowed inside this span.
fn mark_span_with_reason(
Expand Down Expand Up @@ -1326,7 +1322,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
let kind = match &t.kind {
TyKind::Infer => hir::TyKind::Infer,
TyKind::Err => {
hir::TyKind::Err(self.tcx.sess.delay_span_bug(t.span, "TyKind::Err lowered"))
hir::TyKind::Err(self.tcx.sess.span_delayed_bug(t.span, "TyKind::Err lowered"))
}
// FIXME(unnamed_fields): IMPLEMENTATION IN PROGRESS
#[allow(rustc::untranslatable_diagnostic)]
Expand Down Expand Up @@ -1510,7 +1506,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
}
TyKind::MacCall(_) => panic!("`TyKind::MacCall` should have been expanded by now"),
TyKind::CVarArgs => {
let guar = self.tcx.sess.delay_span_bug(
let guar = self.tcx.sess.span_delayed_bug(
t.span,
"`TyKind::CVarArgs` should have been handled elsewhere",
);
Expand Down Expand Up @@ -1653,7 +1649,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
} else {
self.tcx
.sess
.delay_span_bug(lifetime.ident.span, "no def-id for fresh lifetime");
.span_delayed_bug(lifetime.ident.span, "no def-id for fresh lifetime");
continue;
}
}
Expand Down Expand Up @@ -2515,9 +2511,10 @@ impl<'hir> GenericArgsCtor<'hir> {
let hir_id = lcx.next_id();

let Some(host_param_id) = lcx.host_param_id else {
lcx.tcx
.sess
.delay_span_bug(span, "no host param id for call in const yet no errors reported");
lcx.tcx.sess.span_delayed_bug(
span,
"no host param id for call in const yet no errors reported",
);
return;
};

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_ast_lowering/src/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {

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

self.diagnostic().span_bug(
self.tcx.sess.diagnostic().span_bug(
p.span,
format!(
"lower_qpath: no final extension segment in {}..{}",
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_ast_passes/src/feature_gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ impl<'a> PostExpansionVisitor<'a> {
}
Err(abi::AbiDisabled::Unrecognized) => {
if self.sess.opts.pretty.map_or(true, |ppm| ppm.needs_hir()) {
self.sess.parse_sess.span_diagnostic.delay_span_bug(
self.sess.diagnostic().span_delayed_bug(
span,
format!(
"unrecognized ABI not caught in lowering: {}",
Expand Down Expand Up @@ -627,7 +627,7 @@ fn maybe_stage_features(sess: &Session, features: &Features, krate: &ast::Crate)
if all_stable {
err.sugg = Some(attr.span);
}
sess.parse_sess.span_diagnostic.emit_err(err);
sess.diagnostic().emit_err(err);
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_attr/src/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -945,7 +945,7 @@ pub fn parse_repr_attr(sess: &Session, attr: &Attribute) -> Vec<ReprAttr> {
assert!(attr.has_name(sym::repr), "expected `#[repr(..)]`, found: {attr:?}");
use ReprAttr::*;
let mut acc = Vec::new();
let diagnostic = &sess.parse_sess.span_diagnostic;
let diagnostic = sess.diagnostic();

if let Some(items) = attr.meta_item_list() {
for item in items {
Expand Down Expand Up @@ -1060,9 +1060,9 @@ pub fn parse_repr_attr(sess: &Session, attr: &Attribute) -> Vec<ReprAttr> {
// Not a word we recognize. This will be caught and reported by
// the `check_mod_attrs` pass, but this pass doesn't always run
// (e.g. if we only pretty-print the source), so we have to gate
// the `delay_span_bug` call as follows:
// the `span_delayed_bug` call as follows:
if sess.opts.pretty.map_or(true, |pp| pp.needs_analysis()) {
diagnostic.delay_span_bug(item.span(), "unrecognized representation hint");
diagnostic.span_delayed_bug(item.span(), "unrecognized representation hint");
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ fn try_extract_error_from_fulfill_cx<'tcx>(
error_region: Option<ty::Region<'tcx>>,
) -> Option<DiagnosticBuilder<'tcx, ErrorGuaranteed>> {
// We generally shouldn't have errors here because the query was
// already run, but there's no point using `delay_span_bug`
// already run, but there's no point using `span_delayed_bug`
// when we're going to emit an error here anyway.
let _errors = ocx.select_all_or_error();
let region_constraints = ocx.infcx.with_region_constraints(|r| r.clone());
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1135,7 +1135,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
});
} else {
issued_spans.var_subdiag(
Some(&self.infcx.tcx.sess.parse_sess.span_diagnostic),
Some(self.infcx.tcx.sess.diagnostic()),
&mut err,
Some(issued_borrow.kind),
|kind, var_span| {
Expand All @@ -1152,7 +1152,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
);

borrow_spans.var_subdiag(
Some(&self.infcx.tcx.sess.parse_sess.span_diagnostic),
Some(self.infcx.tcx.sess.diagnostic()),
&mut err,
Some(gen_borrow_kind),
|kind, var_span| {
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_borrowck/src/diagnostics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
let did = did.expect_local();
if let Some((span, hir_place)) = self.infcx.tcx.closure_kind_origin(did) {
diag.eager_subdiagnostic(
&self.infcx.tcx.sess.parse_sess.span_diagnostic,
self.infcx.tcx.sess.diagnostic(),
OnClosureNote::InvokedTwice {
place_name: &ty::place_to_string_for_capture(
self.infcx.tcx,
Expand All @@ -146,7 +146,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
let did = did.expect_local();
if let Some((span, hir_place)) = self.infcx.tcx.closure_kind_origin(did) {
diag.eager_subdiagnostic(
&self.infcx.tcx.sess.parse_sess.span_diagnostic,
self.infcx.tcx.sess.diagnostic(),
OnClosureNote::MovedTwice {
place_name: &ty::place_to_string_for_capture(self.infcx.tcx, hir_place),
span: *span,
Expand Down Expand Up @@ -1119,7 +1119,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
&& self.infcx.can_eq(self.param_env, ty, self_ty)
{
err.eager_subdiagnostic(
&self.infcx.tcx.sess.parse_sess.span_diagnostic,
self.infcx.tcx.sess.diagnostic(),
CaptureReasonSuggest::FreshReborrow {
span: move_span.shrink_to_hi(),
},
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_borrowck/src/diagnostics/region_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ impl<'tcx> RegionErrors<'tcx> {
#[track_caller]
pub fn push(&mut self, val: impl Into<RegionErrorKind<'tcx>>) {
let val = val.into();
self.1.sess.delay_span_bug(DUMMY_SP, format!("{val:?}"));
self.1.sess.span_delayed_bug(DUMMY_SP, format!("{val:?}"));
self.0.push(val);
}
pub fn is_empty(&self) -> bool {
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_borrowck/src/diagnostics/region_name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -619,8 +619,8 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
_,
) => {
// HIR lowering sometimes doesn't catch this in erroneous
// programs, so we need to use delay_span_bug here. See #82126.
self.infcx.tcx.sess.delay_span_bug(
// programs, so we need to use span_delayed_bug here. See #82126.
self.infcx.tcx.sess.span_delayed_bug(
hir_arg.span(),
format!("unmatched arg and hir arg: found {kind:?} vs {hir_arg:?}"),
);
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_borrowck/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2130,11 +2130,11 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
&& !self.has_buffered_errors()
{
// rust-lang/rust#46908: In pure NLL mode this code path should be
// unreachable, but we use `delay_span_bug` because we can hit this when
// unreachable, but we use `span_delayed_bug` because we can hit this when
// dereferencing a non-Copy raw pointer *and* have `-Ztreat-err-as-bug`
// enabled. We don't want to ICE for that case, as other errors will have
// been emitted (#52262).
self.infcx.tcx.sess.delay_span_bug(
self.infcx.tcx.sess.span_delayed_bug(
span,
format!(
"Accessing `{place:?}` with the kind `{kind:?}` shouldn't be possible",
Expand Down Expand Up @@ -2428,7 +2428,7 @@ mod error {

pub fn buffer_error(&mut self, t: DiagnosticBuilder<'_, ErrorGuaranteed>) {
if let None = self.tainted_by_errors {
self.tainted_by_errors = Some(self.tcx.sess.delay_span_bug(
self.tainted_by_errors = Some(self.tcx.sess.span_delayed_bug(
t.span.clone_ignoring_labels(),
"diagnostic buffered but not emitted",
))
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_borrowck/src/nll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ pub(crate) fn compute_regions<'cx, 'tcx>(

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

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

regioncx.annotate(tcx, &mut err);

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

err
} else {
let mut err = tcx.sess.diagnostic().span_note_diag(def_span, "no external requirements");
let mut err = tcx.sess.diagnostic().struct_span_note(def_span, "no external requirements");
regioncx.annotate(tcx, &mut err);

err
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_borrowck/src/type_check/input_output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
if argument_index + 1 >= body.local_decls.len() {
self.tcx()
.sess
.delay_span_bug(body.span, "found more normalized_input_ty than local_decls");
.span_delayed_bug(body.span, "found more normalized_input_ty than local_decls");
break;
}

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

// We will not have a universal_regions.yield_ty if we yield (by accident)
// outside of a coroutine and return an `impl Trait`, so emit a delay_span_bug
// outside of a coroutine and return an `impl Trait`, so emit a span_delayed_bug
// because we don't want to panic in an assert here if we've already got errors.
if body.yield_ty().is_some() != universal_regions.yield_ty.is_some() {
self.tcx().sess.delay_span_bug(
self.tcx().sess.span_delayed_bug(
body.span,
format!(
"Expected body to have yield_ty ({:?}) iff we have a UR yield_ty ({:?})",
Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_borrowck/src/type_check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ pub(crate) fn type_check<'mir, 'tcx>(
let mut hidden_type = infcx.resolve_vars_if_possible(decl.hidden_type);
trace!("finalized opaque type {:?} to {:#?}", opaque_type_key, hidden_type.ty.kind());
if hidden_type.has_non_region_infer() {
let reported = infcx.tcx.sess.delay_span_bug(
let reported = infcx.tcx.sess.span_delayed_bug(
decl.hidden_type.span,
format!("could not resolve {:#?}", hidden_type.ty.kind()),
);
Expand Down Expand Up @@ -267,9 +267,9 @@ fn translate_outlives_facts(typeck: &mut TypeChecker<'_, '_>) {
#[track_caller]
fn mirbug(tcx: TyCtxt<'_>, span: Span, msg: String) {
// We sometimes see MIR failures (notably predicate failures) due to
// the fact that we check rvalue sized predicates here. So use `delay_span_bug`
// the fact that we check rvalue sized predicates here. So use `span_delayed_bug`
// to avoid reporting bugs in those cases.
tcx.sess.diagnostic().delay_span_bug(span, msg);
tcx.sess.diagnostic().span_delayed_bug(span, msg);
}

enum FieldAccessError {
Expand Down Expand Up @@ -1068,7 +1068,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
);

if result.is_err() {
self.infcx.tcx.sess.delay_span_bug(
self.infcx.tcx.sess.span_delayed_bug(
self.body.span,
"failed re-defining predefined opaques in mir typeck",
);
Expand Down
5 changes: 1 addition & 4 deletions compiler/rustc_builtin_macros/src/alloc_error_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,7 @@ pub fn expand(
{
(item, true, ecx.with_def_site_ctxt(fn_kind.sig.span))
} else {
ecx.sess
.parse_sess
.span_diagnostic
.emit_err(errors::AllocErrorMustBeFn { span: item.span() });
ecx.sess.diagnostic().emit_err(errors::AllocErrorMustBeFn { span: item.span() });
return vec![orig_item];
};

Expand Down
Loading

0 comments on commit 2da59b8

Please sign in to comment.