From 2ea7a37e1113febac8603729e33fdd94f2738807 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Thu, 4 Jan 2024 12:54:23 +1100 Subject: [PATCH] Add `DiagCtxt::delayed_bug`. We have `span_delayed_bug` and often pass it a `DUMMY_SP`. This commit adds `delayed_bug`, which matches pairs like `err`/`span_err` and `warn`/`span_warn`. --- .../src/diagnostics/region_errors.rs | 4 +- .../src/const_eval/machine.rs | 8 ++-- compiler/rustc_errors/src/lib.rs | 18 +++++---- .../rustc_hir_analysis/src/check/check.rs | 5 +-- .../src/check/compare_impl_item.rs | 9 ++--- .../src/check/compare_impl_item/refine.rs | 17 ++------- .../src/check/intrinsicck.rs | 4 +- .../src/collect/resolve_bound_vars.rs | 11 ++---- .../src/infer/canonical/canonicalizer.rs | 8 ++-- compiler/rustc_infer/src/infer/mod.rs | 8 ++-- .../src/infer/opaque_types/table.rs | 5 +-- .../rustc_infer/src/infer/outlives/verify.rs | 7 ++-- .../rustc_infer/src/infer/relate/combine.rs | 7 ++-- .../src/mir/interpret/allocation.rs | 5 +-- compiler/rustc_middle/src/query/plumbing.rs | 2 +- compiler/rustc_middle/src/ty/layout.rs | 2 +- .../src/build/expr/as_constant.rs | 29 +++++++------- compiler/rustc_mir_build/src/thir/constant.rs | 38 +++++++++---------- compiler/rustc_passes/src/hir_id_validator.rs | 2 +- compiler/rustc_passes/src/liveness.rs | 3 +- .../rustc_query_system/src/query/plumbing.rs | 17 ++++----- compiler/rustc_session/src/session.rs | 5 +-- .../error_reporting/on_unimplemented.rs | 6 +-- .../error_reporting/type_err_ctxt_ext.rs | 2 +- .../src/traits/query/normalize.rs | 7 +--- .../src/traits/query/type_op/custom.rs | 9 ++--- compiler/rustc_ty_utils/src/layout.rs | 11 ++---- 27 files changed, 103 insertions(+), 146 deletions(-) diff --git a/compiler/rustc_borrowck/src/diagnostics/region_errors.rs b/compiler/rustc_borrowck/src/diagnostics/region_errors.rs index 020429c191449..8c8ca1ead400b 100644 --- a/compiler/rustc_borrowck/src/diagnostics/region_errors.rs +++ b/compiler/rustc_borrowck/src/diagnostics/region_errors.rs @@ -27,7 +27,7 @@ use rustc_middle::ty::TypeVisitor; use rustc_middle::ty::{self, RegionVid, Ty}; use rustc_middle::ty::{Region, TyCtxt}; use rustc_span::symbol::{kw, Ident}; -use rustc_span::{Span, DUMMY_SP}; +use rustc_span::Span; use crate::borrowck_errors; use crate::session_diagnostics::{ @@ -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.dcx().span_delayed_bug(DUMMY_SP, format!("{val:?}")); + self.1.sess.dcx().delayed_bug(format!("{val:?}")); self.0.push(val); } pub fn is_empty(&self) -> bool { diff --git a/compiler/rustc_const_eval/src/const_eval/machine.rs b/compiler/rustc_const_eval/src/const_eval/machine.rs index 19489f1e7ef5f..6947ace17c5e6 100644 --- a/compiler/rustc_const_eval/src/const_eval/machine.rs +++ b/compiler/rustc_const_eval/src/const_eval/machine.rs @@ -391,10 +391,10 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir, if ecx.tcx.is_ctfe_mir_available(def) { Ok(ecx.tcx.mir_for_ctfe(def)) } else if ecx.tcx.def_kind(def) == DefKind::AssocConst { - let guar = ecx.tcx.dcx().span_delayed_bug( - rustc_span::DUMMY_SP, - "This is likely a const item that is missing from its impl", - ); + let guar = ecx + .tcx + .dcx() + .delayed_bug("This is likely a const item that is missing from its impl"); throw_inval!(AlreadyReported(guar.into())); } else { // `find_mir_or_eval_fn` checks that this is a const fn before even calling us, diff --git a/compiler/rustc_errors/src/lib.rs b/compiler/rustc_errors/src/lib.rs index e3aa9477874c9..a80058c596b99 100644 --- a/compiler/rustc_errors/src/lib.rs +++ b/compiler/rustc_errors/src/lib.rs @@ -865,10 +865,16 @@ impl DiagCtxt { /// For example, it can be used to create an [`ErrorGuaranteed`] /// (but you should prefer threading through the [`ErrorGuaranteed`] from an error emission /// directly). - /// - /// If no span is available, use [`DUMMY_SP`]. - /// - /// [`DUMMY_SP`]: rustc_span::DUMMY_SP + #[track_caller] + pub fn delayed_bug(&self, msg: impl Into) -> ErrorGuaranteed { + let treat_next_err_as_bug = self.inner.borrow().treat_next_err_as_bug(); + if treat_next_err_as_bug { + self.bug(msg); + } + DiagnosticBuilder::::new(self, DelayedBug, msg).emit() + } + + /// Like `delayed_bug`, but takes an additional span. /// /// Note: this function used to be called `delay_span_bug`. It was renamed /// to match similar functions like `span_err`, `span_warn`, etc. @@ -882,9 +888,7 @@ impl DiagCtxt { if treat_next_err_as_bug { self.span_bug(sp, msg); } - let mut diagnostic = Diagnostic::new(DelayedBug, msg); - diagnostic.span(sp); - self.emit_diagnostic(diagnostic).unwrap() + DiagnosticBuilder::::new(self, DelayedBug, msg).span_mv(sp).emit() } // FIXME(eddyb) note the comment inside `impl Drop for DiagCtxtInner`, that's diff --git a/compiler/rustc_hir_analysis/src/check/check.rs b/compiler/rustc_hir_analysis/src/check/check.rs index feacfeb883f25..fee892d090cee 100644 --- a/compiler/rustc_hir_analysis/src/check/check.rs +++ b/compiler/rustc_hir_analysis/src/check/check.rs @@ -659,10 +659,7 @@ pub(super) fn check_specialization_validity<'tcx>( if !tcx.is_impl_trait_in_trait(impl_item) { report_forbidden_specialization(tcx, impl_item, parent_impl); } else { - tcx.dcx().span_delayed_bug( - DUMMY_SP, - format!("parent item: {parent_impl:?} not marked as default"), - ); + tcx.dcx().delayed_bug(format!("parent item: {parent_impl:?} not marked as default")); } } } 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 e3c465fdf5ca3..9e8a225166581 100644 --- a/compiler/rustc_hir_analysis/src/check/compare_impl_item.rs +++ b/compiler/rustc_hir_analysis/src/check/compare_impl_item.rs @@ -19,7 +19,7 @@ use rustc_middle::ty::{ self, GenericArgs, Ty, TypeFoldable, TypeFolder, TypeSuperFoldable, TypeVisitableExt, }; use rustc_middle::ty::{GenericParamDefKind, TyCtxt}; -use rustc_span::{Span, DUMMY_SP}; +use rustc_span::Span; use rustc_trait_selection::traits::error_reporting::TypeErrCtxtExt; use rustc_trait_selection::traits::outlives_bounds::InferCtxtExt as _; use rustc_trait_selection::traits::{ @@ -942,9 +942,7 @@ impl<'tcx> ty::FallibleTypeFolder> for RemapHiddenTyRegions<'tcx> { .note_mv(format!("hidden type inferred to be `{}`", self.ty)) .emit() } - _ => { - self.tcx.dcx().span_delayed_bug(DUMMY_SP, "should've been able to remap region") - } + _ => self.tcx.dcx().delayed_bug("should've been able to remap region"), }; return Err(guar); }; @@ -1303,8 +1301,7 @@ fn compare_number_of_generics<'tcx>( // inheriting the generics from will also have mismatched arguments, and // we'll report an error for that instead. Delay a bug for safety, though. if trait_.is_impl_trait_in_trait() { - return Err(tcx.dcx().span_delayed_bug( - rustc_span::DUMMY_SP, + return Err(tcx.dcx().delayed_bug( "errors comparing numbers of generics of trait/impl functions were not emitted", )); } diff --git a/compiler/rustc_hir_analysis/src/check/compare_impl_item/refine.rs b/compiler/rustc_hir_analysis/src/check/compare_impl_item/refine.rs index fd1571426c86a..f7fc0c81b953b 100644 --- a/compiler/rustc_hir_analysis/src/check/compare_impl_item/refine.rs +++ b/compiler/rustc_hir_analysis/src/check/compare_impl_item/refine.rs @@ -7,7 +7,7 @@ use rustc_middle::traits::{ObligationCause, Reveal}; use rustc_middle::ty::{ self, Ty, TyCtxt, TypeFoldable, TypeFolder, TypeSuperVisitable, TypeVisitable, TypeVisitor, }; -use rustc_span::{Span, DUMMY_SP}; +use rustc_span::Span; use rustc_trait_selection::traits::{ elaborate, normalize_param_env_or_error, outlives_bounds::InferCtxtExt, ObligationCtxt, }; @@ -153,10 +153,7 @@ pub(super) fn check_refining_return_position_impl_trait_in_trait<'tcx>( trait_m_sig.inputs_and_output, )); if !ocx.select_all_or_error().is_empty() { - tcx.dcx().span_delayed_bug( - DUMMY_SP, - "encountered errors when checking RPITIT refinement (selection)", - ); + tcx.dcx().delayed_bug("encountered errors when checking RPITIT refinement (selection)"); return; } let outlives_env = OutlivesEnvironment::with_bounds( @@ -165,18 +162,12 @@ pub(super) fn check_refining_return_position_impl_trait_in_trait<'tcx>( ); let errors = infcx.resolve_regions(&outlives_env); if !errors.is_empty() { - tcx.dcx().span_delayed_bug( - DUMMY_SP, - "encountered errors when checking RPITIT refinement (regions)", - ); + tcx.dcx().delayed_bug("encountered errors when checking RPITIT refinement (regions)"); return; } // Resolve any lifetime variables that may have been introduced during normalization. let Ok((trait_bounds, impl_bounds)) = infcx.fully_resolve((trait_bounds, impl_bounds)) else { - tcx.dcx().span_delayed_bug( - DUMMY_SP, - "encountered errors when checking RPITIT refinement (resolution)", - ); + tcx.dcx().delayed_bug("encountered errors when checking RPITIT refinement (resolution)"); return; }; diff --git a/compiler/rustc_hir_analysis/src/check/intrinsicck.rs b/compiler/rustc_hir_analysis/src/check/intrinsicck.rs index 0835ae76b9501..aadff6a97e330 100644 --- a/compiler/rustc_hir_analysis/src/check/intrinsicck.rs +++ b/compiler/rustc_hir_analysis/src/check/intrinsicck.rs @@ -4,7 +4,7 @@ use rustc_hir as hir; use rustc_middle::ty::{self, Article, FloatTy, IntTy, Ty, TyCtxt, TypeVisitableExt, UintTy}; use rustc_session::lint; use rustc_span::def_id::LocalDefId; -use rustc_span::{Symbol, DUMMY_SP}; +use rustc_span::Symbol; use rustc_target::abi::FieldIdx; use rustc_target::asm::{InlineAsmReg, InlineAsmRegClass, InlineAsmRegOrRegClass, InlineAsmType}; @@ -294,7 +294,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.dcx().span_delayed_bug(DUMMY_SP, "target architecture does not support asm"); + self.tcx.dcx().delayed_bug("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/collect/resolve_bound_vars.rs b/compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs index 37ae8fd327895..d41279e06158a 100644 --- a/compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs +++ b/compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs @@ -22,7 +22,7 @@ use rustc_middle::ty::{self, TyCtxt, TypeSuperVisitable, TypeVisitor}; use rustc_session::lint; use rustc_span::def_id::DefId; use rustc_span::symbol::{sym, Ident}; -use rustc_span::{Span, DUMMY_SP}; +use rustc_span::Span; use std::fmt; use crate::errors; @@ -335,13 +335,10 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> { // though this may happen when we call `poly_trait_ref_binder_info` with // an (erroneous, #113423) associated return type bound in an impl header. if !supertrait_bound_vars.is_empty() { - self.tcx.dcx().span_delayed_bug( - DUMMY_SP, - format!( - "found supertrait lifetimes without a binder to append \ + self.tcx.dcx().delayed_bug(format!( + "found supertrait lifetimes without a binder to append \ them to: {supertrait_bound_vars:?}" - ), - ); + )); } break (vec![], BinderScopeType::Normal); } diff --git a/compiler/rustc_infer/src/infer/canonical/canonicalizer.rs b/compiler/rustc_infer/src/infer/canonical/canonicalizer.rs index c156c13c96205..e4b37f05b778f 100644 --- a/compiler/rustc_infer/src/infer/canonical/canonicalizer.rs +++ b/compiler/rustc_infer/src/infer/canonical/canonicalizer.rs @@ -192,10 +192,10 @@ impl CanonicalizeMode for CanonicalizeQueryResponse { // rust-lang/rust#57464: `impl Trait` can leak local // scopes (in manner violating typeck). Therefore, use // `span_delayed_bug` to allow type error over an ICE. - canonicalizer.tcx.dcx().span_delayed_bug( - rustc_span::DUMMY_SP, - format!("unexpected region in query response: `{r:?}`"), - ); + canonicalizer + .tcx + .dcx() + .delayed_bug(format!("unexpected region in query response: `{r:?}`")); r } } diff --git a/compiler/rustc_infer/src/infer/mod.rs b/compiler/rustc_infer/src/infer/mod.rs index fa694f09f178d..fcc94687ed293 100644 --- a/compiler/rustc_infer/src/infer/mod.rs +++ b/compiler/rustc_infer/src/infer/mod.rs @@ -38,7 +38,7 @@ use rustc_middle::ty::{self, GenericParamDefKind, InferConst, InferTy, Ty, TyCtx use rustc_middle::ty::{ConstVid, EffectVid, FloatVid, IntVid, TyVid}; use rustc_middle::ty::{GenericArg, GenericArgKind, GenericArgs, GenericArgsRef}; use rustc_span::symbol::Symbol; -use rustc_span::{Span, DUMMY_SP}; +use rustc_span::Span; use std::cell::{Cell, RefCell}; use std::fmt; @@ -1434,10 +1434,8 @@ impl<'tcx> InferCtxt<'tcx> { bug!("`{value:?}` is not fully resolved"); } if value.has_infer_regions() { - let guar = self - .tcx - .dcx() - .span_delayed_bug(DUMMY_SP, format!("`{value:?}` is not fully resolved")); + let guar = + self.tcx.dcx().delayed_bug(format!("`{value:?}` is not fully resolved")); Ok(self.tcx.fold_regions(value, |re, _| { if re.is_var() { ty::Region::new_error(self.tcx, guar) } else { re } })) diff --git a/compiler/rustc_infer/src/infer/opaque_types/table.rs b/compiler/rustc_infer/src/infer/opaque_types/table.rs index c91eb7eddd846..6a684dba8dec5 100644 --- a/compiler/rustc_infer/src/infer/opaque_types/table.rs +++ b/compiler/rustc_infer/src/infer/opaque_types/table.rs @@ -1,6 +1,5 @@ use rustc_data_structures::undo_log::UndoLogs; use rustc_middle::ty::{self, OpaqueHiddenType, OpaqueTypeKey, Ty}; -use rustc_span::DUMMY_SP; use crate::infer::{InferCtxtUndoLogs, UndoLog}; @@ -40,9 +39,7 @@ impl<'tcx> OpaqueTypeStorage<'tcx> { impl<'tcx> Drop for OpaqueTypeStorage<'tcx> { fn drop(&mut self) { if !self.opaque_types.is_empty() { - ty::tls::with(|tcx| { - tcx.dcx().span_delayed_bug(DUMMY_SP, format!("{:?}", self.opaque_types)) - }); + ty::tls::with(|tcx| tcx.dcx().delayed_bug(format!("{:?}", self.opaque_types))); } } } diff --git a/compiler/rustc_infer/src/infer/outlives/verify.rs b/compiler/rustc_infer/src/infer/outlives/verify.rs index dd364312cade2..7a85268492b43 100644 --- a/compiler/rustc_infer/src/infer/outlives/verify.rs +++ b/compiler/rustc_infer/src/infer/outlives/verify.rs @@ -175,10 +175,9 @@ 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.dcx().span_delayed_bug( - rustc_span::DUMMY_SP, - format!("unresolved inference variable in outlives: {v:?}"), - ); + self.tcx + .dcx() + .delayed_bug(format!("unresolved inference variable in outlives: {v:?}")); // add a bound that never holds VerifyBound::AnyBound(vec![]) } diff --git a/compiler/rustc_infer/src/infer/relate/combine.rs b/compiler/rustc_infer/src/infer/relate/combine.rs index 8b31a1118cb75..6634b192811d6 100644 --- a/compiler/rustc_infer/src/infer/relate/combine.rs +++ b/compiler/rustc_infer/src/infer/relate/combine.rs @@ -180,10 +180,9 @@ impl<'tcx> InferCtxt<'tcx> { &mut OriginalQueryValues::default(), ); self.tcx.check_tys_might_be_eq(canonical).map_err(|_| { - self.tcx.dcx().span_delayed_bug( - DUMMY_SP, - format!("cannot relate consts of different types (a={a:?}, b={b:?})",), - ) + self.tcx.dcx().delayed_bug(format!( + "cannot relate consts of different types (a={a:?}, b={b:?})", + )) }) }); diff --git a/compiler/rustc_middle/src/mir/interpret/allocation.rs b/compiler/rustc_middle/src/mir/interpret/allocation.rs index a92b85a716f9e..4047891d7697b 100644 --- a/compiler/rustc_middle/src/mir/interpret/allocation.rs +++ b/compiler/rustc_middle/src/mir/interpret/allocation.rs @@ -14,7 +14,6 @@ use either::{Left, Right}; use rustc_ast::Mutability; use rustc_data_structures::intern::Interned; -use rustc_span::DUMMY_SP; use rustc_target::abi::{Align, HasDataLayout, Size}; use super::{ @@ -314,9 +313,7 @@ impl Allocation { /// available to the compiler to do so. pub fn try_uninit<'tcx>(size: Size, align: Align) -> InterpResult<'tcx, Self> { Self::uninit_inner(size, align, || { - ty::tls::with(|tcx| { - tcx.dcx().span_delayed_bug(DUMMY_SP, "exhausted memory during interpretation") - }); + ty::tls::with(|tcx| tcx.dcx().delayed_bug("exhausted memory during interpretation")); InterpError::ResourceExhaustion(ResourceExhaustionInfo::MemoryExhausted).into() }) } diff --git a/compiler/rustc_middle/src/query/plumbing.rs b/compiler/rustc_middle/src/query/plumbing.rs index 414d4c8d94961..a41d4f1ad5897 100644 --- a/compiler/rustc_middle/src/query/plumbing.rs +++ b/compiler/rustc_middle/src/query/plumbing.rs @@ -551,7 +551,7 @@ macro_rules! define_feedable { // We have an inconsistency. This can happen if one of the two // results is tainted by errors. In this case, delay a bug to // ensure compilation is doomed, and keep the `old` value. - tcx.dcx().span_delayed_bug(DUMMY_SP, format!( + tcx.dcx().delayed_bug(format!( "Trying to feed an already recorded value for query {} key={key:?}:\n\ old value: {old:?}\nnew value: {value:?}", stringify!($name), diff --git a/compiler/rustc_middle/src/ty/layout.rs b/compiler/rustc_middle/src/ty/layout.rs index 5cc0ce87c9bd7..25473f52c039e 100644 --- a/compiler/rustc_middle/src/ty/layout.rs +++ b/compiler/rustc_middle/src/ty/layout.rs @@ -284,7 +284,7 @@ impl<'tcx> LayoutCalculator for LayoutCx<'tcx, TyCtxt<'tcx>> { type TargetDataLayoutRef = &'tcx TargetDataLayout; fn delayed_bug(&self, txt: String) { - self.tcx.dcx().span_delayed_bug(DUMMY_SP, txt); + self.tcx.dcx().delayed_bug(txt); } fn current_data_layout(&self) -> Self::TargetDataLayoutRef { 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 e77e82d9954e8..5721957037e82 100644 --- a/compiler/rustc_mir_build/src/build/expr/as_constant.rs +++ b/compiler/rustc_mir_build/src/build/expr/as_constant.rs @@ -9,7 +9,6 @@ use rustc_middle::thir::*; use rustc_middle::ty::{ self, CanonicalUserType, CanonicalUserTypeAnnotation, TyCtxt, UserTypeAnnotationIndex, }; -use rustc_span::DUMMY_SP; use rustc_target::abi::Size; impl<'a, 'tcx> Builder<'a, 'tcx> { @@ -111,15 +110,15 @@ fn lit_to_mir_constant<'tcx>( let LitToConstInput { lit, ty, neg } = lit_input; let trunc = |n| { let param_ty = ty::ParamEnv::reveal_all().and(ty); - let width = tcx - .layout_of(param_ty) - .map_err(|_| { - LitToConstError::Reported(tcx.dcx().span_delayed_bug( - DUMMY_SP, - format!("couldn't compute width of literal: {:?}", lit_input.lit), - )) - })? - .size; + let width = + tcx.layout_of(param_ty) + .map_err(|_| { + LitToConstError::Reported(tcx.dcx().delayed_bug(format!( + "couldn't compute width of literal: {:?}", + lit_input.lit + ))) + })? + .size; trace!("trunc {} with size {} and shift {}", n, width.bits(), 128 - width.bits()); let result = width.truncate(n); trace!("trunc result: {}", result); @@ -158,16 +157,16 @@ 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.dcx().span_delayed_bug( - DUMMY_SP, - format!("couldn't parse float literal: {:?}", lit_input.lit), - )) + LitToConstError::Reported( + tcx.dcx() + .delayed_bug(format!("couldn't parse float literal: {:?}", lit_input.lit)), + ) })?, (ast::LitKind::Bool(b), ty::Bool) => ConstValue::Scalar(Scalar::from_bool(*b)), (ast::LitKind::Char(c), ty::Char) => ConstValue::Scalar(Scalar::from_char(*c)), (ast::LitKind::Err, _) => { return Err(LitToConstError::Reported( - tcx.dcx().span_delayed_bug(DUMMY_SP, "encountered LitKind::Err during mir build"), + tcx.dcx().delayed_bug("encountered LitKind::Err during mir build"), )); } _ => return Err(LitToConstError::TypeError), diff --git a/compiler/rustc_mir_build/src/thir/constant.rs b/compiler/rustc_mir_build/src/thir/constant.rs index 3a56b03948ec9..8d5e6cd4f4100 100644 --- a/compiler/rustc_mir_build/src/thir/constant.rs +++ b/compiler/rustc_mir_build/src/thir/constant.rs @@ -1,7 +1,6 @@ use rustc_ast as ast; use rustc_middle::mir::interpret::{LitToConstError, LitToConstInput}; use rustc_middle::ty::{self, ParamEnv, ScalarInt, TyCtxt}; -use rustc_span::DUMMY_SP; use crate::build::parse_float_into_scalar; @@ -13,15 +12,15 @@ pub(crate) fn lit_to_const<'tcx>( let trunc = |n| { let param_ty = ParamEnv::reveal_all().and(ty); - let width = tcx - .layout_of(param_ty) - .map_err(|_| { - LitToConstError::Reported(tcx.dcx().span_delayed_bug( - DUMMY_SP, - format!("couldn't compute width of literal: {:?}", lit_input.lit), - )) - })? - .size; + let width = + tcx.layout_of(param_ty) + .map_err(|_| { + LitToConstError::Reported(tcx.dcx().delayed_bug(format!( + "couldn't compute width of literal: {:?}", + lit_input.lit + ))) + })? + .size; trace!("trunc {} with size {} and shift {}", n, width.bits(), 128 - width.bits()); let result = width.truncate(n); trace!("trunc result: {}", result); @@ -60,20 +59,21 @@ pub(crate) fn lit_to_const<'tcx>( } (ast::LitKind::Bool(b), ty::Bool) => ty::ValTree::from_scalar_int((*b).into()), (ast::LitKind::Float(n, _), ty::Float(fty)) => { - let bits = parse_float_into_scalar(*n, *fty, neg) - .ok_or_else(|| { - LitToConstError::Reported(tcx.dcx().span_delayed_bug( - DUMMY_SP, - format!("couldn't parse float literal: {:?}", lit_input.lit), - )) - })? - .assert_int(); + let bits = + parse_float_into_scalar(*n, *fty, neg) + .ok_or_else(|| { + LitToConstError::Reported(tcx.dcx().delayed_bug(format!( + "couldn't parse float literal: {:?}", + lit_input.lit + ))) + })? + .assert_int(); ty::ValTree::from_scalar_int(bits) } (ast::LitKind::Char(c), ty::Char) => ty::ValTree::from_scalar_int((*c).into()), (ast::LitKind::Err, _) => { return Err(LitToConstError::Reported( - tcx.dcx().span_delayed_bug(DUMMY_SP, "encountered LitKind::Err during mir build"), + tcx.dcx().delayed_bug("encountered LitKind::Err during mir build"), )); } _ => return Err(LitToConstError::TypeError), diff --git a/compiler/rustc_passes/src/hir_id_validator.rs b/compiler/rustc_passes/src/hir_id_validator.rs index 0727bad7c5a1d..02f56ecb10b57 100644 --- a/compiler/rustc_passes/src/hir_id_validator.rs +++ b/compiler/rustc_passes/src/hir_id_validator.rs @@ -31,7 +31,7 @@ pub fn check_crate(tcx: TyCtxt<'_>) { if !errors.is_empty() { let message = errors.iter().fold(String::new(), |s1, s2| s1 + "\n" + s2); - tcx.dcx().span_delayed_bug(rustc_span::DUMMY_SP, message); + tcx.dcx().delayed_bug(message); } } } diff --git a/compiler/rustc_passes/src/liveness.rs b/compiler/rustc_passes/src/liveness.rs index aba08e8b5ca14..92687c705aee6 100644 --- a/compiler/rustc_passes/src/liveness.rs +++ b/compiler/rustc_passes/src/liveness.rs @@ -98,7 +98,6 @@ use rustc_middle::query::Providers; use rustc_middle::ty::{self, RootVariableMinCaptureList, Ty, TyCtxt}; use rustc_session::lint; use rustc_span::symbol::{kw, sym, Symbol}; -use rustc_span::DUMMY_SP; use rustc_span::{BytePos, Span}; use std::io; @@ -560,7 +559,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> { match self.successors[ln] { Some(successor) => self.assigned_on_entry(successor, var), None => { - self.ir.tcx.dcx().span_delayed_bug(DUMMY_SP, "no successor"); + self.ir.tcx.dcx().delayed_bug("no successor"); true } } diff --git a/compiler/rustc_query_system/src/query/plumbing.rs b/compiler/rustc_query_system/src/query/plumbing.rs index c5a0cc753a8f1..3bb2cc5634fe8 100644 --- a/compiler/rustc_query_system/src/query/plumbing.rs +++ b/compiler/rustc_query_system/src/query/plumbing.rs @@ -431,17 +431,14 @@ where // We have an inconsistency. This can happen if one of the two // results is tainted by errors. In this case, delay a bug to // ensure compilation is doomed. - qcx.dep_context().sess().dcx().span_delayed_bug( - DUMMY_SP, - format!( - "Computed query value for {:?}({:?}) is inconsistent with fed value,\n\ + qcx.dep_context().sess().dcx().delayed_bug(format!( + "Computed query value for {:?}({:?}) is inconsistent with fed value,\n\ computed={:#?}\nfed={:#?}", - query.dep_kind(), - key, - formatter(&result), - formatter(&cached_result), - ), - ); + query.dep_kind(), + key, + formatter(&result), + formatter(&cached_result), + )); } } } diff --git a/compiler/rustc_session/src/session.rs b/compiler/rustc_session/src/session.rs index ee635de6da4ec..eef14971ea094 100644 --- a/compiler/rustc_session/src/session.rs +++ b/compiler/rustc_session/src/session.rs @@ -341,10 +341,7 @@ impl Session { if self.dcx().err_count() == old_count { Ok(result) } else { - Err(self.dcx().span_delayed_bug( - rustc_span::DUMMY_SP, - "`self.err_count()` changed but an error was not emitted", - )) + Err(self.dcx().delayed_bug("`self.err_count()` changed but an error was not emitted")) } } 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 ad65d106f5ad0..100c9a70aaa2d 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 @@ -14,7 +14,7 @@ use rustc_middle::ty::{self, GenericParamDefKind, TyCtxt}; use rustc_parse_format::{ParseMode, Parser, Piece, Position}; use rustc_session::lint::builtin::UNKNOWN_OR_MALFORMED_DIAGNOSTIC_ATTRIBUTES; use rustc_span::symbol::{kw, sym, Symbol}; -use rustc_span::{Span, DUMMY_SP}; +use rustc_span::Span; use std::iter; use crate::errors::{ @@ -657,9 +657,7 @@ impl<'tcx> OnUnimplementedDirective { Ok(None) } else { - let reported = tcx - .dcx() - .span_delayed_bug(DUMMY_SP, "of_item: neither meta_item_list nor value_str"); + let reported = tcx.dcx().delayed_bug("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/error_reporting/type_err_ctxt_ext.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/type_err_ctxt_ext.rs index 3c54be6b3aeef..cd730ad1a0a17 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/type_err_ctxt_ext.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/type_err_ctxt_ext.rs @@ -228,7 +228,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> { } } - self.dcx().span_delayed_bug(DUMMY_SP, "expected fulfillment errors") + self.dcx().delayed_bug("expected fulfillment errors") } /// Reports that an overflow has occurred and halts compilation. We diff --git a/compiler/rustc_trait_selection/src/traits/query/normalize.rs b/compiler/rustc_trait_selection/src/traits/query/normalize.rs index d5f98db2c9307..2d0e8d9da3f8b 100644 --- a/compiler/rustc_trait_selection/src/traits/query/normalize.rs +++ b/compiler/rustc_trait_selection/src/traits/query/normalize.rs @@ -14,7 +14,6 @@ use rustc_infer::traits::Normalized; use rustc_middle::ty::fold::{FallibleTypeFolder, TypeFoldable, TypeSuperFoldable}; use rustc_middle::ty::visit::{TypeSuperVisitable, TypeVisitable, TypeVisitableExt}; use rustc_middle::ty::{self, Ty, TyCtxt, TypeVisitor}; -use rustc_span::DUMMY_SP; use std::ops::ControlFlow; @@ -286,10 +285,8 @@ 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.dcx().span_delayed_bug( - DUMMY_SP, - format!("unexpected ambiguity: {c_data:?} {result:?}"), - ); + tcx.dcx() + .delayed_bug(format!("unexpected ambiguity: {c_data:?} {result:?}")); } return Err(NoSolution); } 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 f4baae2711fb0..d533e69a4fa7f 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 @@ -6,7 +6,7 @@ use rustc_errors::ErrorGuaranteed; use rustc_infer::infer::region_constraints::RegionConstraintData; use rustc_middle::traits::query::NoSolution; use rustc_middle::ty::{TyCtxt, TypeFoldable}; -use rustc_span::{Span, DUMMY_SP}; +use rustc_span::Span; use std::fmt; @@ -88,10 +88,9 @@ where if errors.is_empty() { Ok(value) } else { - Err(infcx.dcx().span_delayed_bug( - DUMMY_SP, - format!("errors selecting obligation during MIR typeck: {errors:?}"), - )) + Err(infcx + .dcx() + .delayed_bug(format!("errors selecting obligation during MIR typeck: {errors:?}"))) } })?; diff --git a/compiler/rustc_ty_utils/src/layout.rs b/compiler/rustc_ty_utils/src/layout.rs index db89fba2a893e..b8351463c55c7 100644 --- a/compiler/rustc_ty_utils/src/layout.rs +++ b/compiler/rustc_ty_utils/src/layout.rs @@ -11,7 +11,6 @@ use rustc_middle::ty::print::with_no_trimmed_paths; use rustc_middle::ty::{self, AdtDef, EarlyBinder, GenericArgsRef, Ty, TyCtxt, TypeVisitableExt}; use rustc_session::{DataTypeKind, FieldInfo, FieldKind, SizeKind, VariantInfo}; use rustc_span::symbol::Symbol; -use rustc_span::DUMMY_SP; use rustc_target::abi::*; use std::fmt::Debug; @@ -91,7 +90,7 @@ fn univariant_uninterned<'tcx>( let dl = cx.data_layout(); let pack = repr.pack; if pack.is_some() && repr.align.is_some() { - cx.tcx.dcx().span_delayed_bug(DUMMY_SP, "struct cannot be packed and aligned"); + cx.tcx.dcx().delayed_bug("struct cannot be packed and aligned"); return Err(cx.tcx.arena.alloc(LayoutError::Unknown(ty))); } @@ -344,10 +343,7 @@ fn layout_of_uncached<'tcx>( ty::Adt(def, args) if def.repr().simd() => { if !def.is_struct() { // Should have yielded E0517 by now. - tcx.dcx().span_delayed_bug( - DUMMY_SP, - "#[repr(simd)] was applied to an ADT that is not a struct", - ); + tcx.dcx().delayed_bug("#[repr(simd)] was applied to an ADT that is not a struct"); return Err(error(cx, LayoutError::Unknown(ty))); } @@ -374,8 +370,7 @@ fn layout_of_uncached<'tcx>( // (should be caught by typeck) for fi in fields { if fi.ty(tcx, args) != f0_ty { - tcx.dcx().span_delayed_bug( - DUMMY_SP, + tcx.dcx().delayed_bug( "#[repr(simd)] was applied to an ADT with heterogeneous field type", ); return Err(error(cx, LayoutError::Unknown(ty)));