Skip to content

Commit

Permalink
delay_bug_unless_*
Browse files Browse the repository at this point in the history
  • Loading branch information
compiler-errors committed Feb 23, 2023
1 parent 1a3fad5 commit 23a797d
Show file tree
Hide file tree
Showing 110 changed files with 331 additions and 267 deletions.
2 changes: 1 addition & 1 deletion compiler/rustc_ast_lowering/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1404,7 +1404,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
}
TyKind::MacCall(_) => panic!("`TyKind::MacCall` should have been expanded by now"),
TyKind::CVarArgs => {
self.tcx.sess.delay_span_bug(
self.tcx.sess.delay_bug_unless_error(
t.span,
"`TyKind::CVarArgs` should have been handled elsewhere",
);
Expand Down
2 changes: 1 addition & 1 deletion 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.parse_sess.span_diagnostic.delay_bug_unless_error(
span,
&format!(
"unrecognized ABI not caught in lowering: {}",
Expand Down
5 changes: 3 additions & 2 deletions compiler/rustc_attr/src/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1092,9 +1092,10 @@ 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 `delay_bug_unless_error` call as follows:
if sess.opts.pretty.map_or(true, |pp| pp.needs_analysis()) {
diagnostic.delay_span_bug(item.span(), "unrecognized representation hint");
diagnostic
.delay_bug_unless_error(item.span(), "unrecognized representation hint");
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,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 `delay_bug_unless_error`
// 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
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.delay_bug_unless_error(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 delay_bug_unless_error here. See #82126.
self.infcx.tcx.sess.delay_bug_unless_error(
hir_arg.span(),
&format!("unmatched subst and hir arg: found {kind:?} vs {hir_arg:?}"),
);
Expand Down
14 changes: 7 additions & 7 deletions compiler/rustc_borrowck/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2054,11 +2054,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 `delay_bug_unless_error` 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.delay_bug_unless_error(
span,
&format!(
"Accessing `{:?}` with the kind `{:?}` shouldn't be possible",
Expand Down Expand Up @@ -2354,11 +2354,11 @@ 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(t.span.clone(), "diagnostic buffered but not emitted"),
)
self.tainted_by_errors =
Some(self.tcx.sess.delay_bug_unless_error(
t.span.clone(),
"diagnostic buffered but not emitted",
))
}
t.buffer(&mut self.buffered);
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_borrowck/src/nll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,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.delay_bug_unless_error(
body.span,
"`compute_regions` tainted `infcx` with errors but did not emit any errors",
));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ impl<'tcx> UniversalRegionRelationsBuilder<'_, 'tcx> {
.infcx
.tcx
.sess
.delay_span_bug(span, &format!("failed to normalize {:?}", ty));
.delay_bug_unless_error(span, &format!("failed to normalize {:?}", ty));
TypeOpOutput {
output: self.infcx.tcx.ty_error(guar),
constraints: None,
Expand Down
11 changes: 6 additions & 5 deletions compiler/rustc_borrowck/src/type_check/input_output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,10 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
// Equate expected input tys with those in the MIR.
for (argument_index, &normalized_input_ty) in normalized_input_tys.iter().enumerate() {
if argument_index + 1 >= body.local_decls.len() {
self.tcx()
.sess
.delay_span_bug(body.span, "found more normalized_input_ty than local_decls");
self.tcx().sess.delay_bug_unless_error(
body.span,
"found more normalized_input_ty than local_decls",
);
break;
}

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

// We will not have a universal_regions.yield_ty if we yield (by accident)
// outside of a generator and return an `impl Trait`, so emit a delay_span_bug
// outside of a generator and return an `impl Trait`, so emit a delay_bug_unless_error
// 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.delay_bug_unless_error(
body.span,
&format!(
"Expected body to have yield_ty ({:?}) iff we have a UR yield_ty ({:?})",
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_borrowck/src/type_check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,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.delay_bug_unless_error(
decl.hidden_type.span,
&format!("could not resolve {:#?}", hidden_type.ty.kind()),
);
Expand Down Expand Up @@ -277,9 +277,9 @@ fn translate_outlives_facts(typeck: &mut TypeChecker<'_, '_>) {
#[track_caller]
fn mirbug(tcx: TyCtxt<'_>, span: Span, msg: &str) {
// 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 `delay_bug_unless_error`
// to avoid reporting bugs in those cases.
tcx.sess.diagnostic().delay_span_bug(span, msg);
tcx.sess.diagnostic().delay_bug_unless_error(span, msg);
}

enum FieldAccessError {
Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_codegen_ssa/src/codegen_attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: DefId) -> CodegenFnAttrs {
if let DefKind::Fn | DefKind::AssocFn | DefKind::Variant | DefKind::Ctor(..) = def_kind {
true
} else {
tcx.sess.delay_span_bug(attr_sp, "this attribute can only be applied to functions");
tcx.sess
.delay_bug_unless_error(attr_sp, "this attribute can only be applied to functions");
false
}
};
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_const_eval/src/const_eval/machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir,
if ecx.tcx.is_ctfe_mir_available(def.did) {
Ok(ecx.tcx.mir_for_ctfe_opt_const_arg(def))
} else if ecx.tcx.def_kind(def.did) == DefKind::AssocConst {
let guar = ecx.tcx.sess.delay_span_bug(
let guar = ecx.tcx.sess.delay_bug_unless_error(
rustc_span::DUMMY_SP,
"This is likely a const item that is missing from its impl",
);
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_const_eval/src/interpret/eval_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ impl<'tcx> fmt::Display for FrameInfo<'tcx> {
{
write!(f, "inside closure")
} else {
// Note: this triggers a `bug_unless_diagnostic_emitted` state, which means
// Note: this triggers a `bug_unless_diagnostic` state, which means
// that if we ever get here we must emit a diagnostic. We should never display
// a `FrameInfo` unless we actually want to emit a warning or error to the user.
write!(f, "inside `{}`", self.instance)
Expand Down Expand Up @@ -509,7 +509,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
.instance
.try_subst_mir_and_normalize_erasing_regions(*self.tcx, self.param_env, value)
.map_err(|e| {
self.tcx.sess.delay_span_bug(
self.tcx.sess.delay_bug_unless_error(
self.cur_span(),
format!("failed to normalize {}", e.get_type_for_failure()).as_str(),
);
Expand Down
12 changes: 7 additions & 5 deletions compiler/rustc_const_eval/src/interpret/intern.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ fn intern_shallow<'rt, 'mir, 'tcx, M: CompileTimeMachine<'mir, 'tcx, const_eval:
// If the pointer is dangling (neither in local nor global memory), we leave it
// to validation to error -- it has the much better error messages, pointing out where
// in the value the dangling reference lies.
// The `delay_span_bug` ensures that we don't forget such a check in validation.
// The `delay_bug_unless_error` ensures that we don't forget such a check in validation.
if tcx.try_get_global_alloc(alloc_id).is_none() {
tcx.sess.delay_span_bug(ecx.tcx.span, "tried to intern dangling pointer");
tcx.sess.delay_bug_unless_error(ecx.tcx.span, "tried to intern dangling pointer");
}
// treat dangling pointers like other statics
// just to stop trying to recurse into them
Expand Down Expand Up @@ -253,8 +253,10 @@ impl<'rt, 'mir, 'tcx: 'mir, M: CompileTimeMachine<'mir, 'tcx, const_eval::Memory
} else {
// Validation will error (with a better message) on an invalid vtable pointer.
// Let validation show the error message, but make sure it *does* error.
tcx.sess
.delay_span_bug(tcx.span, "vtables pointers cannot be integer pointers");
tcx.sess.delay_bug_unless_error(
tcx.span,
"vtables pointers cannot be integer pointers",
);
}
}
// Check if we have encountered this pointer+layout combination before.
Expand Down Expand Up @@ -385,7 +387,7 @@ pub fn intern_const_alloc_recursive<
match res {
Ok(()) => {}
Err(error) => {
ecx.tcx.sess.delay_span_bug(
ecx.tcx.sess.delay_bug_unless_error(
ecx.tcx.span,
&format!(
"error during interning should later cause validation failure: {}",
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_const_eval/src/interpret/step.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
let layout = self.layout_of(ty)?;
if layout.is_unsized() {
// FIXME: This should be a span_bug (#80742)
self.tcx.sess.delay_span_bug(
self.tcx.sess.delay_bug_unless_error(
self.frame().current_span(),
&format!("Nullary MIR operator called for unsized type {}", ty),
);
Expand Down
6 changes: 4 additions & 2 deletions compiler/rustc_const_eval/src/transform/check_consts/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ impl<'mir, 'tcx> Checker<'mir, 'tcx> {
// `async` functions cannot be `const fn`. This is checked during AST lowering, so there's
// no need to emit duplicate errors here.
if self.ccx.is_async() || body.generator.is_some() {
tcx.sess.delay_span_bug(body.span, "`async` functions cannot be `const fn`");
tcx.sess.delay_bug_unless_error(body.span, "`async` functions cannot be `const fn`");
return;
}

Expand Down Expand Up @@ -332,7 +332,9 @@ impl<'mir, 'tcx> Checker<'mir, 'tcx> {

fn check_static(&mut self, def_id: DefId, span: Span) {
if self.tcx.is_thread_local_static(def_id) {
self.tcx.sess.delay_span_bug(span, "tls access is checked in `Rvalue::ThreadLocalRef");
self.tcx
.sess
.delay_bug_unless_error(span, "tls access is checked in `Rvalue::ThreadLocalRef");
}
self.check_op_spanned(ops::StaticAccess, span)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ pub fn is_const_stable_const_fn(tcx: TyCtxt<'_>, def_id: DefId) -> bool {
None if is_parent_const_stable_trait(tcx, def_id) => {
// Remove this when `#![feature(const_trait_impl)]` is stabilized,
// returning `true` unconditionally.
tcx.sess.delay_span_bug(
tcx.sess.delay_bug_unless_error(
tcx.def_span(def_id),
"trait implementations cannot be const stable yet",
);
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_const_eval/src/transform/validate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
#[track_caller]
fn fail(&self, location: Location, msg: impl AsRef<str>) {
let span = self.body.source_info(location).span;
// We use `delay_span_bug` as we might see broken MIR when other errors have already
// We use `delay_bug_unless_error` as we might see broken MIR when other errors have already
// occurred.
self.tcx.sess.diagnostic().delay_span_bug(
self.tcx.sess.diagnostic().delay_bug_unless_error(
span,
&format!(
"broken MIR in {:?} ({}) at {:?}:\n{}",
Expand Down Expand Up @@ -958,7 +958,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {

fn visit_source_scope(&mut self, scope: SourceScope) {
if self.body.source_scopes.get(scope).is_none() {
self.tcx.sess.diagnostic().delay_span_bug(
self.tcx.sess.diagnostic().delay_bug_unless_error(
self.body.span,
&format!(
"broken MIR in {:?} ({}):\ninvalid source scope {:?}",
Expand Down
Loading

0 comments on commit 23a797d

Please sign in to comment.