From 23a797dd82f6082d19ad372f33cf2f2819da1f70 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Thu, 23 Feb 2023 20:41:02 +0000 Subject: [PATCH] delay_bug_unless_* --- compiler/rustc_ast_lowering/src/lib.rs | 2 +- compiler/rustc_ast_passes/src/feature_gate.rs | 2 +- compiler/rustc_attr/src/builtin.rs | 5 +- .../src/diagnostics/bound_region_errors.rs | 2 +- .../src/diagnostics/region_errors.rs | 2 +- .../src/diagnostics/region_name.rs | 4 +- compiler/rustc_borrowck/src/lib.rs | 14 ++--- compiler/rustc_borrowck/src/nll.rs | 2 +- .../src/type_check/free_region_relations.rs | 2 +- .../src/type_check/input_output.rs | 11 ++-- compiler/rustc_borrowck/src/type_check/mod.rs | 6 +- .../rustc_codegen_ssa/src/codegen_attrs.rs | 3 +- .../src/const_eval/machine.rs | 2 +- .../src/interpret/eval_context.rs | 4 +- .../rustc_const_eval/src/interpret/intern.rs | 12 ++-- .../rustc_const_eval/src/interpret/step.rs | 2 +- .../src/transform/check_consts/check.rs | 6 +- .../src/transform/check_consts/mod.rs | 2 +- .../src/transform/validate.rs | 6 +- compiler/rustc_errors/src/lib.rs | 55 +++++++++++-------- compiler/rustc_expand/src/expand.rs | 2 +- compiler/rustc_expand/src/mbe/diagnostics.rs | 7 ++- .../rustc_hir_analysis/src/astconv/mod.rs | 11 ++-- .../rustc_hir_analysis/src/check/check.rs | 16 ++++-- .../src/check/compare_impl_item.rs | 9 +-- .../rustc_hir_analysis/src/check/dropck.rs | 2 +- .../src/check/intrinsicck.rs | 2 +- .../rustc_hir_analysis/src/check/wfcheck.rs | 6 +- .../src/coherence/unsafety.rs | 2 +- .../src/collect/resolve_bound_vars.rs | 11 ++-- .../rustc_hir_analysis/src/collect/type_of.rs | 10 ++-- .../rustc_hir_analysis/src/hir_wf_check.rs | 8 ++- .../rustc_hir_analysis/src/impl_wf_check.rs | 2 +- compiler/rustc_hir_typeck/src/callee.rs | 4 +- compiler/rustc_hir_typeck/src/cast.rs | 8 +-- compiler/rustc_hir_typeck/src/coercion.rs | 4 +- compiler/rustc_hir_typeck/src/demand.rs | 2 +- compiler/rustc_hir_typeck/src/expr.rs | 14 +++-- .../rustc_hir_typeck/src/expr_use_visitor.rs | 4 +- .../rustc_hir_typeck/src/fn_ctxt/_impl.rs | 4 +- .../rustc_hir_typeck/src/fn_ctxt/checks.rs | 8 ++- .../drop_ranges/cfg_build.rs | 7 ++- .../drop_ranges/record_consumed_borrow.rs | 2 +- .../src/generator_interior/mod.rs | 6 +- compiler/rustc_hir_typeck/src/intrinsicck.rs | 2 +- .../src/mem_categorization.rs | 13 +++-- compiler/rustc_hir_typeck/src/method/mod.rs | 4 +- .../rustc_hir_typeck/src/method/suggest.rs | 2 +- compiler/rustc_hir_typeck/src/op.rs | 7 ++- compiler/rustc_hir_typeck/src/pat.rs | 9 ++- compiler/rustc_hir_typeck/src/writeback.rs | 6 +- .../src/infer/canonical/canonicalizer.rs | 4 +- compiler/rustc_infer/src/infer/combine.rs | 2 +- .../src/infer/lexical_region_resolve/mod.rs | 2 +- compiler/rustc_infer/src/infer/mod.rs | 2 +- .../rustc_infer/src/infer/nll_relate/mod.rs | 4 +- .../src/infer/opaque_types/table.rs | 2 +- .../src/infer/outlives/obligations.rs | 2 +- .../rustc_infer/src/infer/outlives/verify.rs | 2 +- compiler/rustc_lint/src/early.rs | 2 +- compiler/rustc_middle/src/macros.rs | 8 +-- compiler/rustc_middle/src/middle/stability.rs | 5 +- .../src/mir/interpret/allocation.rs | 2 +- .../rustc_middle/src/mir/interpret/mod.rs | 2 +- compiler/rustc_middle/src/ty/adt.rs | 2 +- compiler/rustc_middle/src/ty/consts.rs | 2 +- compiler/rustc_middle/src/ty/context.rs | 24 ++++---- compiler/rustc_middle/src/ty/layout.rs | 2 +- compiler/rustc_middle/src/ty/print/pretty.rs | 2 +- .../rustc_middle/src/ty/typeck_results.rs | 2 +- compiler/rustc_middle/src/util/bug.rs | 6 +- .../src/build/expr/as_constant.rs | 7 ++- .../rustc_mir_build/src/check_unsafety.rs | 2 +- compiler/rustc_mir_build/src/thir/constant.rs | 5 +- .../rustc_mir_build/src/thir/pattern/mod.rs | 4 +- .../rustc_mir_transform/src/check_unsafety.rs | 2 +- .../src/elaborate_drops.rs | 6 +- compiler/rustc_mir_transform/src/generator.rs | 8 ++- compiler/rustc_mir_transform/src/lib.rs | 2 +- .../rustc_parse/src/parser/attr_wrapper.rs | 4 +- compiler/rustc_parse/src/parser/pat.rs | 4 +- compiler/rustc_passes/src/entry.rs | 2 +- compiler/rustc_passes/src/hir_id_validator.rs | 2 +- compiler/rustc_privacy/src/lib.rs | 4 +- compiler/rustc_resolve/src/ident.rs | 4 +- compiler/rustc_resolve/src/late.rs | 2 +- compiler/rustc_resolve/src/macros.rs | 4 +- compiler/rustc_session/src/config.rs | 4 +- compiler/rustc_session/src/options.rs | 2 +- compiler/rustc_session/src/session.rs | 12 ++-- .../src/solve/project_goals.rs | 2 +- .../src/traits/coherence.rs | 2 +- .../src/traits/const_evaluatable.rs | 12 ++-- .../src/traits/error_reporting/mod.rs | 8 +-- .../error_reporting/on_unimplemented.rs | 5 +- .../rustc_trait_selection/src/traits/misc.rs | 2 +- .../rustc_trait_selection/src/traits/mod.rs | 2 +- .../src/traits/object_safety.rs | 8 +-- .../src/traits/outlives_bounds.rs | 4 +- .../src/traits/project.rs | 2 +- .../src/traits/query/normalize.rs | 4 +- .../src/traits/query/type_op/custom.rs | 2 +- .../src/traits/select/confirmation.rs | 2 +- .../src/traits/select/mod.rs | 2 +- .../src/traits/specialize/mod.rs | 24 ++++---- .../src/traits/structural_match.rs | 4 +- compiler/rustc_traits/src/dropck_outlives.rs | 4 +- compiler/rustc_ty_utils/src/instance.rs | 4 +- compiler/rustc_ty_utils/src/layout.rs | 6 +- compiler/rustc_ty_utils/src/needs_drop.rs | 2 +- 110 files changed, 331 insertions(+), 267 deletions(-) diff --git a/compiler/rustc_ast_lowering/src/lib.rs b/compiler/rustc_ast_lowering/src/lib.rs index c5b144e68dc7e..bc05ac5771ff2 100644 --- a/compiler/rustc_ast_lowering/src/lib.rs +++ b/compiler/rustc_ast_lowering/src/lib.rs @@ -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", ); diff --git a/compiler/rustc_ast_passes/src/feature_gate.rs b/compiler/rustc_ast_passes/src/feature_gate.rs index d69c84bf4d1d2..9ca6f3e10b962 100644 --- a/compiler/rustc_ast_passes/src/feature_gate.rs +++ b/compiler/rustc_ast_passes/src/feature_gate.rs @@ -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: {}", diff --git a/compiler/rustc_attr/src/builtin.rs b/compiler/rustc_attr/src/builtin.rs index 3d240108b4ab1..d238080139118 100644 --- a/compiler/rustc_attr/src/builtin.rs +++ b/compiler/rustc_attr/src/builtin.rs @@ -1092,9 +1092,10 @@ pub fn parse_repr_attr(sess: &Session, attr: &Attribute) -> Vec { // 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"); } } } diff --git a/compiler/rustc_borrowck/src/diagnostics/bound_region_errors.rs b/compiler/rustc_borrowck/src/diagnostics/bound_region_errors.rs index 68205fa45587b..2f4dd0df97822 100644 --- a/compiler/rustc_borrowck/src/diagnostics/bound_region_errors.rs +++ b/compiler/rustc_borrowck/src/diagnostics/bound_region_errors.rs @@ -380,7 +380,7 @@ fn try_extract_error_from_fulfill_cx<'tcx>( error_region: Option>, ) -> Option> { // 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()); diff --git a/compiler/rustc_borrowck/src/diagnostics/region_errors.rs b/compiler/rustc_borrowck/src/diagnostics/region_errors.rs index 4baf1b6aa8701..505b561c537bc 100644 --- a/compiler/rustc_borrowck/src/diagnostics/region_errors.rs +++ b/compiler/rustc_borrowck/src/diagnostics/region_errors.rs @@ -84,7 +84,7 @@ impl<'tcx> RegionErrors<'tcx> { #[track_caller] pub fn push(&mut self, val: impl Into>) { 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 { diff --git a/compiler/rustc_borrowck/src/diagnostics/region_name.rs b/compiler/rustc_borrowck/src/diagnostics/region_name.rs index f6881a2e5bc87..c798e44512077 100644 --- a/compiler/rustc_borrowck/src/diagnostics/region_name.rs +++ b/compiler/rustc_borrowck/src/diagnostics/region_name.rs @@ -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:?}"), ); diff --git a/compiler/rustc_borrowck/src/lib.rs b/compiler/rustc_borrowck/src/lib.rs index 18d7bde60d789..58037ef21768a 100644 --- a/compiler/rustc_borrowck/src/lib.rs +++ b/compiler/rustc_borrowck/src/lib.rs @@ -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", @@ -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); } diff --git a/compiler/rustc_borrowck/src/nll.rs b/compiler/rustc_borrowck/src/nll.rs index e5dbb83dd0728..4022a6587e4f0 100644 --- a/compiler/rustc_borrowck/src/nll.rs +++ b/compiler/rustc_borrowck/src/nll.rs @@ -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", )); diff --git a/compiler/rustc_borrowck/src/type_check/free_region_relations.rs b/compiler/rustc_borrowck/src/type_check/free_region_relations.rs index e2f897a89e82e..ffd0628412c82 100644 --- a/compiler/rustc_borrowck/src/type_check/free_region_relations.rs +++ b/compiler/rustc_borrowck/src/type_check/free_region_relations.rs @@ -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, diff --git a/compiler/rustc_borrowck/src/type_check/input_output.rs b/compiler/rustc_borrowck/src/type_check/input_output.rs index c6b78df9a5ff0..2e592b6c877ae 100644 --- a/compiler/rustc_borrowck/src/type_check/input_output.rs +++ b/compiler/rustc_borrowck/src/type_check/input_output.rs @@ -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; } @@ -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 ({:?})", diff --git a/compiler/rustc_borrowck/src/type_check/mod.rs b/compiler/rustc_borrowck/src/type_check/mod.rs index c4e7e1f8ffa30..78e7f95e1ab0e 100644 --- a/compiler/rustc_borrowck/src/type_check/mod.rs +++ b/compiler/rustc_borrowck/src/type_check/mod.rs @@ -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()), ); @@ -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 { diff --git a/compiler/rustc_codegen_ssa/src/codegen_attrs.rs b/compiler/rustc_codegen_ssa/src/codegen_attrs.rs index 7d5c0048626c9..4b27cc5021125 100644 --- a/compiler/rustc_codegen_ssa/src/codegen_attrs.rs +++ b/compiler/rustc_codegen_ssa/src/codegen_attrs.rs @@ -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 } }; diff --git a/compiler/rustc_const_eval/src/const_eval/machine.rs b/compiler/rustc_const_eval/src/const_eval/machine.rs index a44f70ed05906..8e29c3070ecd1 100644 --- a/compiler/rustc_const_eval/src/const_eval/machine.rs +++ b/compiler/rustc_const_eval/src/const_eval/machine.rs @@ -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", ); diff --git a/compiler/rustc_const_eval/src/interpret/eval_context.rs b/compiler/rustc_const_eval/src/interpret/eval_context.rs index d349426412507..a0a1ccc1bd865 100644 --- a/compiler/rustc_const_eval/src/interpret/eval_context.rs +++ b/compiler/rustc_const_eval/src/interpret/eval_context.rs @@ -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) @@ -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(), ); diff --git a/compiler/rustc_const_eval/src/interpret/intern.rs b/compiler/rustc_const_eval/src/interpret/intern.rs index 21ef1836188c0..56e047ffad7f8 100644 --- a/compiler/rustc_const_eval/src/interpret/intern.rs +++ b/compiler/rustc_const_eval/src/interpret/intern.rs @@ -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 @@ -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. @@ -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: {}", diff --git a/compiler/rustc_const_eval/src/interpret/step.rs b/compiler/rustc_const_eval/src/interpret/step.rs index 6863435e50878..a9f4dd204dc7f 100644 --- a/compiler/rustc_const_eval/src/interpret/step.rs +++ b/compiler/rustc_const_eval/src/interpret/step.rs @@ -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), ); diff --git a/compiler/rustc_const_eval/src/transform/check_consts/check.rs b/compiler/rustc_const_eval/src/transform/check_consts/check.rs index e4366f655e471..e40b8f497241b 100644 --- a/compiler/rustc_const_eval/src/transform/check_consts/check.rs +++ b/compiler/rustc_const_eval/src/transform/check_consts/check.rs @@ -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; } @@ -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) } diff --git a/compiler/rustc_const_eval/src/transform/check_consts/mod.rs b/compiler/rustc_const_eval/src/transform/check_consts/mod.rs index 0e4501922f416..8f7f585fea710 100644 --- a/compiler/rustc_const_eval/src/transform/check_consts/mod.rs +++ b/compiler/rustc_const_eval/src/transform/check_consts/mod.rs @@ -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", ); diff --git a/compiler/rustc_const_eval/src/transform/validate.rs b/compiler/rustc_const_eval/src/transform/validate.rs index 3af2d0c4e668a..d57fe97b09cd7 100644 --- a/compiler/rustc_const_eval/src/transform/validate.rs +++ b/compiler/rustc_const_eval/src/transform/validate.rs @@ -92,9 +92,9 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { #[track_caller] fn fail(&self, location: Location, msg: impl AsRef) { 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{}", @@ -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 {:?}", diff --git a/compiler/rustc_errors/src/lib.rs b/compiler/rustc_errors/src/lib.rs index 51e7632eec7fd..b630f4030c952 100644 --- a/compiler/rustc_errors/src/lib.rs +++ b/compiler/rustc_errors/src/lib.rs @@ -409,11 +409,12 @@ struct HandlerInner { warn_count: usize, deduplicated_err_count: usize, emitter: Box, - delayed_span_bugs: Vec, - /// Bugs that are delayed unless a diagnostic (warn/lint/error) is emitted. + /// Bugs that are delayed unless an error is emitted. + delayed_expected_error_bugs: Vec, + /// Bugs that are delayed unless any diagnostic (warn/lint/error) is emitted. delayed_expect_diagnostic_bugs: Vec, /// This flag indicates that an expected diagnostic was emitted and suppressed. - /// This is used for the `delayed_bugs_unless_diagnostic_emitted` check. + /// This is used for the `delayed_bugs_unless_diagnostic` check. suppressed_expected_diag: bool, /// This set contains the `DiagnosticId` of all emitted diagnostics to avoid @@ -500,7 +501,7 @@ pub struct HandlerFlags { /// If true, immediately emit diagnostics that would otherwise be buffered. /// (rustc: see `-Z dont-buffer-diagnostics` and `-Z treat-err-as-bug`) pub dont_buffer_diagnostics: bool, - /// If true, immediately print bugs registered with `delay_span_bug`. + /// If true, immediately print bugs registered with `delay_bug_unless_error`. /// (rustc: see `-Z report-delayed-bugs`) pub report_delayed_bugs: bool, /// Show macro backtraces. @@ -517,8 +518,11 @@ impl Drop for HandlerInner { self.emit_stashed_diagnostics(); if !self.has_errors() { - let bugs = std::mem::replace(&mut self.delayed_span_bugs, Vec::new()); - self.flush_delayed(bugs, "no errors encountered even though `delay_span_bug` issued"); + let bugs = std::mem::replace(&mut self.delayed_expected_error_bugs, Vec::new()); + self.flush_delayed( + bugs, + "no errors encountered even though `delay_bug_unless_error` issued", + ); } // They're `delayed_span_bugs` but for "require some diagnostic happened" @@ -528,7 +532,7 @@ impl Drop for HandlerInner { let bugs = std::mem::replace(&mut self.delayed_expect_diagnostic_bugs, Vec::new()); self.flush_delayed( bugs, - "no warnings or errors encountered even though `delayed_bugs_unless_diagnostic_emitted` issued", + "no warnings or errors encountered even though `delayed_bugs_unless_diagnostic` issued", ); } @@ -606,7 +610,7 @@ impl Handler { deduplicated_err_count: 0, deduplicated_warn_count: 0, emitter, - delayed_span_bugs: Vec::new(), + delayed_expected_error_bugs: Vec::new(), delayed_expect_diagnostic_bugs: Vec::new(), suppressed_expected_diag: false, taught_diagnostics: Default::default(), @@ -660,7 +664,7 @@ impl Handler { inner.deduplicated_warn_count = 0; // actually free the underlying memory (which `clear` would not do) - inner.delayed_span_bugs = Default::default(); + inner.delayed_expected_error_bugs = Default::default(); inner.delayed_expect_diagnostic_bugs = Default::default(); inner.taught_diagnostics = Default::default(); inner.emitted_diagnostic_codes = Default::default(); @@ -994,19 +998,19 @@ impl Handler { self.inner.borrow_mut().span_bug(span, msg) } - /// For documentation on this, see `Session::delay_span_bug`. + /// For documentation on this, see `Session::delay_bug_unless_error`. #[track_caller] - pub fn delay_span_bug( + pub fn delay_bug_unless_error( &self, span: impl Into, msg: impl Into, ) -> ErrorGuaranteed { - self.inner.borrow_mut().delay_span_bug(span, msg) + self.inner.borrow_mut().delay_bug_unless_error(span, msg) } // FIXME(eddyb) note the comment inside `impl Drop for HandlerInner`. - pub fn delay_bug_unless_diagnostic_emitted(&self, msg: impl Into) { - self.inner.borrow_mut().delay_bug_unless_diagnostic_emitted(msg) + pub fn delay_bug_unless_diagnostic(&self, msg: impl Into) { + self.inner.borrow_mut().delay_bug_unless_diagnostic(msg) } #[track_caller] @@ -1266,8 +1270,11 @@ impl Handler { pub fn flush_delayed(&self) { let mut inner = self.inner.lock(); - let bugs = std::mem::replace(&mut inner.delayed_span_bugs, Vec::new()); - inner.flush_delayed(bugs, "no errors encountered even though `delay_span_bug` issued"); + let bugs = std::mem::replace(&mut inner.delayed_expected_error_bugs, Vec::new()); + inner.flush_delayed( + bugs, + "no errors encountered even though `delay_bug_unless_error` issued", + ); } } @@ -1328,7 +1335,7 @@ impl HandlerInner { // when an error is first emitted, also), but maybe there's a case // in which that's not sound? otherwise this is really inefficient. let backtrace = std::backtrace::Backtrace::force_capture(); - self.delayed_span_bugs + self.delayed_expected_error_bugs .push(DelayedDiagnostic::with_backtrace(diagnostic.clone(), backtrace)); if !self.flags.report_delayed_bugs { @@ -1434,7 +1441,7 @@ impl HandlerInner { } fn delayed_bug_count(&self) -> usize { - self.delayed_span_bugs.len() + self.delayed_expect_diagnostic_bugs.len() + self.delayed_expected_error_bugs.len() + self.delayed_expect_diagnostic_bugs.len() } fn print_error_count(&mut self, registry: &Registry) { @@ -1558,14 +1565,14 @@ impl HandlerInner { self.has_errors() || self.lint_err_count > 0 } fn has_errors_or_delayed_span_bugs(&self) -> bool { - self.has_errors() || !self.delayed_span_bugs.is_empty() + self.has_errors() || !self.delayed_expected_error_bugs.is_empty() } fn has_any_message(&self) -> bool { self.err_count() > 0 || self.lint_err_count > 0 || self.warn_count > 0 } fn is_compilation_going_to_fail(&self) -> bool { - self.has_errors() || self.lint_err_count > 0 || !self.delayed_span_bugs.is_empty() + self.has_errors() || self.lint_err_count > 0 || !self.delayed_expected_error_bugs.is_empty() } fn abort_if_errors(&mut self) { @@ -1586,14 +1593,14 @@ impl HandlerInner { self.emit_diagnostic(diag.set_span(sp)); } - /// For documentation on this, see `Session::delay_span_bug`. + /// For documentation on this, see `Session::delay_bug_unless_error`. #[track_caller] - fn delay_span_bug( + fn delay_bug_unless_error( &mut self, sp: impl Into, msg: impl Into, ) -> ErrorGuaranteed { - // This is technically `self.treat_err_as_bug()` but `delay_span_bug` is called before + // This is technically `self.treat_err_as_bug()` but `delay_bug_unless_error` is called before // incrementing `err_count` by one, so we need to +1 the comparing. // FIXME: Would be nice to increment err_count in a more coherent way. if self.flags.treat_err_as_bug.map_or(false, |c| { @@ -1608,7 +1615,7 @@ impl HandlerInner { } // FIXME(eddyb) note the comment inside `impl Drop for HandlerInner`. - fn delay_bug_unless_diagnostic_emitted(&mut self, msg: impl Into) { + fn delay_bug_unless_diagnostic(&mut self, msg: impl Into) { let mut diagnostic = Diagnostic::new(Level::DelayedBug, msg); if self.flags.report_delayed_bugs { self.emit_diagnostic(&mut diagnostic); diff --git a/compiler/rustc_expand/src/expand.rs b/compiler/rustc_expand/src/expand.rs index 79d058d9c9736..836e01be4ed48 100644 --- a/compiler/rustc_expand/src/expand.rs +++ b/compiler/rustc_expand/src/expand.rs @@ -435,7 +435,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> { invocations = mem::take(&mut undetermined_invocations); force = !mem::replace(&mut progress, false); if force && self.monotonic { - self.cx.sess.delay_span_bug( + self.cx.sess.delay_bug_unless_error( invocations.last().unwrap().0.span(), "expansion entered force mode without producing any errors", ); diff --git a/compiler/rustc_expand/src/mbe/diagnostics.rs b/compiler/rustc_expand/src/mbe/diagnostics.rs index f469b2daef5eb..b2f57607cf131 100644 --- a/compiler/rustc_expand/src/mbe/diagnostics.rs +++ b/compiler/rustc_expand/src/mbe/diagnostics.rs @@ -35,7 +35,10 @@ pub(super) fn failed_to_match_macro<'cx>( if try_success_result.is_ok() { // Nonterminal parser recovery might turn failed matches into successful ones, // but for that it must have emitted an error already - tracker.cx.sess.delay_span_bug(sp, "Macro matching returned a success on the second try"); + tracker + .cx + .sess + .delay_bug_unless_error(sp, "Macro matching returned a success on the second try"); } if let Some(result) = tracker.result { @@ -133,7 +136,7 @@ impl<'a, 'cx, 'matcher> Tracker<'matcher> for CollectTrackerAndEmitter<'a, 'cx, Success(_) => { // Nonterminal parser recovery might turn failed matches into successful ones, // but for that it must have emitted an error already - self.cx.sess.delay_span_bug( + self.cx.sess.delay_bug_unless_error( self.root_span, "should not collect detailed info for successful macro match", ); diff --git a/compiler/rustc_hir_analysis/src/astconv/mod.rs b/compiler/rustc_hir_analysis/src/astconv/mod.rs index 92dc02c8d3f15..b0fe3948952b5 100644 --- a/compiler/rustc_hir_analysis/src/astconv/mod.rs +++ b/compiler/rustc_hir_analysis/src/astconv/mod.rs @@ -1577,9 +1577,10 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { false }); if references_self { - let guar = tcx - .sess - .delay_span_bug(span, "trait object projection bounds reference `Self`"); + let guar = tcx.sess.delay_bug_unless_error( + span, + "trait object projection bounds reference `Self`", + ); let substs: Vec<_> = b .projection_ty .substs @@ -2064,7 +2065,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { // trait reference. let Some(trait_ref) = tcx.impl_trait_ref(impl_def_id) else { // A cycle error occurred, most likely. - let guar = tcx.sess.delay_span_bug(span, "expected cycle error"); + let guar = tcx.sess.delay_bug_unless_error(span, "expected cycle error"); return Err(guar); }; @@ -2982,7 +2983,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { let e = self .tcx() .sess - .delay_span_bug(path.span, "path with `Res::Err` but no error emitted"); + .delay_bug_unless_error(path.span, "path with `Res::Err` but no error emitted"); self.set_tainted_by_errors(e); self.tcx().ty_error(e) } diff --git a/compiler/rustc_hir_analysis/src/check/check.rs b/compiler/rustc_hir_analysis/src/check/check.rs index 4ea471f8f0553..84f143306f012 100644 --- a/compiler/rustc_hir_analysis/src/check/check.rs +++ b/compiler/rustc_hir_analysis/src/check/check.rs @@ -155,7 +155,10 @@ fn check_union_fields(tcx: TyCtxt<'_>, span: Span, item_def_id: LocalDefId) -> b return false; } else if field_ty.needs_drop(tcx, param_env) { // This should never happen. But we can get here e.g. in case of name resolution errors. - tcx.sess.delay_span_bug(span, "we should never accept maybe-dropping union fields"); + tcx.sess.delay_bug_unless_error( + span, + "we should never accept maybe-dropping union fields", + ); } } } else { @@ -187,7 +190,7 @@ fn check_static_inhabited(tcx: TyCtxt<'_>, def_id: LocalDefId) { } // Generic statics are rejected, but we still reach this case. Err(e) => { - tcx.sess.delay_span_bug(span, &e.to_string()); + tcx.sess.delay_bug_unless_error(span, &e.to_string()); return; } }; @@ -210,7 +213,7 @@ fn check_static_inhabited(tcx: TyCtxt<'_>, def_id: LocalDefId) { fn check_opaque(tcx: TyCtxt<'_>, id: hir::ItemId) { let item = tcx.hir().item(id); let hir::ItemKind::OpaqueTy(hir::OpaqueTy { origin, .. }) = item.kind else { - tcx.sess.delay_span_bug(item.span, "expected opaque item"); + tcx.sess.delay_bug_unless_error(item.span, "expected opaque item"); return; }; @@ -438,7 +441,7 @@ fn check_opaque_meets_bounds<'tcx>( Ok(()) => {} Err(ty_err) => { let ty_err = ty_err.to_string(tcx); - tcx.sess.delay_span_bug( + tcx.sess.delay_bug_unless_error( span, &format!("could not unify `{hidden_ty}` with revealed type:\n{ty_err}"), ); @@ -757,7 +760,10 @@ fn check_impl_items_against_trait<'tcx>( tcx.associated_item(trait_item_id) } else { // Checked in `associated_item`. - tcx.sess.delay_span_bug(tcx.def_span(impl_item), "missing associated item in trait"); + tcx.sess.delay_bug_unless_error( + tcx.def_span(impl_item), + "missing associated item in trait", + ); continue; }; match ty_impl_item.kind { diff --git a/compiler/rustc_hir_analysis/src/check/compare_impl_item.rs b/compiler/rustc_hir_analysis/src/check/compare_impl_item.rs index bdc9ff5cada9a..68553907db039 100644 --- a/compiler/rustc_hir_analysis/src/check/compare_impl_item.rs +++ b/compiler/rustc_hir_analysis/src/check/compare_impl_item.rs @@ -369,9 +369,10 @@ fn compare_method_predicate_entailment<'tcx>( if infcx.tainted_by_errors().is_none() { infcx.err_ctxt().report_region_errors(impl_m_def_id, &errors); } - return Err(tcx - .sess - .delay_span_bug(rustc_span::DUMMY_SP, "error should have been emitted")); + return Err(tcx.sess.delay_bug_unless_error( + rustc_span::DUMMY_SP, + "error should have been emitted", + )); } } } @@ -786,7 +787,7 @@ pub(super) fn collect_return_position_impl_trait_in_trait_tys<'tcx>( collected_tys.insert(def_id, ty); } Err(err) => { - let reported = tcx.sess.delay_span_bug( + let reported = tcx.sess.delay_bug_unless_error( return_span, format!("could not fully resolve: {ty} => {err:?}"), ); diff --git a/compiler/rustc_hir_analysis/src/check/dropck.rs b/compiler/rustc_hir_analysis/src/check/dropck.rs index 2bb724138f584..b9544b52075bc 100644 --- a/compiler/rustc_hir_analysis/src/check/dropck.rs +++ b/compiler/rustc_hir_analysis/src/check/dropck.rs @@ -50,7 +50,7 @@ pub fn check_drop_impl(tcx: TyCtxt<'_>, drop_impl_did: DefId) -> Result<(), Erro // already checked by coherence, but compilation may // not have been terminated. let span = tcx.def_span(drop_impl_did); - let reported = tcx.sess.delay_span_bug( + let reported = tcx.sess.delay_bug_unless_error( span, &format!("should have been rejected by coherence check: {dtor_self_type}"), ); diff --git a/compiler/rustc_hir_analysis/src/check/intrinsicck.rs b/compiler/rustc_hir_analysis/src/check/intrinsicck.rs index b1d5a27be9397..e8c164db753b0 100644 --- a/compiler/rustc_hir_analysis/src/check/intrinsicck.rs +++ b/compiler/rustc_hir_analysis/src/check/intrinsicck.rs @@ -257,7 +257,7 @@ impl<'a, 'tcx> InlineAsmCtxt<'a, 'tcx> { pub fn check_asm(&self, asm: &hir::InlineAsm<'tcx>, enclosing_id: LocalDefId) { let target_features = self.tcx.asm_target_features(enclosing_id.to_def_id()); let Some(asm_arch) = self.tcx.sess.asm_arch else { - self.tcx.sess.delay_span_bug(DUMMY_SP, "target architecture does not support asm"); + self.tcx.sess.delay_bug_unless_error(DUMMY_SP, "target architecture does not support asm"); return; }; for (idx, (op, op_sp)) in asm.operands.iter().enumerate() { diff --git a/compiler/rustc_hir_analysis/src/check/wfcheck.rs b/compiler/rustc_hir_analysis/src/check/wfcheck.rs index 25be62534a5da..965d9d4e0f702 100644 --- a/compiler/rustc_hir_analysis/src/check/wfcheck.rs +++ b/compiler/rustc_hir_analysis/src/check/wfcheck.rs @@ -1035,8 +1035,10 @@ fn check_type_defn<'tcx>(tcx: TyCtxt<'tcx>, item: &hir::Item<'tcx>, all_sized: b let ty = tcx.type_of(variant.fields.last().unwrap().did).subst_identity(); let ty = tcx.erase_regions(ty); if ty.needs_infer() { - tcx.sess - .delay_span_bug(item.span, &format!("inference variables in {:?}", ty)); + tcx.sess.delay_bug_unless_error( + item.span, + &format!("inference variables in {:?}", ty), + ); // Just treat unresolved type expression as if it needs drop. true } else { diff --git a/compiler/rustc_hir_analysis/src/coherence/unsafety.rs b/compiler/rustc_hir_analysis/src/coherence/unsafety.rs index c6b16171311fb..16565d29101ba 100644 --- a/compiler/rustc_hir_analysis/src/coherence/unsafety.rs +++ b/compiler/rustc_hir_analysis/src/coherence/unsafety.rs @@ -82,7 +82,7 @@ pub(super) fn check_item(tcx: TyCtxt<'_>, def_id: LocalDefId) { (_, _, Unsafety::Unsafe, hir::ImplPolarity::Negative(_)) => { // Reported in AST validation - tcx.sess.delay_span_bug(item.span, "unsafe negative impl"); + tcx.sess.delay_bug_unless_error(item.span, "unsafe negative impl"); } (_, _, Unsafety::Normal, hir::ImplPolarity::Negative(_)) | (Unsafety::Unsafe, _, Unsafety::Unsafe, hir::ImplPolarity::Positive) diff --git a/compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs b/compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs index 6c00b8ff7bdee..605fbe65184e4 100644 --- a/compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs +++ b/compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs @@ -1338,7 +1338,7 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> { } } - self.tcx.sess.delay_span_bug( + self.tcx.sess.delay_bug_unless_error( lifetime_ref.ident.span, &format!("Could not resolve {:?} in scope {:#?}", lifetime_ref, self.scope,), ); @@ -1392,9 +1392,10 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> { return; } - self.tcx - .sess - .delay_span_bug(self.tcx.hir().span(hir_id), "could not resolve {param_def_id:?}"); + self.tcx.sess.delay_bug_unless_error( + self.tcx.hir().span(hir_id), + "could not resolve {param_def_id:?}", + ); } #[instrument(level = "debug", skip(self))] @@ -1888,7 +1889,7 @@ fn is_late_bound_map( Some(true) => Some(arg), Some(false) => None, None => { - tcx.sess.delay_span_bug( + tcx.sess.delay_bug_unless_error( *span, format!( "Incorrect generic arg count for alias {:?}", diff --git a/compiler/rustc_hir_analysis/src/collect/type_of.rs b/compiler/rustc_hir_analysis/src/collect/type_of.rs index 50073d94ea5c9..007b097b6f525 100644 --- a/compiler/rustc_hir_analysis/src/collect/type_of.rs +++ b/compiler/rustc_hir_analysis/src/collect/type_of.rs @@ -88,7 +88,7 @@ pub(super) fn opt_const_param_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Option< (generics, arg_index) } else { // I dont think it's possible to reach this but I'm not 100% sure - BoxyUwU - tcx.sess.delay_span_bug( + tcx.sess.delay_bug_unless_error( tcx.def_span(def_id), "unexpected non-GAT usage of an anon const", ); @@ -142,7 +142,7 @@ pub(super) fn opt_const_param_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Option< if let Some(path) = get_path_containing_arg_in_pat(pat, hir_id) { path } else { - tcx.sess.delay_span_bug( + tcx.sess.delay_bug_unless_error( tcx.def_span(def_id), &format!("unable to find const parent for {} in pat {:?}", hir_id, pat), ); @@ -150,7 +150,7 @@ pub(super) fn opt_const_param_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Option< } } _ => { - tcx.sess.delay_span_bug( + tcx.sess.delay_bug_unless_error( tcx.def_span(def_id), &format!("unexpected const parent path {:?}", parent_node), ); @@ -173,7 +173,7 @@ pub(super) fn opt_const_param_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Option< .position(|ct| ct.hir_id == hir_id) .map(|idx| (idx, seg))) }) else { - tcx.sess.delay_span_bug( + tcx.sess.delay_bug_unless_error( tcx.def_span(def_id), "no arg matching AnonConst in path", ); @@ -183,7 +183,7 @@ pub(super) fn opt_const_param_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Option< let generics = match tcx.res_generics_def_id(segment.res) { Some(def_id) => tcx.generics_of(def_id), None => { - tcx.sess.delay_span_bug( + tcx.sess.delay_bug_unless_error( tcx.def_span(def_id), &format!("unexpected anon const res {:?} in path: {:?}", segment.res, path), ); diff --git a/compiler/rustc_hir_analysis/src/hir_wf_check.rs b/compiler/rustc_hir_analysis/src/hir_wf_check.rs index e330fcc785770..3c413777c385a 100644 --- a/compiler/rustc_hir_analysis/src/hir_wf_check.rs +++ b/compiler/rustc_hir_analysis/src/hir_wf_check.rs @@ -28,8 +28,10 @@ fn diagnostic_hir_wf_check<'tcx>( let hir_id = hir.local_def_id_to_hir_id(def_id); // HIR wfcheck should only ever happen as part of improving an existing error - tcx.sess - .delay_span_bug(tcx.def_span(def_id), "Performed HIR wfcheck without an existing error!"); + tcx.sess.delay_bug_unless_error( + tcx.def_span(def_id), + "Performed HIR wfcheck without an existing error!", + ); let icx = ItemCtxt::new(tcx, def_id.to_def_id()); @@ -187,7 +189,7 @@ struct EraseAllBoundRegions<'tcx> { // `ItemCtxt::to_ty`. To make things simpler, we just erase all // of them, regardless of depth. At worse, this will give // us an inaccurate span for an error message, but cannot -// lead to unsoundness (we call `delay_span_bug` at the start +// lead to unsoundness (we call `delay_bug_unless_error` at the start // of `diagnostic_hir_wf_check`). impl<'tcx> TypeFolder> for EraseAllBoundRegions<'tcx> { fn interner(&self) -> TyCtxt<'tcx> { diff --git a/compiler/rustc_hir_analysis/src/impl_wf_check.rs b/compiler/rustc_hir_analysis/src/impl_wf_check.rs index 82a96f8e67408..6ec7b7766fd61 100644 --- a/compiler/rustc_hir_analysis/src/impl_wf_check.rs +++ b/compiler/rustc_hir_analysis/src/impl_wf_check.rs @@ -74,7 +74,7 @@ fn enforce_impl_params_are_constrained(tcx: TyCtxt<'_>, impl_def_id: LocalDefId) if impl_self_ty.references_error() { // Don't complain about unconstrained type params when self ty isn't known due to errors. // (#36836) - tcx.sess.delay_span_bug( + tcx.sess.delay_bug_unless_error( tcx.def_span(impl_def_id), &format!( "potentially unconstrained type parameters weren't evaluated: {:?}", diff --git a/compiler/rustc_hir_typeck/src/callee.rs b/compiler/rustc_hir_typeck/src/callee.rs index fe2f6319c1ad3..a7b8259fc0f2e 100644 --- a/compiler/rustc_hir_typeck/src/callee.rs +++ b/compiler/rustc_hir_typeck/src/callee.rs @@ -249,7 +249,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { ) { // Check for `self` receiver on the method, otherwise we can't use this as a `Fn*` trait. if !self.tcx.associated_item(ok.value.def_id).fn_has_self_parameter { - self.tcx.sess.delay_span_bug( + self.tcx.sess.delay_bug_unless_error( call_expr.span, "input to overloaded call fn is not a self receiver", ); @@ -266,7 +266,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // caused an error elsewhere. self.tcx .sess - .delay_span_bug(call_expr.span, "input to call/call_mut is not a ref"); + .delay_bug_unless_error(call_expr.span, "input to call/call_mut is not a ref"); return None; }; diff --git a/compiler/rustc_hir_typeck/src/cast.rs b/compiler/rustc_hir_typeck/src/cast.rs index 316c2a7eeeb4b..bf8c087915bdb 100644 --- a/compiler/rustc_hir_typeck/src/cast.rs +++ b/compiler/rustc_hir_typeck/src/cast.rs @@ -141,10 +141,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { | ty::Never | ty::Dynamic(_, _, ty::DynStar) | ty::Error(_) => { - let reported = self - .tcx - .sess - .delay_span_bug(span, &format!("`{:?}` should be sized but is not?", t)); + let reported = self.tcx.sess.delay_bug_unless_error( + span, + &format!("`{:?}` should be sized but is not?", t), + ); return Err(reported); } }) diff --git a/compiler/rustc_hir_typeck/src/coercion.rs b/compiler/rustc_hir_typeck/src/coercion.rs index 00b86890b33f4..cd7d5a582b0a7 100644 --- a/compiler/rustc_hir_typeck/src/coercion.rs +++ b/compiler/rustc_hir_typeck/src/coercion.rs @@ -1519,7 +1519,9 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> { // any superfluous errors we might encounter while trying to // emit or provide suggestions on how to fix the initial error. fcx.set_tainted_by_errors( - fcx.tcx.sess.delay_span_bug(cause.span, "coercion error but no error emitted"), + fcx.tcx + .sess + .delay_bug_unless_error(cause.span, "coercion error but no error emitted"), ); let (expected, found) = if label_expression_as_expected { // In the case where this is a "forced unit", like diff --git a/compiler/rustc_hir_typeck/src/demand.rs b/compiler/rustc_hir_typeck/src/demand.rs index 34d62987c3b0a..f4e7b959746da 100644 --- a/compiler/rustc_hir_typeck/src/demand.rs +++ b/compiler/rustc_hir_typeck/src/demand.rs @@ -188,7 +188,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { Err(e) => e, }; - self.set_tainted_by_errors(self.tcx.sess.delay_span_bug( + self.set_tainted_by_errors(self.tcx.sess.delay_bug_unless_error( expr.span, "`TypeError` when attempting coercion but no error emitted", )); diff --git a/compiler/rustc_hir_typeck/src/expr.rs b/compiler/rustc_hir_typeck/src/expr.rs index 6d54f6948c8ca..dfd134652eb0b 100644 --- a/compiler/rustc_hir_typeck/src/expr.rs +++ b/compiler/rustc_hir_typeck/src/expr.rs @@ -81,7 +81,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // coercions from ! to `expected`. if ty.is_never() { if let Some(adjustments) = self.typeck_results.borrow().adjustments().get(expr.hir_id) { - let reported = self.tcx().sess.delay_span_bug( + let reported = self.tcx().sess.delay_bug_unless_error( expr.span, "expression with never type wound up being adjusted", ); @@ -528,8 +528,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let ty = match res { Res::Err => { self.suggest_assoc_method_call(segs); - let e = - self.tcx.sess.delay_span_bug(qpath.span(), "`Res::Err` but no error emitted"); + let e = self + .tcx + .sess + .delay_bug_unless_error(qpath.span(), "`Res::Err` but no error emitted"); self.set_tainted_by_errors(e); tcx.ty_error(e) } @@ -1211,7 +1213,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // permit break with a value [1]. if ctxt.coerce.is_none() && !ctxt.may_break { // [1] - self.tcx.sess.delay_span_bug(body.span, "no coercion, but loop may not break"); + self.tcx.sess.delay_bug_unless_error(body.span, "no coercion, but loop may not break"); } ctxt.coerce.map(|c| c.complete(self)).unwrap_or_else(|| self.tcx.mk_unit()) } @@ -2002,7 +2004,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let guar = self .tcx .sess - .delay_span_bug(expr_span, "parser recovered but no error was emitted"); + .delay_bug_unless_error(expr_span, "parser recovered but no error was emitted"); self.set_tainted_by_errors(guar); return guar; } @@ -2270,7 +2272,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } let guar = if field.name == kw::Empty { - self.tcx.sess.delay_span_bug(field.span, "field name with no name") + self.tcx.sess.delay_bug_unless_error(field.span, "field name with no name") } else if self.method_exists( field, base_ty, diff --git a/compiler/rustc_hir_typeck/src/expr_use_visitor.rs b/compiler/rustc_hir_typeck/src/expr_use_visitor.rs index c8cda0dc90c6d..4e689c43fceac 100644 --- a/compiler/rustc_hir_typeck/src/expr_use_visitor.rs +++ b/compiler/rustc_hir_typeck/src/expr_use_visitor.rs @@ -526,7 +526,9 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> { // The struct path probably didn't resolve if self.mc.typeck_results.opt_field_index(field.hir_id).is_none() { - self.tcx().sess.delay_span_bug(field.span, "couldn't resolve index for field"); + self.tcx() + .sess + .delay_bug_unless_error(field.span, "couldn't resolve index for field"); } } diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs index 60e55c7b0cf57..41f7e1614f018 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs @@ -272,7 +272,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // FIXME: currently we never try to compose autoderefs // and ReifyFnPointer/UnsafeFnPointer, but we could. _ => { - self.tcx.sess.delay_span_bug( + self.tcx.sess.delay_bug_unless_error( expr.span, &format!( "while adjusting {:?}, can't compose {:?} and {:?}", @@ -1322,7 +1322,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { match self.at(&self.misc(span), self.param_env).eq(impl_ty, self_ty) { Ok(ok) => self.register_infer_ok_obligations(ok), Err(_) => { - self.tcx.sess.delay_span_bug( + self.tcx.sess.delay_bug_unless_error( span, &format!( "instantiate_value_path: (UFCS) {:?} was a subtype of {:?} but now is not?", diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs index 99339153de2d6..81d60f73e1fa9 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs @@ -513,7 +513,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let tcx = self.tcx; // FIXME: taint after emitting errors and pass through an `ErrorGuaranteed` self.set_tainted_by_errors( - tcx.sess.delay_span_bug(call_span, "no errors reported for args"), + tcx.sess.delay_bug_unless_error(call_span, "no errors reported for args"), ); // Get the argument span in the context of the call span so that @@ -1301,8 +1301,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let (def, ty) = self.finish_resolving_struct_path(qpath, path_span, hir_id); let variant = match def { Res::Err => { - let guar = - self.tcx.sess.delay_span_bug(path_span, "`Res::Err` but no error emitted"); + let guar = self + .tcx + .sess + .delay_bug_unless_error(path_span, "`Res::Err` but no error emitted"); self.set_tainted_by_errors(guar); return Err(guar); } diff --git a/compiler/rustc_hir_typeck/src/generator_interior/drop_ranges/cfg_build.rs b/compiler/rustc_hir_typeck/src/generator_interior/drop_ranges/cfg_build.rs index adedb5b742884..0d2e92b5e80e7 100644 --- a/compiler/rustc_hir_typeck/src/generator_interior/drop_ranges/cfg_build.rs +++ b/compiler/rustc_hir_typeck/src/generator_interior/drop_ranges/cfg_build.rs @@ -230,9 +230,10 @@ impl<'a, 'tcx> DropRangeVisitor<'a, 'tcx> { let ty = self.typeck_results.expr_ty(expr); let ty = self.infcx.resolve_vars_if_possible(ty); if ty.has_non_region_infer() { - self.tcx() - .sess - .delay_span_bug(expr.span, format!("could not resolve infer vars in `{ty}`")); + self.tcx().sess.delay_bug_unless_error( + expr.span, + format!("could not resolve infer vars in `{ty}`"), + ); return; } let ty = self.tcx().erase_regions(ty); diff --git a/compiler/rustc_hir_typeck/src/generator_interior/drop_ranges/record_consumed_borrow.rs b/compiler/rustc_hir_typeck/src/generator_interior/drop_ranges/record_consumed_borrow.rs index fa3887362d99c..ca6171765ed8f 100644 --- a/compiler/rustc_hir_typeck/src/generator_interior/drop_ranges/record_consumed_borrow.rs +++ b/compiler/rustc_hir_typeck/src/generator_interior/drop_ranges/record_consumed_borrow.rs @@ -203,7 +203,7 @@ impl<'tcx> expr_use_visitor::Delegate<'tcx> for ExprUseDelegate<'tcx> { // since it is essentially doing `Drop::drop(&mut x); x = new_value;`. let ty = self.tcx.erase_regions(assignee_place.place.base_ty); if ty.needs_infer() { - self.tcx.sess.delay_span_bug( + self.tcx.sess.delay_bug_unless_error( self.tcx.hir().span(assignee_place.hir_id), &format!("inference variables in {ty}"), ); diff --git a/compiler/rustc_hir_typeck/src/generator_interior/mod.rs b/compiler/rustc_hir_typeck/src/generator_interior/mod.rs index e5f9292290ffe..d43224d0d1c31 100644 --- a/compiler/rustc_hir_typeck/src/generator_interior/mod.rs +++ b/compiler/rustc_hir_typeck/src/generator_interior/mod.rs @@ -112,7 +112,7 @@ impl<'a, 'tcx> InteriorVisitor<'a, 'tcx> { self.fcx .tcx .sess - .delay_span_bug(span, &format!("Encountered var {:?}", unresolved_term)); + .delay_bug_unless_error(span, &format!("Encountered var {:?}", unresolved_term)); } else { let note = format!( "the type is part of the {} because of this {}", @@ -466,7 +466,7 @@ impl<'a, 'tcx> Visitor<'tcx> for InteriorVisitor<'a, 'tcx> { self.fcx .tcx .sess - .delay_span_bug(expr.span, &format!("inference variables in {ty}")); + .delay_bug_unless_error(expr.span, &format!("inference variables in {ty}")); true } else { ty.needs_drop(self.fcx.tcx, self.fcx.param_env) @@ -523,7 +523,7 @@ impl<'a, 'tcx> Visitor<'tcx> for InteriorVisitor<'a, 'tcx> { if let Some(ty) = self.fcx.typeck_results.borrow().expr_ty_opt(expr) { self.record(ty, expr.hir_id, scope, Some(expr), expr.span); } else { - self.fcx.tcx.sess.delay_span_bug(expr.span, "no type for node"); + self.fcx.tcx.sess.delay_bug_unless_error(expr.span, "no type for node"); } } } diff --git a/compiler/rustc_hir_typeck/src/intrinsicck.rs b/compiler/rustc_hir_typeck/src/intrinsicck.rs index 19d2befc43879..90881533f0a64 100644 --- a/compiler/rustc_hir_typeck/src/intrinsicck.rs +++ b/compiler/rustc_hir_typeck/src/intrinsicck.rs @@ -48,7 +48,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let to = normalize(to); trace!(?from, ?to); if from.has_non_region_infer() || to.has_non_region_infer() { - tcx.sess.delay_span_bug(span, "argument to transmute has inference variables"); + tcx.sess.delay_bug_unless_error(span, "argument to transmute has inference variables"); return; } // Transmutes that are only changing lifetimes are always ok. diff --git a/compiler/rustc_hir_typeck/src/mem_categorization.rs b/compiler/rustc_hir_typeck/src/mem_categorization.rs index e50f5c77552dc..b5bb4adbb8d96 100644 --- a/compiler/rustc_hir_typeck/src/mem_categorization.rs +++ b/compiler/rustc_hir_typeck/src/mem_categorization.rs @@ -547,7 +547,7 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> { let ty::Adt(adt_def, _) = ty.kind() else { self.tcx() .sess - .delay_span_bug(span, "struct or tuple struct pattern not applied to an ADT"); + .delay_bug_unless_error(span, "struct or tuple struct pattern not applied to an ADT"); return Err(()); }; @@ -580,9 +580,10 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> { match ty.kind() { ty::Adt(adt_def, _) => Ok(adt_def.variant(variant_index).fields.len()), _ => { - self.tcx() - .sess - .delay_span_bug(span, "struct or tuple struct pattern not applied to an ADT"); + self.tcx().sess.delay_bug_unless_error( + span, + "struct or tuple struct pattern not applied to an ADT", + ); Err(()) } } @@ -595,7 +596,9 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> { match ty.kind() { ty::Tuple(substs) => Ok(substs.len()), _ => { - self.tcx().sess.delay_span_bug(span, "tuple pattern not applied to a tuple"); + self.tcx() + .sess + .delay_bug_unless_error(span, "tuple pattern not applied to a tuple"); Err(()) } } diff --git a/compiler/rustc_hir_typeck/src/method/mod.rs b/compiler/rustc_hir_typeck/src/method/mod.rs index 0456dd56c340e..c07e7c9ef8249 100644 --- a/compiler/rustc_hir_typeck/src/method/mod.rs +++ b/compiler/rustc_hir_typeck/src/method/mod.rs @@ -374,7 +374,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // type parameters or early-bound regions. let tcx = self.tcx; let Some(method_item) = self.associated_value(trait_def_id, m_name) else { - tcx.sess.delay_span_bug( + tcx.sess.delay_bug_unless_error( obligation.cause.span, "operator trait does not have corresponding operator method", ); @@ -382,7 +382,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { }; if method_item.kind != ty::AssocKind::Fn { - self.tcx.sess.delay_span_bug(tcx.def_span(method_item.def_id), "not a method"); + self.tcx.sess.delay_bug_unless_error(tcx.def_span(method_item.def_id), "not a method"); return None; } diff --git a/compiler/rustc_hir_typeck/src/method/suggest.rs b/compiler/rustc_hir_typeck/src/method/suggest.rs index de8b24461b2f2..ecef29b6c92a6 100644 --- a/compiler/rustc_hir_typeck/src/method/suggest.rs +++ b/compiler/rustc_hir_typeck/src/method/suggest.rs @@ -708,7 +708,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { span: item_span, .. })) => { - tcx.sess.delay_span_bug( + tcx.sess.delay_bug_unless_error( *item_span, "auto trait is invoked with no method error, but no error reported?", ); diff --git a/compiler/rustc_hir_typeck/src/op.rs b/compiler/rustc_hir_typeck/src/op.rs index a4b325a9b7984..767f40e9b5aa0 100644 --- a/compiler/rustc_hir_typeck/src/op.rs +++ b/compiler/rustc_hir_typeck/src/op.rs @@ -742,9 +742,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { Op::Unary(..) => 0, }, ) { - self.tcx - .sess - .delay_span_bug(span, "operator didn't have the right number of generic args"); + self.tcx.sess.delay_bug_unless_error( + span, + "operator didn't have the right number of generic args", + ); return Err(vec![]); } diff --git a/compiler/rustc_hir_typeck/src/pat.rs b/compiler/rustc_hir_typeck/src/pat.rs index 9d95866fca4ab..e6edfbed3f449 100644 --- a/compiler/rustc_hir_typeck/src/pat.rs +++ b/compiler/rustc_hir_typeck/src/pat.rs @@ -884,7 +884,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let (res, opt_ty, segments) = path_resolution; match res { Res::Err => { - let e = tcx.sess.delay_span_bug(qpath.span(), "`Res::Err` but no error emitted"); + let e = tcx + .sess + .delay_bug_unless_error(qpath.span(), "`Res::Err` but no error emitted"); self.set_tainted_by_errors(e); return tcx.ty_error(e); } @@ -1048,7 +1050,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let (res, opt_ty, segments) = self.resolve_ty_and_res_fully_qualified_call(qpath, pat.hir_id, pat.span); if res == Res::Err { - let e = tcx.sess.delay_span_bug(pat.span, "`Res::Err` but no error emitted"); + let e = tcx.sess.delay_bug_unless_error(pat.span, "`Res::Err` but no error emitted"); self.set_tainted_by_errors(e); on_error(e); return tcx.ty_error(e); @@ -1064,7 +1066,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let variant = match res { Res::Err => { - let e = tcx.sess.delay_span_bug(pat.span, "`Res::Err` but no error emitted"); + let e = + tcx.sess.delay_bug_unless_error(pat.span, "`Res::Err` but no error emitted"); self.set_tainted_by_errors(e); on_error(e); return tcx.ty_error(e); diff --git a/compiler/rustc_hir_typeck/src/writeback.rs b/compiler/rustc_hir_typeck/src/writeback.rs index 00348f3afdc44..b06c90e3bc1a8 100644 --- a/compiler/rustc_hir_typeck/src/writeback.rs +++ b/compiler/rustc_hir_typeck/src/writeback.rs @@ -227,7 +227,7 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> { // When encountering `return [0][0]` outside of a `fn` body we can encounter a base // that isn't in the type table. We assume more relevant errors have already been // emitted, so we delay an ICE if none have. (#64638) - self.tcx().sess.delay_span_bug(e.span, &format!("bad base: `{:?}`", base)); + self.tcx().sess.delay_bug_unless_error(e.span, &format!("bad base: `{:?}`", base)); } if let Some(ty::Ref(_, base_ty, _)) = base_ty { let index_ty = typeck_results.expr_ty_adjusted_opt(index).unwrap_or_else(|| { @@ -318,7 +318,9 @@ impl<'cx, 'tcx> Visitor<'tcx> for WritebackCx<'cx, 'tcx> { // Nothing to write back here } hir::GenericParamKind::Type { .. } | hir::GenericParamKind::Const { .. } => { - self.tcx().sess.delay_span_bug(p.span, format!("unexpected generic param: {p:?}")); + self.tcx() + .sess + .delay_bug_unless_error(p.span, format!("unexpected generic param: {p:?}")); } } } diff --git a/compiler/rustc_infer/src/infer/canonical/canonicalizer.rs b/compiler/rustc_infer/src/infer/canonical/canonicalizer.rs index f66f6bd4ae1bc..0c344c5440945 100644 --- a/compiler/rustc_infer/src/infer/canonical/canonicalizer.rs +++ b/compiler/rustc_infer/src/infer/canonical/canonicalizer.rs @@ -202,8 +202,8 @@ impl CanonicalizeMode for CanonicalizeQueryResponse { // // rust-lang/rust#57464: `impl Trait` can leak local // scopes (in manner violating typeck). Therefore, use - // `delay_span_bug` to allow type error over an ICE. - canonicalizer.tcx.sess.delay_span_bug( + // `delay_bug_unless_error` to allow type error over an ICE. + canonicalizer.tcx.sess.delay_bug_unless_error( rustc_span::DUMMY_SP, &format!("unexpected region in query response: `{:?}`", r), ); diff --git a/compiler/rustc_infer/src/infer/combine.rs b/compiler/rustc_infer/src/infer/combine.rs index 33292e871b11c..c43f33d4fb61a 100644 --- a/compiler/rustc_infer/src/infer/combine.rs +++ b/compiler/rustc_infer/src/infer/combine.rs @@ -175,7 +175,7 @@ impl<'tcx> InferCtxt<'tcx> { ); if let Err(NoSolution) = self.tcx.check_tys_might_be_eq(canonical) { - self.tcx.sess.delay_span_bug( + self.tcx.sess.delay_bug_unless_error( DUMMY_SP, &format!("cannot relate consts of different types (a={:?}, b={:?})", a, b,), ); diff --git a/compiler/rustc_infer/src/infer/lexical_region_resolve/mod.rs b/compiler/rustc_infer/src/infer/lexical_region_resolve/mod.rs index 335eb4c54062f..7d27fc31220b4 100644 --- a/compiler/rustc_infer/src/infer/lexical_region_resolve/mod.rs +++ b/compiler/rustc_infer/src/infer/lexical_region_resolve/mod.rs @@ -856,7 +856,7 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> { // Errors in earlier passes can yield error variables without // resolution errors here; delay ICE in favor of those errors. - self.tcx().sess.delay_span_bug( + self.tcx().sess.delay_bug_unless_error( self.var_infos[node_idx].origin.span(), &format!( "collect_error_for_expanding_node() could not find \ diff --git a/compiler/rustc_infer/src/infer/mod.rs b/compiler/rustc_infer/src/infer/mod.rs index cf8007c964dc0..6d060d2bdb7cd 100644 --- a/compiler/rustc_infer/src/infer/mod.rs +++ b/compiler/rustc_infer/src/infer/mod.rs @@ -1740,7 +1740,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { Err(self .tcx .sess - .delay_span_bug(rustc_span::DUMMY_SP, "error should have been emitted")) + .delay_bug_unless_error(rustc_span::DUMMY_SP, "error should have been emitted")) } } diff --git a/compiler/rustc_infer/src/infer/nll_relate/mod.rs b/compiler/rustc_infer/src/infer/nll_relate/mod.rs index 6e413a7f41287..a492b468673d3 100644 --- a/compiler/rustc_infer/src/infer/nll_relate/mod.rs +++ b/compiler/rustc_infer/src/infer/nll_relate/mod.rs @@ -572,7 +572,7 @@ where &ty::Alias(ty::Opaque, ty::AliasTy { def_id: a_def_id, .. }), &ty::Alias(ty::Opaque, ty::AliasTy { def_id: b_def_id, .. }), ) if a_def_id == b_def_id => infcx.super_combine_tys(self, a, b).or_else(|err| { - self.tcx().sess.delay_span_bug( + self.tcx().sess.delay_bug_unless_error( self.delegate.span(), "failure to relate an opaque to itself should result in an error later on", ); @@ -635,7 +635,7 @@ where match b.kind() { ty::ConstKind::Infer(InferConst::Var(_)) if D::forbid_inference_vars() => { // Forbid inference variables in the RHS. - self.infcx.tcx.sess.delay_span_bug( + self.infcx.tcx.sess.delay_bug_unless_error( self.delegate.span(), format!("unexpected inference var {:?}", b,), ); diff --git a/compiler/rustc_infer/src/infer/opaque_types/table.rs b/compiler/rustc_infer/src/infer/opaque_types/table.rs index ae4b85c8799ef..778d8b3322939 100644 --- a/compiler/rustc_infer/src/infer/opaque_types/table.rs +++ b/compiler/rustc_infer/src/infer/opaque_types/table.rs @@ -42,7 +42,7 @@ impl<'tcx> Drop for OpaqueTypeStorage<'tcx> { fn drop(&mut self) { if !self.opaque_types.is_empty() { ty::tls::with(|tcx| { - tcx.sess.delay_span_bug(DUMMY_SP, &format!("{:?}", self.opaque_types)) + tcx.sess.delay_bug_unless_error(DUMMY_SP, &format!("{:?}", self.opaque_types)) }); } } diff --git a/compiler/rustc_infer/src/infer/outlives/obligations.rs b/compiler/rustc_infer/src/infer/outlives/obligations.rs index bbe7d4c63f794..6f96262e4219e 100644 --- a/compiler/rustc_infer/src/infer/outlives/obligations.rs +++ b/compiler/rustc_infer/src/infer/outlives/obligations.rs @@ -273,7 +273,7 @@ where // ignore this, we presume it will yield an error // later, since if a type variable is not resolved by // this point it never will be - self.tcx.sess.delay_span_bug( + self.tcx.sess.delay_bug_unless_error( origin.span(), &format!("unresolved inference variable in outlives: {:?}", v), ); diff --git a/compiler/rustc_infer/src/infer/outlives/verify.rs b/compiler/rustc_infer/src/infer/outlives/verify.rs index bae246418b05a..b8f4e1f327ac5 100644 --- a/compiler/rustc_infer/src/infer/outlives/verify.rs +++ b/compiler/rustc_infer/src/infer/outlives/verify.rs @@ -172,7 +172,7 @@ impl<'cx, 'tcx> VerifyBoundCx<'cx, 'tcx> { // ignore this, we presume it will yield an error // later, since if a type variable is not resolved by // this point it never will be - self.tcx.sess.delay_span_bug( + self.tcx.sess.delay_bug_unless_error( rustc_span::DUMMY_SP, &format!("unresolved inference variable in outlives: {:?}", v), ); diff --git a/compiler/rustc_lint/src/early.rs b/compiler/rustc_lint/src/early.rs index 337a19dd024d2..51b1cc5012cb8 100644 --- a/compiler/rustc_lint/src/early.rs +++ b/compiler/rustc_lint/src/early.rs @@ -427,7 +427,7 @@ pub fn check_ast_node_inner<'a, T: EarlyLintPass>( // that was not lint-checked (perhaps it doesn't exist?). This is a bug. for (id, lints) in cx.context.buffered.map { for early_lint in lints { - sess.delay_span_bug( + sess.delay_bug_unless_error( early_lint.span, &format!( "failed to process buffered lint here (dummy = {})", diff --git a/compiler/rustc_middle/src/macros.rs b/compiler/rustc_middle/src/macros.rs index a8d71ce030c2a..8cb520a9b3ba1 100644 --- a/compiler/rustc_middle/src/macros.rs +++ b/compiler/rustc_middle/src/macros.rs @@ -4,9 +4,9 @@ /// /// If you have a span available, you should use [`span_bug`] instead. /// -/// If the bug should only be emitted when compilation didn't fail, [`Session::delay_span_bug`] may be useful. +/// If the bug should only be emitted when compilation didn't fail, [`Session::delay_bug_unless_error`] may be useful. /// -/// [`Session::delay_span_bug`]: rustc_session::Session::delay_span_bug +/// [`Session::delay_bug_unless_error`]: rustc_session::Session::delay_bug_unless_error /// [`span_bug`]: crate::span_bug #[macro_export] macro_rules! bug { @@ -23,9 +23,9 @@ macro_rules! bug { /// at the code the compiler was compiling when it ICEd. This is the preferred way to trigger /// ICEs. /// -/// If the bug should only be emitted when compilation didn't fail, [`Session::delay_span_bug`] may be useful. +/// If the bug should only be emitted when compilation didn't fail, [`Session::delay_bug_unless_error`] may be useful. /// -/// [`Session::delay_span_bug`]: rustc_session::Session::delay_span_bug +/// [`Session::delay_bug_unless_error`]: rustc_session::Session::delay_bug_unless_error #[macro_export] macro_rules! span_bug { ($span:expr, $msg:expr) => ({ $crate::util::bug::span_bug_fmt($span, ::std::format_args!($msg)) }); diff --git a/compiler/rustc_middle/src/middle/stability.rs b/compiler/rustc_middle/src/middle/stability.rs index 354c84e2209a3..d269a2a31a4f0 100644 --- a/compiler/rustc_middle/src/middle/stability.rs +++ b/compiler/rustc_middle/src/middle/stability.rs @@ -599,7 +599,10 @@ impl<'tcx> TyCtxt<'tcx> { |span, def_id| { // The API could be uncallable for other reasons, for example when a private module // was referenced. - self.sess.delay_span_bug(span, &format!("encountered unmarked API: {:?}", def_id)); + self.sess.delay_bug_unless_error( + span, + &format!("encountered unmarked API: {:?}", def_id), + ); }, ) } diff --git a/compiler/rustc_middle/src/mir/interpret/allocation.rs b/compiler/rustc_middle/src/mir/interpret/allocation.rs index 221105ac48f79..30ca0bf96be8f 100644 --- a/compiler/rustc_middle/src/mir/interpret/allocation.rs +++ b/compiler/rustc_middle/src/mir/interpret/allocation.rs @@ -258,7 +258,7 @@ impl Allocation { panic!("Allocation::uninit called with panic_on_fail had allocation failure") } ty::tls::with(|tcx| { - tcx.sess.delay_span_bug(DUMMY_SP, "exhausted memory during interpretation") + tcx.sess.delay_bug_unless_error(DUMMY_SP, "exhausted memory during interpretation") }); InterpError::ResourceExhaustion(ResourceExhaustionInfo::MemoryExhausted) })?; diff --git a/compiler/rustc_middle/src/mir/interpret/mod.rs b/compiler/rustc_middle/src/mir/interpret/mod.rs index b0975616b6151..bf2fa557fb9e2 100644 --- a/compiler/rustc_middle/src/mir/interpret/mod.rs +++ b/compiler/rustc_middle/src/mir/interpret/mod.rs @@ -173,7 +173,7 @@ pub struct LitToConstInput<'tcx> { #[derive(Copy, Clone, Debug, Eq, PartialEq, HashStable)] pub enum LitToConstError { /// The literal's inferred type did not match the expected `ty` in the input. - /// This is used for graceful error handling (`delay_span_bug`) in + /// This is used for graceful error handling (`delay_bug_unless_error`) in /// type checking (`Const::from_anon_const`). TypeError, Reported(ErrorGuaranteed), diff --git a/compiler/rustc_middle/src/ty/adt.rs b/compiler/rustc_middle/src/ty/adt.rs index f127b6275a21d..299ad078360d6 100644 --- a/compiler/rustc_middle/src/ty/adt.rs +++ b/compiler/rustc_middle/src/ty/adt.rs @@ -463,7 +463,7 @@ impl<'tcx> AdtDef<'tcx> { ErrorHandled::Reported(_) => "enum discriminant evaluation failed", ErrorHandled::TooGeneric => "enum discriminant depends on generics", }; - tcx.sess.delay_span_bug(tcx.def_span(expr_did), msg); + tcx.sess.delay_bug_unless_error(tcx.def_span(expr_did), msg); None } } diff --git a/compiler/rustc_middle/src/ty/consts.rs b/compiler/rustc_middle/src/ty/consts.rs index 884ae7f5da284..c7e80e82c2a7e 100644 --- a/compiler/rustc_middle/src/ty/consts.rs +++ b/compiler/rustc_middle/src/ty/consts.rs @@ -122,7 +122,7 @@ impl<'tcx> Const<'tcx> { match tcx.at(expr.span).lit_to_const(lit_input) { Ok(c) => return Some(c), Err(e) => { - tcx.sess.delay_span_bug( + tcx.sess.delay_bug_unless_error( expr.span, &format!("Const::from_anon_const: couldn't lit_to_const {:?}", e), ); diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs index 796daa7646f9c..4a5652d335776 100644 --- a/compiler/rustc_middle/src/ty/context.rs +++ b/compiler/rustc_middle/src/ty/context.rs @@ -653,8 +653,10 @@ impl<'tcx> TyCtxt<'tcx> { { Bound::Included(a) } else { - self.sess - .delay_span_bug(attr.span, "invalid rustc_layout_scalar_valid_range attribute"); + self.sess.delay_bug_unless_error( + attr.span, + "invalid rustc_layout_scalar_valid_range attribute", + ); Bound::Unbounded } }; @@ -722,17 +724,17 @@ impl<'tcx> TyCtxt<'tcx> { self.mk_ty(Error(reported)) } - /// Constructs a `TyKind::Error` type and registers a `delay_span_bug` to ensure it gets used. + /// Constructs a `TyKind::Error` type and registers a `delay_bug_unless_error` to ensure it gets used. #[track_caller] pub fn ty_error_misc(self) -> Ty<'tcx> { self.ty_error_with_message(DUMMY_SP, "TyKind::Error constructed but no error reported") } - /// Constructs a `TyKind::Error` type and registers a `delay_span_bug` with the given `msg` to + /// Constructs a `TyKind::Error` type and registers a `delay_bug_unless_error` with the given `msg` to /// ensure it gets used. #[track_caller] pub fn ty_error_with_message>(self, span: S, msg: &str) -> Ty<'tcx> { - let reported = self.sess.delay_span_bug(span, msg); + let reported = self.sess.delay_bug_unless_error(span, msg); self.mk_ty(Error(reported)) } @@ -742,7 +744,7 @@ impl<'tcx> TyCtxt<'tcx> { self.intern_region(ty::ReError(reported)) } - /// Constructs a `RegionKind::ReError` lifetime and registers a `delay_span_bug` to ensure it + /// Constructs a `RegionKind::ReError` lifetime and registers a `delay_bug_unless_error` to ensure it /// gets used. #[track_caller] pub fn mk_re_error_misc(self) -> Region<'tcx> { @@ -752,11 +754,11 @@ impl<'tcx> TyCtxt<'tcx> { ) } - /// Constructs a `RegionKind::ReError` lifetime and registers a `delay_span_bug` with the given + /// Constructs a `RegionKind::ReError` lifetime and registers a `delay_bug_unless_error` with the given /// `msg` to ensure it gets used. #[track_caller] pub fn mk_re_error_with_message>(self, span: S, msg: &str) -> Region<'tcx> { - let reported = self.sess.delay_span_bug(span, msg); + let reported = self.sess.delay_bug_unless_error(span, msg); self.mk_re_error(reported) } @@ -788,7 +790,7 @@ impl<'tcx> TyCtxt<'tcx> { span: S, msg: &str, ) -> Const<'tcx> { - let reported = self.sess.delay_span_bug(span, msg); + let reported = self.sess.delay_bug_unless_error(span, msg); self.mk_const(ty::ConstKind::Error(reported), ty) } @@ -2456,13 +2458,13 @@ impl<'tcx> TyCtxt<'tcx> { } impl<'tcx> TyCtxtAt<'tcx> { - /// Constructs a `TyKind::Error` type and registers a `delay_span_bug` to ensure it gets used. + /// Constructs a `TyKind::Error` type and registers a `delay_bug_unless_error` to ensure it gets used. #[track_caller] pub fn ty_error_misc(self) -> Ty<'tcx> { self.tcx.ty_error_with_message(self.span, "TyKind::Error constructed but no error reported") } - /// Constructs a `TyKind::Error` type and registers a `delay_span_bug` with the given `msg to + /// Constructs a `TyKind::Error` type and registers a `delay_bug_unless_error` with the given `msg to /// ensure it gets used. #[track_caller] pub fn ty_error_with_message(self, msg: &str) -> Ty<'tcx> { diff --git a/compiler/rustc_middle/src/ty/layout.rs b/compiler/rustc_middle/src/ty/layout.rs index 146803df02bcd..5d8ecb518289d 100644 --- a/compiler/rustc_middle/src/ty/layout.rs +++ b/compiler/rustc_middle/src/ty/layout.rs @@ -228,7 +228,7 @@ impl<'tcx> LayoutCalculator for LayoutCx<'tcx, TyCtxt<'tcx>> { type TargetDataLayoutRef = &'tcx TargetDataLayout; fn delay_bug(&self, txt: &str) { - self.tcx.sess.delay_span_bug(DUMMY_SP, txt); + self.tcx.sess.delay_bug_unless_error(DUMMY_SP, txt); } fn current_data_layout(&self) -> Self::TargetDataLayoutRef { diff --git a/compiler/rustc_middle/src/ty/print/pretty.rs b/compiler/rustc_middle/src/ty/print/pretty.rs index fb020ac8c1799..2b80d51589790 100644 --- a/compiler/rustc_middle/src/ty/print/pretty.rs +++ b/compiler/rustc_middle/src/ty/print/pretty.rs @@ -2947,7 +2947,7 @@ fn trimmed_def_paths(tcx: TyCtxt<'_>, (): ()) -> FxHashMap { // // For good paths causing this bug, the `rustc_middle::ty::print::with_no_trimmed_paths` // wrapper can be used to suppress this query, in exchange for full paths being formatted. - tcx.sess.delay_bug_unless_diagnostic_emitted( + tcx.sess.delay_bug_unless_diagnostic( "trimmed_def_paths constructed but no diagnostic emitted; \ use `DelayDm` for lints or `with_no_trimmed_paths` for debugging", ); diff --git a/compiler/rustc_middle/src/ty/typeck_results.rs b/compiler/rustc_middle/src/ty/typeck_results.rs index 9beaac87183a7..3b59784c7cd82 100644 --- a/compiler/rustc_middle/src/ty/typeck_results.rs +++ b/compiler/rustc_middle/src/ty/typeck_results.rs @@ -458,7 +458,7 @@ impl<'tcx> TypeckResults<'tcx> { pub fn extract_binding_mode(&self, s: &Session, id: HirId, sp: Span) -> Option { self.pat_binding_modes().get(id).copied().or_else(|| { - s.delay_span_bug(sp, "missing binding mode"); + s.delay_bug_unless_error(sp, "missing binding mode"); None }) } diff --git a/compiler/rustc_middle/src/util/bug.rs b/compiler/rustc_middle/src/util/bug.rs index b73ae59390535..f4c39909a6c03 100644 --- a/compiler/rustc_middle/src/util/bug.rs +++ b/compiler/rustc_middle/src/util/bug.rs @@ -38,11 +38,11 @@ fn opt_span_bug_fmt>( }) } -/// A query to trigger a `delay_span_bug`. Clearly, if one has a `tcx` one can already trigger a -/// `delay_span_bug`, so what is the point of this? It exists to help us test `delay_span_bug`'s +/// A query to trigger a `delay_bug_unless_error`. Clearly, if one has a `tcx` one can already trigger a +/// `delay_bug_unless_error`, so what is the point of this? It exists to help us test `delay_bug_unless_error`'s /// interactions with the query system and incremental. pub fn trigger_delay_span_bug(tcx: TyCtxt<'_>, key: rustc_hir::def_id::DefId) { - tcx.sess.delay_span_bug( + tcx.sess.delay_bug_unless_error( tcx.def_span(key), "delayed span bug triggered by #[rustc_error(delay_span_bug_from_inside_query)]", ); diff --git a/compiler/rustc_mir_build/src/build/expr/as_constant.rs b/compiler/rustc_mir_build/src/build/expr/as_constant.rs index 1d96893c7a3ea..7351d7588dc72 100644 --- a/compiler/rustc_mir_build/src/build/expr/as_constant.rs +++ b/compiler/rustc_mir_build/src/build/expr/as_constant.rs @@ -116,7 +116,7 @@ pub(crate) fn lit_to_mir_constant<'tcx>( let width = tcx .layout_of(param_ty) .map_err(|_| { - LitToConstError::Reported(tcx.sess.delay_span_bug( + LitToConstError::Reported(tcx.sess.delay_bug_unless_error( DUMMY_SP, format!("couldn't compute width of literal: {:?}", lit_input.lit), )) @@ -154,7 +154,7 @@ pub(crate) fn lit_to_mir_constant<'tcx>( } (ast::LitKind::Float(n, _), ty::Float(fty)) => parse_float_into_constval(*n, *fty, neg) .ok_or_else(|| { - LitToConstError::Reported(tcx.sess.delay_span_bug( + LitToConstError::Reported(tcx.sess.delay_bug_unless_error( DUMMY_SP, format!("couldn't parse float literal: {:?}", lit_input.lit), )) @@ -163,7 +163,8 @@ pub(crate) fn lit_to_mir_constant<'tcx>( (ast::LitKind::Char(c), ty::Char) => ConstValue::Scalar(Scalar::from_char(*c)), (ast::LitKind::Err, _) => { return Err(LitToConstError::Reported( - tcx.sess.delay_span_bug(DUMMY_SP, "encountered LitKind::Err during mir build"), + tcx.sess + .delay_bug_unless_error(DUMMY_SP, "encountered LitKind::Err during mir build"), )); } _ => return Err(LitToConstError::TypeError), diff --git a/compiler/rustc_mir_build/src/check_unsafety.rs b/compiler/rustc_mir_build/src/check_unsafety.rs index 03a7f2d70faeb..d3a8475cf08f9 100644 --- a/compiler/rustc_mir_build/src/check_unsafety.rs +++ b/compiler/rustc_mir_build/src/check_unsafety.rs @@ -415,7 +415,7 @@ impl<'a, 'tcx> Visitor<'a, 'tcx> for UnsafetyVisitor<'a, 'tcx> { if let Some((assigned_ty, assignment_span)) = self.assignment_info { if assigned_ty.needs_drop(self.tcx, self.param_env) { // This would be unsafe, but should be outright impossible since we reject such unions. - self.tcx.sess.delay_span_bug(assignment_span, format!("union fields that need dropping should be impossible: {assigned_ty}")); + self.tcx.sess.delay_bug_unless_error(assignment_span, format!("union fields that need dropping should be impossible: {assigned_ty}")); } } else { self.requires_unsafe(expr.span, AccessToUnionField); diff --git a/compiler/rustc_mir_build/src/thir/constant.rs b/compiler/rustc_mir_build/src/thir/constant.rs index 57ae6a3652df5..109eee80d1058 100644 --- a/compiler/rustc_mir_build/src/thir/constant.rs +++ b/compiler/rustc_mir_build/src/thir/constant.rs @@ -14,7 +14,7 @@ pub(crate) fn lit_to_const<'tcx>( let width = tcx .layout_of(param_ty) .map_err(|_| { - LitToConstError::Reported(tcx.sess.delay_span_bug( + LitToConstError::Reported(tcx.sess.delay_bug_unless_error( DUMMY_SP, format!("couldn't compute width of literal: {:?}", lit_input.lit), )) @@ -55,7 +55,8 @@ pub(crate) fn lit_to_const<'tcx>( (ast::LitKind::Char(c), ty::Char) => ty::ValTree::from_scalar_int((*c).into()), (ast::LitKind::Err, _) => { return Err(LitToConstError::Reported( - tcx.sess.delay_span_bug(DUMMY_SP, "encountered LitKind::Err during mir build"), + tcx.sess + .delay_bug_unless_error(DUMMY_SP, "encountered LitKind::Err during mir build"), )); } _ => return Err(LitToConstError::TypeError), diff --git a/compiler/rustc_mir_build/src/thir/pattern/mod.rs b/compiler/rustc_mir_build/src/thir/pattern/mod.rs index 41306dd80fbdd..09bce6532d17b 100644 --- a/compiler/rustc_mir_build/src/thir/pattern/mod.rs +++ b/compiler/rustc_mir_build/src/thir/pattern/mod.rs @@ -56,7 +56,7 @@ pub(super) fn pat_from_hir<'a, 'tcx>( let result = pcx.lower_pattern(pat); if !pcx.errors.is_empty() { let msg = format!("encountered errors lowering pattern: {:?}", pcx.errors); - tcx.sess.delay_span_bug(pat.span, &msg); + tcx.sess.delay_bug_unless_error(pat.span, &msg); } debug!("pat_from_hir({:?}) = {:?}", pat, result); result @@ -259,7 +259,7 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> { "found bad range pattern `{:?}` outside of error recovery", (&lo, &hi), ); - self.tcx.sess.delay_span_bug(pat.span, msg); + self.tcx.sess.delay_bug_unless_error(pat.span, msg); PatKind::Wild } }; diff --git a/compiler/rustc_mir_transform/src/check_unsafety.rs b/compiler/rustc_mir_transform/src/check_unsafety.rs index d00ee1f4babe8..c96f897fb6ab4 100644 --- a/compiler/rustc_mir_transform/src/check_unsafety.rs +++ b/compiler/rustc_mir_transform/src/check_unsafety.rs @@ -239,7 +239,7 @@ impl<'tcx> Visitor<'tcx> for UnsafetyChecker<'_, 'tcx> { let assigned_ty = place.ty(&self.body.local_decls, self.tcx).ty; if assigned_ty.needs_drop(self.tcx, self.param_env) { // This would be unsafe, but should be outright impossible since we reject such unions. - self.tcx.sess.delay_span_bug( + self.tcx.sess.delay_bug_unless_error( self.source_info.span, format!("union fields that need dropping should be impossible: {assigned_ty}") ); diff --git a/compiler/rustc_mir_transform/src/elaborate_drops.rs b/compiler/rustc_mir_transform/src/elaborate_drops.rs index c2ff8645635e0..3aa4e4a21de62 100644 --- a/compiler/rustc_mir_transform/src/elaborate_drops.rs +++ b/compiler/rustc_mir_transform/src/elaborate_drops.rs @@ -58,7 +58,7 @@ impl<'tcx> MirPass<'tcx> for ElaborateDrops { let (side_table, move_data) = match MoveData::gather_moves(body, tcx, param_env) { Ok(move_data) => move_data, Err((move_data, _)) => { - tcx.sess.delay_span_bug( + tcx.sess.delay_bug_unless_error( body.span, "No `move_errors` should be allowed in MIR borrowck", ); @@ -354,7 +354,7 @@ impl<'b, 'tcx> ElaborateDropsCtxt<'b, 'tcx> { } if maybe_dead { - self.tcx.sess.delay_span_bug( + self.tcx.sess.delay_bug_unless_error( terminator.source_info.span, &format!( "drop of untracked, uninitialized value {:?}, place {:?} ({:?})", @@ -410,7 +410,7 @@ impl<'b, 'tcx> ElaborateDropsCtxt<'b, 'tcx> { bb, ), LookupResult::Parent(..) => { - self.tcx.sess.delay_span_bug( + self.tcx.sess.delay_bug_unless_error( terminator.source_info.span, &format!("drop of untracked value {:?}", bb), ); diff --git a/compiler/rustc_mir_transform/src/generator.rs b/compiler/rustc_mir_transform/src/generator.rs index dc5f88f24f801..3858329ffc1b7 100644 --- a/compiler/rustc_mir_transform/src/generator.rs +++ b/compiler/rustc_mir_transform/src/generator.rs @@ -863,7 +863,7 @@ fn sanitize_witness<'tcx>( tcx.normalize_erasing_late_bound_regions(param_env, interior_tys) } _ => { - tcx.sess.delay_span_bug( + tcx.sess.delay_bug_unless_error( body.span, &format!("unexpected generator witness type {:?}", witness.kind()), ); @@ -1439,8 +1439,10 @@ impl<'tcx> MirPass<'tcx> for StateTransform { ) } _ => { - tcx.sess - .delay_span_bug(body.span, &format!("unexpected generator type {}", gen_ty)); + tcx.sess.delay_bug_unless_error( + body.span, + &format!("unexpected generator type {}", gen_ty), + ); return; } }; diff --git a/compiler/rustc_mir_transform/src/lib.rs b/compiler/rustc_mir_transform/src/lib.rs index bdd1e8fb98f75..8dbcace14a313 100644 --- a/compiler/rustc_mir_transform/src/lib.rs +++ b/compiler/rustc_mir_transform/src/lib.rs @@ -253,7 +253,7 @@ fn mir_const_qualif(tcx: TyCtxt<'_>, def: ty::WithOptConstParam) -> let body = &tcx.mir_const(def).borrow(); if body.return_ty().references_error() { - tcx.sess.delay_span_bug(body.span, "mir_const_qualif: MIR had errors"); + tcx.sess.delay_bug_unless_error(body.span, "mir_const_qualif: MIR had errors"); return Default::default(); } diff --git a/compiler/rustc_parse/src/parser/attr_wrapper.rs b/compiler/rustc_parse/src/parser/attr_wrapper.rs index dbd3b76786f42..0b52a3af8c9cd 100644 --- a/compiler/rustc_parse/src/parser/attr_wrapper.rs +++ b/compiler/rustc_parse/src/parser/attr_wrapper.rs @@ -41,7 +41,7 @@ impl AttrWrapper { } pub(crate) fn take_for_recovery(self, sess: &ParseSess) -> AttrVec { - sess.span_diagnostic.delay_span_bug( + sess.span_diagnostic.delay_bug_unless_error( self.attrs.get(0).map(|attr| attr.span).unwrap_or(DUMMY_SP), "AttrVec is taken for recovery but no error is produced", ); @@ -269,7 +269,7 @@ impl<'a> Parser<'a> { } else { self.sess .span_diagnostic - .delay_span_bug(inner_attr.span, "Missing token range for attribute"); + .delay_bug_unless_error(inner_attr.span, "Missing token range for attribute"); } } diff --git a/compiler/rustc_parse/src/parser/pat.rs b/compiler/rustc_parse/src/parser/pat.rs index 8e920f1c42143..08fcff32ffc82 100644 --- a/compiler/rustc_parse/src/parser/pat.rs +++ b/compiler/rustc_parse/src/parser/pat.rs @@ -220,8 +220,8 @@ impl<'a> Parser<'a> { // emit again. // FIXME(#100717): pass `TopLevelOrPatternNotAllowed::* { sub: None }` to - // `delay_span_bug()` instead of fluent message - self.sess.span_diagnostic.delay_span_bug( + // `delay_bug_unless_error()` instead of fluent message + self.sess.span_diagnostic.delay_bug_unless_error( span, match syntax_loc { PatternLocation::LetBinding => { diff --git a/compiler/rustc_passes/src/entry.rs b/compiler/rustc_passes/src/entry.rs index b327ba63330ba..c4433ee0d4402 100644 --- a/compiler/rustc_passes/src/entry.rs +++ b/compiler/rustc_passes/src/entry.rs @@ -189,7 +189,7 @@ fn no_main_err(tcx: TyCtxt<'_>, visitor: &EntryContext<'_>) { if *tcx.sess.parse_sess.reached_eof.borrow() { // There's an unclosed brace that made the parser reach `Eof`, we shouldn't complain about // the missing `fn main()` then as it might have been hidden inside an unclosed block. - tcx.sess.delay_span_bug(sp, "`main` not found, but expected unclosed brace error"); + tcx.sess.delay_bug_unless_error(sp, "`main` not found, but expected unclosed brace error"); return; } diff --git a/compiler/rustc_passes/src/hir_id_validator.rs b/compiler/rustc_passes/src/hir_id_validator.rs index de0e50a65de6e..1cde164007719 100644 --- a/compiler/rustc_passes/src/hir_id_validator.rs +++ b/compiler/rustc_passes/src/hir_id_validator.rs @@ -33,7 +33,7 @@ pub fn check_crate(tcx: TyCtxt<'_>) { if !errors.is_empty() { let message = errors.iter().fold(String::new(), |s1, s2| s1 + "\n" + s2); - tcx.sess.delay_span_bug(rustc_span::DUMMY_SP, &message); + tcx.sess.delay_bug_unless_error(rustc_span::DUMMY_SP, &message); } } } diff --git a/compiler/rustc_privacy/src/lib.rs b/compiler/rustc_privacy/src/lib.rs index 50176c8023288..3e99ac6160b06 100644 --- a/compiler/rustc_privacy/src/lib.rs +++ b/compiler/rustc_privacy/src/lib.rs @@ -1294,7 +1294,7 @@ impl<'tcx> Visitor<'tcx> for TypePrivacyVisitor<'tcx> { } else { self.tcx .sess - .delay_span_bug(expr.span, "no type-dependent def for method call"); + .delay_bug_unless_error(expr.span, "no type-dependent def for method call"); } } _ => {} @@ -2092,7 +2092,7 @@ fn local_visibility(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Visibility { .. }) => tr.path.res.opt_def_id().map_or_else( || { - tcx.sess.delay_span_bug(tr.path.span, "trait without a def-id"); + tcx.sess.delay_bug_unless_error(tr.path.span, "trait without a def-id"); ty::Visibility::Public }, |def_id| tcx.visibility(def_id).expect_local(), diff --git a/compiler/rustc_resolve/src/ident.rs b/compiler/rustc_resolve/src/ident.rs index ba7f04239c35f..40358576bca97 100644 --- a/compiler/rustc_resolve/src/ident.rs +++ b/compiler/rustc_resolve/src/ident.rs @@ -1208,7 +1208,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { is_type: true, }, ); - self.tcx.sess.delay_span_bug(span, CG_BUG_STR); + self.tcx.sess.delay_bug_unless_error(span, CG_BUG_STR); } return Res::Err; @@ -1268,7 +1268,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { is_type: false, }, ); - self.tcx.sess.delay_span_bug(span, CG_BUG_STR); + self.tcx.sess.delay_bug_unless_error(span, CG_BUG_STR); } return Res::Err; diff --git a/compiler/rustc_resolve/src/late.rs b/compiler/rustc_resolve/src/late.rs index 7df17376b3eae..46c751408ca55 100644 --- a/compiler/rustc_resolve/src/late.rs +++ b/compiler/rustc_resolve/src/late.rs @@ -3385,7 +3385,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> { Res::SelfCtor(_) => { // We resolve `Self` in pattern position as an ident sometimes during recovery, // so delay a bug instead of ICEing. - self.r.tcx.sess.delay_span_bug( + self.r.tcx.sess.delay_bug_unless_error( ident.span, "unexpected `SelfCtor` in pattern, expected identifier" ); diff --git a/compiler/rustc_resolve/src/macros.rs b/compiler/rustc_resolve/src/macros.rs index b38c11e8bb8d4..8661cac6c6b26 100644 --- a/compiler/rustc_resolve/src/macros.rs +++ b/compiler/rustc_resolve/src/macros.rs @@ -661,7 +661,9 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { // Make sure compilation does not succeed if preferred macro resolution // has changed after the macro had been expanded. In theory all such // situations should be reported as errors, so this is a bug. - this.tcx.sess.delay_span_bug(span, "inconsistent resolution for a macro"); + this.tcx + .sess + .delay_bug_unless_error(span, "inconsistent resolution for a macro"); } } else { // It's possible that the macro was unresolved (indeterminate) and silently diff --git a/compiler/rustc_session/src/config.rs b/compiler/rustc_session/src/config.rs index 6d2143a94641a..0ecc0a1b8f4f5 100644 --- a/compiler/rustc_session/src/config.rs +++ b/compiler/rustc_session/src/config.rs @@ -413,9 +413,9 @@ pub enum TrimmedDefPaths { /// `try_print_trimmed_def_path` never prints a trimmed path and never calls the expensive query #[default] Never, - /// `try_print_trimmed_def_path` calls the expensive query, the query doesn't call `delay_bug_unless_diagnostic_emitted` + /// `try_print_trimmed_def_path` calls the expensive query, the query doesn't call `delay_bug_unless_diagnostic` Always, - /// `try_print_trimmed_def_path` calls the expensive query, the query calls `delay_bug_unless_diagnostic_emitted` + /// `try_print_trimmed_def_path` calls the expensive query, the query calls `delay_bug_unless_diagnostic` GoodPath, } diff --git a/compiler/rustc_session/src/options.rs b/compiler/rustc_session/src/options.rs index 1f3eb8d4832fe..cde606a453a1e 100644 --- a/compiler/rustc_session/src/options.rs +++ b/compiler/rustc_session/src/options.rs @@ -1618,7 +1618,7 @@ options! { remap_cwd_prefix: Option = (None, parse_opt_pathbuf, [TRACKED], "remap paths under the current working directory to this path prefix"), report_delayed_bugs: bool = (false, parse_bool, [TRACKED], - "immediately print bugs registered with `delay_span_bug` (default: no)"), + "immediately print bugs registered with `delay_bug_unless_error` (default: no)"), sanitizer: SanitizerSet = (SanitizerSet::empty(), parse_sanitizers, [TRACKED], "use a sanitizer"), sanitizer_memory_track_origins: usize = (0, parse_sanitizer_memory_track_origins, [TRACKED], diff --git a/compiler/rustc_session/src/session.rs b/compiler/rustc_session/src/session.rs index 0f23e13314388..812e54b4eefab 100644 --- a/compiler/rustc_session/src/session.rs +++ b/compiler/rustc_session/src/session.rs @@ -573,7 +573,7 @@ impl Session { if self.err_count() == old_count { Ok(result) } else { - Err(self.delay_span_bug( + Err(self.delay_bug_unless_error( rustc_span::DUMMY_SP, "`self.err_count()` changed but an error was not emitted", )) @@ -620,18 +620,18 @@ impl Session { /// /// [`DUMMY_SP`]: rustc_span::DUMMY_SP #[track_caller] - pub fn delay_span_bug>( + pub fn delay_bug_unless_error>( &self, sp: S, msg: impl Into, ) -> ErrorGuaranteed { - self.diagnostic().delay_span_bug(sp, msg) + self.diagnostic().delay_bug_unless_error(sp, msg) } /// Used for code paths of expensive computations that should only take place when /// warnings or errors are emitted. If no messages are emitted ("good path"), then /// it's likely a bug. - pub fn delay_bug_unless_diagnostic_emitted(&self, msg: impl Into) { + pub fn delay_bug_unless_diagnostic(&self, msg: impl Into) { if self.opts.unstable_opts.print_type_sizes || self.opts.unstable_opts.query_dep_graph || self.opts.unstable_opts.dump_mir.is_some() @@ -642,7 +642,7 @@ impl Session { return; } - self.diagnostic().delay_bug_unless_diagnostic_emitted(msg) + self.diagnostic().delay_bug_unless_diagnostic(msg) } #[rustc_lint_diagnostics] @@ -892,7 +892,7 @@ impl Session { if fuel.remaining == 0 && !fuel.out_of_fuel { if self.diagnostic().can_emit_warnings() { // We only call `msg` in case we can actually emit warnings. - // Otherwise, this could cause a `delay_bug_unless_diagnostic_emitted` to + // Otherwise, this could cause a `delay_bug_unless_diagnostic` to // trigger (issue #79546). self.emit_warning(errors::OptimisationFuelExhausted { msg: msg() }); } diff --git a/compiler/rustc_trait_selection/src/solve/project_goals.rs b/compiler/rustc_trait_selection/src/solve/project_goals.rs index d4fdd54573751..79156143c11e4 100644 --- a/compiler/rustc_trait_selection/src/solve/project_goals.rs +++ b/compiler/rustc_trait_selection/src/solve/project_goals.rs @@ -173,7 +173,7 @@ impl<'tcx> assembly::GoalKind<'tcx> for ProjectionPredicate<'tcx> { }; if !assoc_def.item.defaultness(tcx).has_value() { - tcx.sess.delay_span_bug( + tcx.sess.delay_bug_unless_error( tcx.def_span(assoc_def.item.def_id), "missing value for assoc item in impl", ); diff --git a/compiler/rustc_trait_selection/src/traits/coherence.rs b/compiler/rustc_trait_selection/src/traits/coherence.rs index 6b688c322c786..70fc08d1fc400 100644 --- a/compiler/rustc_trait_selection/src/traits/coherence.rs +++ b/compiler/rustc_trait_selection/src/traits/coherence.rs @@ -298,7 +298,7 @@ fn negative_impl(tcx: TyCtxt<'_>, impl1_def_id: DefId, impl2_def_id: DefId) -> b ) { Ok(s) => s, Err(err) => { - tcx.sess.delay_span_bug( + tcx.sess.delay_bug_unless_error( tcx.def_span(impl1_def_id), format!("failed to fully normalize {:?}: {:?}", impl1_def_id, err), ); diff --git a/compiler/rustc_trait_selection/src/traits/const_evaluatable.rs b/compiler/rustc_trait_selection/src/traits/const_evaluatable.rs index 345e84990ed03..6c9e278fbfbc7 100644 --- a/compiler/rustc_trait_selection/src/traits/const_evaluatable.rs +++ b/compiler/rustc_trait_selection/src/traits/const_evaluatable.rs @@ -65,7 +65,7 @@ pub fn is_const_evaluatable<'tcx>( // FIXME(generic_const_exprs): we have a `ConstKind::Expr` which is fully concrete, but // currently it is not possible to evaluate `ConstKind::Expr` so we are unable to tell if it // is evaluatable or not. For now we just ICE until this is implemented. - Err(NotConstEvaluatable::Error(tcx.sess.delay_span_bug( + Err(NotConstEvaluatable::Error(tcx.sess.delay_bug_unless_error( span, "evaluating `ConstKind::Expr` is not currently supported", ))) @@ -74,7 +74,7 @@ pub fn is_const_evaluatable<'tcx>( let concrete = infcx.const_eval_resolve(param_env, uv, Some(span)); match concrete { Err(ErrorHandled::TooGeneric) => { - Err(NotConstEvaluatable::Error(infcx.tcx.sess.delay_span_bug( + Err(NotConstEvaluatable::Error(infcx.tcx.sess.delay_bug_unless_error( span, "Missing value for constant, but no error reported?", ))) @@ -138,10 +138,10 @@ pub fn is_const_evaluatable<'tcx>( } else if uv.has_non_region_param() { NotConstEvaluatable::MentionsParam } else { - let guar = infcx - .tcx - .sess - .delay_span_bug(span, "Missing value for constant, but no error reported?"); + let guar = infcx.tcx.sess.delay_bug_unless_error( + span, + "Missing value for constant, but no error reported?", + ); NotConstEvaluatable::Error(guar) }; diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs index a844a1494e262..d457c78462021 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs @@ -474,7 +474,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> { } } - self.tcx.sess.delay_span_bug(DUMMY_SP, "expected fullfillment errors") + self.tcx.sess.delay_bug_unless_error(DUMMY_SP, "expected fullfillment errors") } /// Reports that an overflow has occurred and halts compilation. We @@ -621,7 +621,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> { let mut span = obligation.cause.span; // FIXME: statically guarantee this by tainting after the diagnostic is emitted self.set_tainted_by_errors( - tcx.sess.delay_span_bug(span, "`report_selection_error` did not emit an error"), + tcx.sess.delay_bug_unless_error(span, "`report_selection_error` did not emit an error"), ); let mut err = match *error { @@ -1467,12 +1467,12 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> { // Already reported in the query. SelectionError::NotConstEvaluatable(NotConstEvaluatable::Error(_)) => { // FIXME(eddyb) remove this once `ErrorGuaranteed` becomes a proof token. - self.tcx.sess.delay_span_bug(span, "`ErrorGuaranteed` without an error"); + self.tcx.sess.delay_bug_unless_error(span, "`ErrorGuaranteed` without an error"); return; } // Already reported. Overflow(OverflowError::Error(_)) => { - self.tcx.sess.delay_span_bug(span, "`OverflowError` has been reported"); + self.tcx.sess.delay_bug_unless_error(span, "`OverflowError` has been reported"); return; } Overflow(_) => { diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/on_unimplemented.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/on_unimplemented.rs index b3bf9ad599acc..14ed6f0aa2198 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/on_unimplemented.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/on_unimplemented.rs @@ -461,8 +461,9 @@ impl<'tcx> OnUnimplementedDirective { append_const_msg: None, })) } else { - let reported = - tcx.sess.delay_span_bug(DUMMY_SP, "of_item: neither meta_item_list nor value_str"); + let reported = tcx + .sess + .delay_bug_unless_error(DUMMY_SP, "of_item: neither meta_item_list nor value_str"); return Err(reported); }; debug!("of_item({:?}) = {:?}", item_def_id, result); diff --git a/compiler/rustc_trait_selection/src/traits/misc.rs b/compiler/rustc_trait_selection/src/traits/misc.rs index b94346b09560a..a4f03290a9fdc 100644 --- a/compiler/rustc_trait_selection/src/traits/misc.rs +++ b/compiler/rustc_trait_selection/src/traits/misc.rs @@ -88,7 +88,7 @@ pub fn type_allowed_to_implement_copy<'tcx>( let ty = ocx.normalize(&normalization_cause, param_env, unnormalized_ty); let normalization_errors = ocx.select_where_possible(); if !normalization_errors.is_empty() { - tcx.sess.delay_span_bug(field_span, format!("couldn't normalize struct field `{unnormalized_ty}` when checking Copy implementation")); + tcx.sess.delay_bug_unless_error(field_span, format!("couldn't normalize struct field `{unnormalized_ty}` when checking Copy implementation")); continue; } diff --git a/compiler/rustc_trait_selection/src/traits/mod.rs b/compiler/rustc_trait_selection/src/traits/mod.rs index c8b233bfe26aa..83b8af7dc3ad5 100644 --- a/compiler/rustc_trait_selection/src/traits/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/mod.rs @@ -224,7 +224,7 @@ fn do_normalize_predicates<'tcx>( // the normalized predicates. let errors = infcx.resolve_regions(&outlives_env); if !errors.is_empty() { - tcx.sess.delay_span_bug( + tcx.sess.delay_bug_unless_error( span, format!("failed region resolution while normalizing {elaborated_env:?}: {errors:?}"), ); diff --git a/compiler/rustc_trait_selection/src/traits/object_safety.rs b/compiler/rustc_trait_selection/src/traits/object_safety.rs index b87f75422ef60..d07226658ecec 100644 --- a/compiler/rustc_trait_selection/src/traits/object_safety.rs +++ b/compiler/rustc_trait_selection/src/traits/object_safety.rs @@ -506,7 +506,7 @@ fn virtual_call_violation_for_method<'tcx>( Ok(layout) => Some(layout.abi), Err(err) => { // #78372 - tcx.sess.delay_span_bug( + tcx.sess.delay_bug_unless_error( tcx.def_span(method.def_id), &format!("error: {}\n while computing layout for type {:?}", err, ty), ); @@ -522,7 +522,7 @@ fn virtual_call_violation_for_method<'tcx>( match abi_of_ty(unit_receiver_ty) { Some(Abi::Scalar(..)) => (), abi => { - tcx.sess.delay_span_bug( + tcx.sess.delay_bug_unless_error( tcx.def_span(method.def_id), &format!( "receiver when `Self = ()` should have a Scalar ABI; found {:?}", @@ -541,7 +541,7 @@ fn virtual_call_violation_for_method<'tcx>( match abi_of_ty(trait_object_receiver) { Some(Abi::ScalarPair(..)) => (), abi => { - tcx.sess.delay_span_bug( + tcx.sess.delay_bug_unless_error( tcx.def_span(method.def_id), &format!( "receiver when `Self = {}` should have a ScalarPair ABI; found {:?}", @@ -595,7 +595,7 @@ fn virtual_call_violation_for_method<'tcx>( // would already have reported an error at the definition of the // auto trait. if pred_trait_ref.substs.len() != 1 { - tcx.sess.diagnostic().delay_span_bug( + tcx.sess.diagnostic().delay_bug_unless_error( span, "auto traits cannot have generic parameters", ); diff --git a/compiler/rustc_trait_selection/src/traits/outlives_bounds.rs b/compiler/rustc_trait_selection/src/traits/outlives_bounds.rs index 6cb64ad574f5b..a8858feb04e3e 100644 --- a/compiler/rustc_trait_selection/src/traits/outlives_bounds.rs +++ b/compiler/rustc_trait_selection/src/traits/outlives_bounds.rs @@ -59,7 +59,7 @@ impl<'a, 'tcx: 'a> InferCtxtExt<'a, 'tcx> for InferCtxt<'tcx> { let result = match result { Ok(r) => r, Err(NoSolution) => { - self.tcx.sess.delay_span_bug( + self.tcx.sess.delay_bug_unless_error( span, "implied_outlives_bounds failed to solve all obligations", ); @@ -88,7 +88,7 @@ impl<'a, 'tcx: 'a> InferCtxtExt<'a, 'tcx> for InferCtxt<'tcx> { span_bug!(span, "{:#?}", constraints.member_constraints); } if !errors.is_empty() { - self.tcx.sess.delay_span_bug( + self.tcx.sess.delay_bug_unless_error( span, "implied_outlives_bounds failed to solve obligations from instantiation", ); diff --git a/compiler/rustc_trait_selection/src/traits/project.rs b/compiler/rustc_trait_selection/src/traits/project.rs index 14bba00b57e05..289be8c103be2 100644 --- a/compiler/rustc_trait_selection/src/traits/project.rs +++ b/compiler/rustc_trait_selection/src/traits/project.rs @@ -1730,7 +1730,7 @@ fn assemble_candidates_from_impls<'cx, 'tcx>( | super::ImplSource::TraitUpcasting(_) | super::ImplSource::ConstDestruct(_) => { // These traits have no associated types. - selcx.tcx().sess.delay_span_bug( + selcx.tcx().sess.delay_bug_unless_error( obligation.cause.span, &format!("Cannot project an associated type from `{:?}`", impl_source), ); diff --git a/compiler/rustc_trait_selection/src/traits/query/normalize.rs b/compiler/rustc_trait_selection/src/traits/query/normalize.rs index b0cec3ce7a3ea..f26eba9c80e36 100644 --- a/compiler/rustc_trait_selection/src/traits/query/normalize.rs +++ b/compiler/rustc_trait_selection/src/traits/query/normalize.rs @@ -269,7 +269,7 @@ impl<'cx, 'tcx> FallibleTypeFolder> for QueryNormalizer<'cx, 'tcx> // Rustdoc normalizes possibly not well-formed types, so only // treat this as a bug if we're not in rustdoc. if !tcx.sess.opts.actually_rustdoc { - tcx.sess.delay_span_bug( + tcx.sess.delay_bug_unless_error( DUMMY_SP, format!("unexpected ambiguity: {:?} {:?}", c_data, result), ); @@ -320,7 +320,7 @@ impl<'cx, 'tcx> FallibleTypeFolder> for QueryNormalizer<'cx, 'tcx> // Rustdoc normalizes possibly not well-formed types, so only // treat this as a bug if we're not in rustdoc. if !tcx.sess.opts.actually_rustdoc { - tcx.sess.delay_span_bug( + tcx.sess.delay_bug_unless_error( DUMMY_SP, format!("unexpected ambiguity: {:?} {:?}", c_data, result), ); diff --git a/compiler/rustc_trait_selection/src/traits/query/type_op/custom.rs b/compiler/rustc_trait_selection/src/traits/query/type_op/custom.rs index 6bf3ed0d0e29a..bb88d908b0596 100644 --- a/compiler/rustc_trait_selection/src/traits/query/type_op/custom.rs +++ b/compiler/rustc_trait_selection/src/traits/query/type_op/custom.rs @@ -75,7 +75,7 @@ pub fn scrape_region_constraints<'tcx, Op: super::TypeOp<'tcx, Output = R>, R>( let InferOk { value, obligations } = infcx.commit_if_ok(|_| op())?; let errors = traits::fully_solve_obligations(infcx, obligations); if !errors.is_empty() { - infcx.tcx.sess.diagnostic().delay_span_bug( + infcx.tcx.sess.diagnostic().delay_bug_unless_error( DUMMY_SP, &format!("errors selecting obligation during MIR typeck: {:?}", errors), ); diff --git a/compiler/rustc_trait_selection/src/traits/select/confirmation.rs b/compiler/rustc_trait_selection/src/traits/select/confirmation.rs index 270f513ce3cd1..81c7725c8225c 100644 --- a/compiler/rustc_trait_selection/src/traits/select/confirmation.rs +++ b/compiler/rustc_trait_selection/src/traits/select/confirmation.rs @@ -498,7 +498,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { let defs: &ty::Generics = tcx.generics_of(assoc_type); if !defs.params.is_empty() && !tcx.features().generic_associated_types_extended { - tcx.sess.delay_span_bug( + tcx.sess.delay_bug_unless_error( obligation.cause.span, "GATs in trait object shouldn't have been considered", ); diff --git a/compiler/rustc_trait_selection/src/traits/select/mod.rs b/compiler/rustc_trait_selection/src/traits/select/mod.rs index e2fb954e31f36..e77b14c4a8467 100644 --- a/compiler/rustc_trait_selection/src/traits/select/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/select/mod.rs @@ -2443,7 +2443,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { // the placeholder trait ref may fail due the Generalizer relation // raising a CyclicalTy error due to a sub_root_var relation // for a variable being generalized... - let guar = self.infcx.tcx.sess.delay_span_bug( + let guar = self.infcx.tcx.sess.delay_bug_unless_error( obligation.cause.span, &format!( "Impl {:?} was matchable against {:?} but now is not", diff --git a/compiler/rustc_trait_selection/src/traits/specialize/mod.rs b/compiler/rustc_trait_selection/src/traits/specialize/mod.rs index d1d6a7a90cf74..98d391ef8d837 100644 --- a/compiler/rustc_trait_selection/src/traits/specialize/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/specialize/mod.rs @@ -156,7 +156,7 @@ pub(super) fn specializes(tcx: TyCtxt<'_>, (impl1_def_id, impl2_def_id): (DefId, match traits::fully_normalize(&infcx, ObligationCause::dummy(), penv, impl1_trait_ref) { Ok(impl1_trait_ref) => impl1_trait_ref, Err(_errors) => { - tcx.sess.delay_span_bug( + tcx.sess.delay_bug_unless_error( tcx.def_span(impl1_def_id), format!("failed to fully normalize {impl1_trait_ref}"), ); @@ -395,16 +395,18 @@ fn report_conflicting_impls<'tcx>( match used_to_be_allowed { None => { - let reported = if overlap.with_impl.is_local() - || tcx.orphan_check_impl(impl_def_id).is_ok() - { - let mut err = tcx.sess.struct_span_err(impl_span, msg); - err.code(error_code!(E0119)); - decorate(tcx, &overlap, impl_span, &mut err); - Some(err.emit()) - } else { - Some(tcx.sess.delay_span_bug(impl_span, "impl should have failed the orphan check")) - }; + let reported = + if overlap.with_impl.is_local() || tcx.orphan_check_impl(impl_def_id).is_ok() { + let mut err = tcx.sess.struct_span_err(impl_span, msg); + err.code(error_code!(E0119)); + decorate(tcx, &overlap, impl_span, &mut err); + Some(err.emit()) + } else { + Some(tcx.sess.delay_bug_unless_error( + impl_span, + "impl should have failed the orphan check", + )) + }; sg.has_errored = reported; } Some(kind) => { diff --git a/compiler/rustc_trait_selection/src/traits/structural_match.rs b/compiler/rustc_trait_selection/src/traits/structural_match.rs index e38ae9381c1d7..4f100a5ec472b 100644 --- a/compiler/rustc_trait_selection/src/traits/structural_match.rs +++ b/compiler/rustc_trait_selection/src/traits/structural_match.rs @@ -169,7 +169,9 @@ impl<'tcx> TypeVisitor> for Search<'tcx> { bug!("unexpected type during structural-match checking: {:?}", ty); } ty::Error(_) => { - self.tcx.sess.delay_span_bug(self.span, "ty::Error in structural-match check"); + self.tcx + .sess + .delay_bug_unless_error(self.span, "ty::Error in structural-match check"); // We still want to check other types after encountering an error, // as this may still emit relevant errors. return ControlFlow::Continue(()); diff --git a/compiler/rustc_traits/src/dropck_outlives.rs b/compiler/rustc_traits/src/dropck_outlives.rs index b5924e949146b..e61598aa8cdb8 100644 --- a/compiler/rustc_traits/src/dropck_outlives.rs +++ b/compiler/rustc_traits/src/dropck_outlives.rs @@ -188,7 +188,7 @@ fn dtorck_constraint_for_ty<'tcx>( // By the time this code runs, all type variables ought to // be fully resolved. - tcx.sess.delay_span_bug( + tcx.sess.delay_bug_unless_error( span, &format!("upvar_tys for closure not found. Expected capture information for closure {ty}",), ); @@ -230,7 +230,7 @@ fn dtorck_constraint_for_ty<'tcx>( if !substs.as_generator().is_valid() { // By the time this code runs, all type variables ought to // be fully resolved. - tcx.sess.delay_span_bug( + tcx.sess.delay_bug_unless_error( span, &format!("upvar_tys for generator not found. Expected capture information for generator {ty}",), ); diff --git a/compiler/rustc_ty_utils/src/instance.rs b/compiler/rustc_ty_utils/src/instance.rs index 2eaeca73da75f..656ad12386f68 100644 --- a/compiler/rustc_ty_utils/src/instance.rs +++ b/compiler/rustc_ty_utils/src/instance.rs @@ -109,7 +109,7 @@ fn resolve_associated_item<'tcx>( let vtbl = match tcx.codegen_select_candidate((param_env, ty::Binder::dummy(trait_ref))) { Ok(vtbl) => vtbl, Err(CodegenObligationError::Ambiguity) => { - let reported = tcx.sess.delay_span_bug( + let reported = tcx.sess.delay_bug_unless_error( tcx.def_span(trait_item_id), &format!( "encountered ambiguity selecting `{trait_ref:?}` during codegen, presuming due to \ @@ -178,7 +178,7 @@ fn resolve_associated_item<'tcx>( // Any final impl is required to define all associated items. if !leaf_def.item.defaultness(tcx).has_value() { - let guard = tcx.sess.delay_span_bug( + let guard = tcx.sess.delay_bug_unless_error( tcx.def_span(leaf_def.item.def_id), "missing value for assoc item in impl", ); diff --git a/compiler/rustc_ty_utils/src/layout.rs b/compiler/rustc_ty_utils/src/layout.rs index a400fbfe683ef..03bad86e378e1 100644 --- a/compiler/rustc_ty_utils/src/layout.rs +++ b/compiler/rustc_ty_utils/src/layout.rs @@ -85,7 +85,7 @@ fn univariant_uninterned<'tcx>( let dl = cx.data_layout(); let pack = repr.pack; if pack.is_some() && repr.align.is_some() { - cx.tcx.sess.delay_span_bug(DUMMY_SP, "struct cannot be packed and aligned"); + cx.tcx.sess.delay_bug_unless_error(DUMMY_SP, "struct cannot be packed and aligned"); return Err(LayoutError::Unknown(ty)); } @@ -294,7 +294,7 @@ fn layout_of_uncached<'tcx>( ty::Adt(def, substs) if def.repr().simd() => { if !def.is_struct() { // Should have yielded E0517 by now. - tcx.sess.delay_span_bug( + tcx.sess.delay_bug_unless_error( DUMMY_SP, "#[repr(simd)] was applied to an ADT that is not a struct", ); @@ -420,7 +420,7 @@ fn layout_of_uncached<'tcx>( if def.is_union() { if def.repr().pack.is_some() && def.repr().align.is_some() { - cx.tcx.sess.delay_span_bug( + cx.tcx.sess.delay_bug_unless_error( tcx.def_span(def.did()), "union cannot be packed and aligned", ); diff --git a/compiler/rustc_ty_utils/src/needs_drop.rs b/compiler/rustc_ty_utils/src/needs_drop.rs index c177d60bb5967..8715ea20ced68 100644 --- a/compiler/rustc_ty_utils/src/needs_drop.rs +++ b/compiler/rustc_ty_utils/src/needs_drop.rs @@ -130,7 +130,7 @@ where let interior_tys = match witness.kind() { &ty::GeneratorWitness(tys) => tcx.erase_late_bound_regions(tys), _ => { - tcx.sess.delay_span_bug( + tcx.sess.delay_bug_unless_error( tcx.hir().span_if_local(def_id).unwrap_or(DUMMY_SP), &format!("unexpected generator witness type {:?}", witness), );