1
Fork 0

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`.
This commit is contained in:
Nicholas Nethercote 2024-01-04 12:54:23 +11:00
parent 3c4f1d85af
commit 2ea7a37e11
27 changed files with 103 additions and 146 deletions

View file

@ -27,7 +27,7 @@ use rustc_middle::ty::TypeVisitor;
use rustc_middle::ty::{self, RegionVid, Ty}; use rustc_middle::ty::{self, RegionVid, Ty};
use rustc_middle::ty::{Region, TyCtxt}; use rustc_middle::ty::{Region, TyCtxt};
use rustc_span::symbol::{kw, Ident}; use rustc_span::symbol::{kw, Ident};
use rustc_span::{Span, DUMMY_SP}; use rustc_span::Span;
use crate::borrowck_errors; use crate::borrowck_errors;
use crate::session_diagnostics::{ use crate::session_diagnostics::{
@ -84,7 +84,7 @@ impl<'tcx> RegionErrors<'tcx> {
#[track_caller] #[track_caller]
pub fn push(&mut self, val: impl Into<RegionErrorKind<'tcx>>) { pub fn push(&mut self, val: impl Into<RegionErrorKind<'tcx>>) {
let val = val.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); self.0.push(val);
} }
pub fn is_empty(&self) -> bool { pub fn is_empty(&self) -> bool {

View file

@ -391,10 +391,10 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir,
if ecx.tcx.is_ctfe_mir_available(def) { if ecx.tcx.is_ctfe_mir_available(def) {
Ok(ecx.tcx.mir_for_ctfe(def)) Ok(ecx.tcx.mir_for_ctfe(def))
} else if ecx.tcx.def_kind(def) == DefKind::AssocConst { } else if ecx.tcx.def_kind(def) == DefKind::AssocConst {
let guar = ecx.tcx.dcx().span_delayed_bug( let guar = ecx
rustc_span::DUMMY_SP, .tcx
"This is likely a const item that is missing from its impl", .dcx()
); .delayed_bug("This is likely a const item that is missing from its impl");
throw_inval!(AlreadyReported(guar.into())); throw_inval!(AlreadyReported(guar.into()));
} else { } else {
// `find_mir_or_eval_fn` checks that this is a const fn before even calling us, // `find_mir_or_eval_fn` checks that this is a const fn before even calling us,

View file

@ -865,10 +865,16 @@ impl DiagCtxt {
/// For example, it can be used to create an [`ErrorGuaranteed`] /// For example, it can be used to create an [`ErrorGuaranteed`]
/// (but you should prefer threading through the [`ErrorGuaranteed`] from an error emission /// (but you should prefer threading through the [`ErrorGuaranteed`] from an error emission
/// directly). /// directly).
/// #[track_caller]
/// If no span is available, use [`DUMMY_SP`]. pub fn delayed_bug(&self, msg: impl Into<DiagnosticMessage>) -> ErrorGuaranteed {
/// let treat_next_err_as_bug = self.inner.borrow().treat_next_err_as_bug();
/// [`DUMMY_SP`]: rustc_span::DUMMY_SP if treat_next_err_as_bug {
self.bug(msg);
}
DiagnosticBuilder::<ErrorGuaranteed>::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 /// Note: this function used to be called `delay_span_bug`. It was renamed
/// to match similar functions like `span_err`, `span_warn`, etc. /// to match similar functions like `span_err`, `span_warn`, etc.
@ -882,9 +888,7 @@ impl DiagCtxt {
if treat_next_err_as_bug { if treat_next_err_as_bug {
self.span_bug(sp, msg); self.span_bug(sp, msg);
} }
let mut diagnostic = Diagnostic::new(DelayedBug, msg); DiagnosticBuilder::<ErrorGuaranteed>::new(self, DelayedBug, msg).span_mv(sp).emit()
diagnostic.span(sp);
self.emit_diagnostic(diagnostic).unwrap()
} }
// FIXME(eddyb) note the comment inside `impl Drop for DiagCtxtInner`, that's // FIXME(eddyb) note the comment inside `impl Drop for DiagCtxtInner`, that's

View file

@ -659,10 +659,7 @@ pub(super) fn check_specialization_validity<'tcx>(
if !tcx.is_impl_trait_in_trait(impl_item) { if !tcx.is_impl_trait_in_trait(impl_item) {
report_forbidden_specialization(tcx, impl_item, parent_impl); report_forbidden_specialization(tcx, impl_item, parent_impl);
} else { } else {
tcx.dcx().span_delayed_bug( tcx.dcx().delayed_bug(format!("parent item: {parent_impl:?} not marked as default"));
DUMMY_SP,
format!("parent item: {parent_impl:?} not marked as default"),
);
} }
} }
} }

View file

@ -19,7 +19,7 @@ use rustc_middle::ty::{
self, GenericArgs, Ty, TypeFoldable, TypeFolder, TypeSuperFoldable, TypeVisitableExt, self, GenericArgs, Ty, TypeFoldable, TypeFolder, TypeSuperFoldable, TypeVisitableExt,
}; };
use rustc_middle::ty::{GenericParamDefKind, TyCtxt}; 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::error_reporting::TypeErrCtxtExt;
use rustc_trait_selection::traits::outlives_bounds::InferCtxtExt as _; use rustc_trait_selection::traits::outlives_bounds::InferCtxtExt as _;
use rustc_trait_selection::traits::{ use rustc_trait_selection::traits::{
@ -942,9 +942,7 @@ impl<'tcx> ty::FallibleTypeFolder<TyCtxt<'tcx>> for RemapHiddenTyRegions<'tcx> {
.note_mv(format!("hidden type inferred to be `{}`", self.ty)) .note_mv(format!("hidden type inferred to be `{}`", self.ty))
.emit() .emit()
} }
_ => { _ => self.tcx.dcx().delayed_bug("should've been able to remap region"),
self.tcx.dcx().span_delayed_bug(DUMMY_SP, "should've been able to remap region")
}
}; };
return Err(guar); return Err(guar);
}; };
@ -1303,8 +1301,7 @@ fn compare_number_of_generics<'tcx>(
// inheriting the generics from will also have mismatched arguments, and // inheriting the generics from will also have mismatched arguments, and
// we'll report an error for that instead. Delay a bug for safety, though. // we'll report an error for that instead. Delay a bug for safety, though.
if trait_.is_impl_trait_in_trait() { if trait_.is_impl_trait_in_trait() {
return Err(tcx.dcx().span_delayed_bug( return Err(tcx.dcx().delayed_bug(
rustc_span::DUMMY_SP,
"errors comparing numbers of generics of trait/impl functions were not emitted", "errors comparing numbers of generics of trait/impl functions were not emitted",
)); ));
} }

View file

@ -7,7 +7,7 @@ use rustc_middle::traits::{ObligationCause, Reveal};
use rustc_middle::ty::{ use rustc_middle::ty::{
self, Ty, TyCtxt, TypeFoldable, TypeFolder, TypeSuperVisitable, TypeVisitable, TypeVisitor, self, Ty, TyCtxt, TypeFoldable, TypeFolder, TypeSuperVisitable, TypeVisitable, TypeVisitor,
}; };
use rustc_span::{Span, DUMMY_SP}; use rustc_span::Span;
use rustc_trait_selection::traits::{ use rustc_trait_selection::traits::{
elaborate, normalize_param_env_or_error, outlives_bounds::InferCtxtExt, ObligationCtxt, 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, trait_m_sig.inputs_and_output,
)); ));
if !ocx.select_all_or_error().is_empty() { if !ocx.select_all_or_error().is_empty() {
tcx.dcx().span_delayed_bug( tcx.dcx().delayed_bug("encountered errors when checking RPITIT refinement (selection)");
DUMMY_SP,
"encountered errors when checking RPITIT refinement (selection)",
);
return; return;
} }
let outlives_env = OutlivesEnvironment::with_bounds( 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); let errors = infcx.resolve_regions(&outlives_env);
if !errors.is_empty() { if !errors.is_empty() {
tcx.dcx().span_delayed_bug( tcx.dcx().delayed_bug("encountered errors when checking RPITIT refinement (regions)");
DUMMY_SP,
"encountered errors when checking RPITIT refinement (regions)",
);
return; return;
} }
// Resolve any lifetime variables that may have been introduced during normalization. // 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 { let Ok((trait_bounds, impl_bounds)) = infcx.fully_resolve((trait_bounds, impl_bounds)) else {
tcx.dcx().span_delayed_bug( tcx.dcx().delayed_bug("encountered errors when checking RPITIT refinement (resolution)");
DUMMY_SP,
"encountered errors when checking RPITIT refinement (resolution)",
);
return; return;
}; };

View file

@ -4,7 +4,7 @@ use rustc_hir as hir;
use rustc_middle::ty::{self, Article, FloatTy, IntTy, Ty, TyCtxt, TypeVisitableExt, UintTy}; use rustc_middle::ty::{self, Article, FloatTy, IntTy, Ty, TyCtxt, TypeVisitableExt, UintTy};
use rustc_session::lint; use rustc_session::lint;
use rustc_span::def_id::LocalDefId; use rustc_span::def_id::LocalDefId;
use rustc_span::{Symbol, DUMMY_SP}; use rustc_span::Symbol;
use rustc_target::abi::FieldIdx; use rustc_target::abi::FieldIdx;
use rustc_target::asm::{InlineAsmReg, InlineAsmRegClass, InlineAsmRegOrRegClass, InlineAsmType}; 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) { 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 target_features = self.tcx.asm_target_features(enclosing_id.to_def_id());
let Some(asm_arch) = self.tcx.sess.asm_arch else { 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; return;
}; };
for (idx, (op, op_sp)) in asm.operands.iter().enumerate() { for (idx, (op, op_sp)) in asm.operands.iter().enumerate() {

View file

@ -22,7 +22,7 @@ use rustc_middle::ty::{self, TyCtxt, TypeSuperVisitable, TypeVisitor};
use rustc_session::lint; use rustc_session::lint;
use rustc_span::def_id::DefId; use rustc_span::def_id::DefId;
use rustc_span::symbol::{sym, Ident}; use rustc_span::symbol::{sym, Ident};
use rustc_span::{Span, DUMMY_SP}; use rustc_span::Span;
use std::fmt; use std::fmt;
use crate::errors; 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 // though this may happen when we call `poly_trait_ref_binder_info` with
// an (erroneous, #113423) associated return type bound in an impl header. // an (erroneous, #113423) associated return type bound in an impl header.
if !supertrait_bound_vars.is_empty() { if !supertrait_bound_vars.is_empty() {
self.tcx.dcx().span_delayed_bug( self.tcx.dcx().delayed_bug(format!(
DUMMY_SP, "found supertrait lifetimes without a binder to append \
format!(
"found supertrait lifetimes without a binder to append \
them to: {supertrait_bound_vars:?}" them to: {supertrait_bound_vars:?}"
), ));
);
} }
break (vec![], BinderScopeType::Normal); break (vec![], BinderScopeType::Normal);
} }

View file

@ -192,10 +192,10 @@ impl CanonicalizeMode for CanonicalizeQueryResponse {
// rust-lang/rust#57464: `impl Trait` can leak local // rust-lang/rust#57464: `impl Trait` can leak local
// scopes (in manner violating typeck). Therefore, use // scopes (in manner violating typeck). Therefore, use
// `span_delayed_bug` to allow type error over an ICE. // `span_delayed_bug` to allow type error over an ICE.
canonicalizer.tcx.dcx().span_delayed_bug( canonicalizer
rustc_span::DUMMY_SP, .tcx
format!("unexpected region in query response: `{r:?}`"), .dcx()
); .delayed_bug(format!("unexpected region in query response: `{r:?}`"));
r r
} }
} }

View file

@ -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::{ConstVid, EffectVid, FloatVid, IntVid, TyVid};
use rustc_middle::ty::{GenericArg, GenericArgKind, GenericArgs, GenericArgsRef}; use rustc_middle::ty::{GenericArg, GenericArgKind, GenericArgs, GenericArgsRef};
use rustc_span::symbol::Symbol; use rustc_span::symbol::Symbol;
use rustc_span::{Span, DUMMY_SP}; use rustc_span::Span;
use std::cell::{Cell, RefCell}; use std::cell::{Cell, RefCell};
use std::fmt; use std::fmt;
@ -1434,10 +1434,8 @@ impl<'tcx> InferCtxt<'tcx> {
bug!("`{value:?}` is not fully resolved"); bug!("`{value:?}` is not fully resolved");
} }
if value.has_infer_regions() { if value.has_infer_regions() {
let guar = self let guar =
.tcx self.tcx.dcx().delayed_bug(format!("`{value:?}` is not fully resolved"));
.dcx()
.span_delayed_bug(DUMMY_SP, format!("`{value:?}` is not fully resolved"));
Ok(self.tcx.fold_regions(value, |re, _| { Ok(self.tcx.fold_regions(value, |re, _| {
if re.is_var() { ty::Region::new_error(self.tcx, guar) } else { re } if re.is_var() { ty::Region::new_error(self.tcx, guar) } else { re }
})) }))

View file

@ -1,6 +1,5 @@
use rustc_data_structures::undo_log::UndoLogs; use rustc_data_structures::undo_log::UndoLogs;
use rustc_middle::ty::{self, OpaqueHiddenType, OpaqueTypeKey, Ty}; use rustc_middle::ty::{self, OpaqueHiddenType, OpaqueTypeKey, Ty};
use rustc_span::DUMMY_SP;
use crate::infer::{InferCtxtUndoLogs, UndoLog}; use crate::infer::{InferCtxtUndoLogs, UndoLog};
@ -40,9 +39,7 @@ impl<'tcx> OpaqueTypeStorage<'tcx> {
impl<'tcx> Drop for OpaqueTypeStorage<'tcx> { impl<'tcx> Drop for OpaqueTypeStorage<'tcx> {
fn drop(&mut self) { fn drop(&mut self) {
if !self.opaque_types.is_empty() { if !self.opaque_types.is_empty() {
ty::tls::with(|tcx| { ty::tls::with(|tcx| tcx.dcx().delayed_bug(format!("{:?}", self.opaque_types)));
tcx.dcx().span_delayed_bug(DUMMY_SP, format!("{:?}", self.opaque_types))
});
} }
} }
} }

View file

@ -175,10 +175,9 @@ impl<'cx, 'tcx> VerifyBoundCx<'cx, 'tcx> {
// ignore this, we presume it will yield an error // ignore this, we presume it will yield an error
// later, since if a type variable is not resolved by // later, since if a type variable is not resolved by
// this point it never will be // this point it never will be
self.tcx.dcx().span_delayed_bug( self.tcx
rustc_span::DUMMY_SP, .dcx()
format!("unresolved inference variable in outlives: {v:?}"), .delayed_bug(format!("unresolved inference variable in outlives: {v:?}"));
);
// add a bound that never holds // add a bound that never holds
VerifyBound::AnyBound(vec![]) VerifyBound::AnyBound(vec![])
} }

View file

@ -180,10 +180,9 @@ impl<'tcx> InferCtxt<'tcx> {
&mut OriginalQueryValues::default(), &mut OriginalQueryValues::default(),
); );
self.tcx.check_tys_might_be_eq(canonical).map_err(|_| { self.tcx.check_tys_might_be_eq(canonical).map_err(|_| {
self.tcx.dcx().span_delayed_bug( self.tcx.dcx().delayed_bug(format!(
DUMMY_SP, "cannot relate consts of different types (a={a:?}, b={b:?})",
format!("cannot relate consts of different types (a={a:?}, b={b:?})",), ))
)
}) })
}); });

View file

@ -14,7 +14,6 @@ use either::{Left, Right};
use rustc_ast::Mutability; use rustc_ast::Mutability;
use rustc_data_structures::intern::Interned; use rustc_data_structures::intern::Interned;
use rustc_span::DUMMY_SP;
use rustc_target::abi::{Align, HasDataLayout, Size}; use rustc_target::abi::{Align, HasDataLayout, Size};
use super::{ use super::{
@ -314,9 +313,7 @@ impl<Prov: Provenance, Bytes: AllocBytes> Allocation<Prov, (), Bytes> {
/// available to the compiler to do so. /// available to the compiler to do so.
pub fn try_uninit<'tcx>(size: Size, align: Align) -> InterpResult<'tcx, Self> { pub fn try_uninit<'tcx>(size: Size, align: Align) -> InterpResult<'tcx, Self> {
Self::uninit_inner(size, align, || { Self::uninit_inner(size, align, || {
ty::tls::with(|tcx| { ty::tls::with(|tcx| tcx.dcx().delayed_bug("exhausted memory during interpretation"));
tcx.dcx().span_delayed_bug(DUMMY_SP, "exhausted memory during interpretation")
});
InterpError::ResourceExhaustion(ResourceExhaustionInfo::MemoryExhausted).into() InterpError::ResourceExhaustion(ResourceExhaustionInfo::MemoryExhausted).into()
}) })
} }

View file

@ -551,7 +551,7 @@ macro_rules! define_feedable {
// We have an inconsistency. This can happen if one of the two // We have an inconsistency. This can happen if one of the two
// results is tainted by errors. In this case, delay a bug to // results is tainted by errors. In this case, delay a bug to
// ensure compilation is doomed, and keep the `old` value. // 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\ "Trying to feed an already recorded value for query {} key={key:?}:\n\
old value: {old:?}\nnew value: {value:?}", old value: {old:?}\nnew value: {value:?}",
stringify!($name), stringify!($name),

View file

@ -284,7 +284,7 @@ impl<'tcx> LayoutCalculator for LayoutCx<'tcx, TyCtxt<'tcx>> {
type TargetDataLayoutRef = &'tcx TargetDataLayout; type TargetDataLayoutRef = &'tcx TargetDataLayout;
fn delayed_bug(&self, txt: String) { 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 { fn current_data_layout(&self) -> Self::TargetDataLayoutRef {

View file

@ -9,7 +9,6 @@ use rustc_middle::thir::*;
use rustc_middle::ty::{ use rustc_middle::ty::{
self, CanonicalUserType, CanonicalUserTypeAnnotation, TyCtxt, UserTypeAnnotationIndex, self, CanonicalUserType, CanonicalUserTypeAnnotation, TyCtxt, UserTypeAnnotationIndex,
}; };
use rustc_span::DUMMY_SP;
use rustc_target::abi::Size; use rustc_target::abi::Size;
impl<'a, 'tcx> Builder<'a, 'tcx> { impl<'a, 'tcx> Builder<'a, 'tcx> {
@ -111,15 +110,15 @@ fn lit_to_mir_constant<'tcx>(
let LitToConstInput { lit, ty, neg } = lit_input; let LitToConstInput { lit, ty, neg } = lit_input;
let trunc = |n| { let trunc = |n| {
let param_ty = ty::ParamEnv::reveal_all().and(ty); let param_ty = ty::ParamEnv::reveal_all().and(ty);
let width = tcx let width =
.layout_of(param_ty) tcx.layout_of(param_ty)
.map_err(|_| { .map_err(|_| {
LitToConstError::Reported(tcx.dcx().span_delayed_bug( LitToConstError::Reported(tcx.dcx().delayed_bug(format!(
DUMMY_SP, "couldn't compute width of literal: {:?}",
format!("couldn't compute width of literal: {:?}", lit_input.lit), lit_input.lit
)) )))
})? })?
.size; .size;
trace!("trunc {} with size {} and shift {}", n, width.bits(), 128 - width.bits()); trace!("trunc {} with size {} and shift {}", n, width.bits(), 128 - width.bits());
let result = width.truncate(n); let result = width.truncate(n);
trace!("trunc result: {}", result); 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) (ast::LitKind::Float(n, _), ty::Float(fty)) => parse_float_into_constval(*n, *fty, neg)
.ok_or_else(|| { .ok_or_else(|| {
LitToConstError::Reported(tcx.dcx().span_delayed_bug( LitToConstError::Reported(
DUMMY_SP, tcx.dcx()
format!("couldn't parse float literal: {:?}", lit_input.lit), .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::Bool(b), ty::Bool) => ConstValue::Scalar(Scalar::from_bool(*b)),
(ast::LitKind::Char(c), ty::Char) => ConstValue::Scalar(Scalar::from_char(*c)), (ast::LitKind::Char(c), ty::Char) => ConstValue::Scalar(Scalar::from_char(*c)),
(ast::LitKind::Err, _) => { (ast::LitKind::Err, _) => {
return Err(LitToConstError::Reported( 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), _ => return Err(LitToConstError::TypeError),

View file

@ -1,7 +1,6 @@
use rustc_ast as ast; use rustc_ast as ast;
use rustc_middle::mir::interpret::{LitToConstError, LitToConstInput}; use rustc_middle::mir::interpret::{LitToConstError, LitToConstInput};
use rustc_middle::ty::{self, ParamEnv, ScalarInt, TyCtxt}; use rustc_middle::ty::{self, ParamEnv, ScalarInt, TyCtxt};
use rustc_span::DUMMY_SP;
use crate::build::parse_float_into_scalar; use crate::build::parse_float_into_scalar;
@ -13,15 +12,15 @@ pub(crate) fn lit_to_const<'tcx>(
let trunc = |n| { let trunc = |n| {
let param_ty = ParamEnv::reveal_all().and(ty); let param_ty = ParamEnv::reveal_all().and(ty);
let width = tcx let width =
.layout_of(param_ty) tcx.layout_of(param_ty)
.map_err(|_| { .map_err(|_| {
LitToConstError::Reported(tcx.dcx().span_delayed_bug( LitToConstError::Reported(tcx.dcx().delayed_bug(format!(
DUMMY_SP, "couldn't compute width of literal: {:?}",
format!("couldn't compute width of literal: {:?}", lit_input.lit), lit_input.lit
)) )))
})? })?
.size; .size;
trace!("trunc {} with size {} and shift {}", n, width.bits(), 128 - width.bits()); trace!("trunc {} with size {} and shift {}", n, width.bits(), 128 - width.bits());
let result = width.truncate(n); let result = width.truncate(n);
trace!("trunc result: {}", result); 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::Bool(b), ty::Bool) => ty::ValTree::from_scalar_int((*b).into()),
(ast::LitKind::Float(n, _), ty::Float(fty)) => { (ast::LitKind::Float(n, _), ty::Float(fty)) => {
let bits = parse_float_into_scalar(*n, *fty, neg) let bits =
.ok_or_else(|| { parse_float_into_scalar(*n, *fty, neg)
LitToConstError::Reported(tcx.dcx().span_delayed_bug( .ok_or_else(|| {
DUMMY_SP, LitToConstError::Reported(tcx.dcx().delayed_bug(format!(
format!("couldn't parse float literal: {:?}", lit_input.lit), "couldn't parse float literal: {:?}",
)) lit_input.lit
})? )))
.assert_int(); })?
.assert_int();
ty::ValTree::from_scalar_int(bits) ty::ValTree::from_scalar_int(bits)
} }
(ast::LitKind::Char(c), ty::Char) => ty::ValTree::from_scalar_int((*c).into()), (ast::LitKind::Char(c), ty::Char) => ty::ValTree::from_scalar_int((*c).into()),
(ast::LitKind::Err, _) => { (ast::LitKind::Err, _) => {
return Err(LitToConstError::Reported( 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), _ => return Err(LitToConstError::TypeError),

View file

@ -31,7 +31,7 @@ pub fn check_crate(tcx: TyCtxt<'_>) {
if !errors.is_empty() { if !errors.is_empty() {
let message = errors.iter().fold(String::new(), |s1, s2| s1 + "\n" + s2); 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);
} }
} }
} }

View file

@ -98,7 +98,6 @@ use rustc_middle::query::Providers;
use rustc_middle::ty::{self, RootVariableMinCaptureList, Ty, TyCtxt}; use rustc_middle::ty::{self, RootVariableMinCaptureList, Ty, TyCtxt};
use rustc_session::lint; use rustc_session::lint;
use rustc_span::symbol::{kw, sym, Symbol}; use rustc_span::symbol::{kw, sym, Symbol};
use rustc_span::DUMMY_SP;
use rustc_span::{BytePos, Span}; use rustc_span::{BytePos, Span};
use std::io; use std::io;
@ -560,7 +559,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
match self.successors[ln] { match self.successors[ln] {
Some(successor) => self.assigned_on_entry(successor, var), Some(successor) => self.assigned_on_entry(successor, var),
None => { None => {
self.ir.tcx.dcx().span_delayed_bug(DUMMY_SP, "no successor"); self.ir.tcx.dcx().delayed_bug("no successor");
true true
} }
} }

View file

@ -431,17 +431,14 @@ where
// We have an inconsistency. This can happen if one of the two // We have an inconsistency. This can happen if one of the two
// results is tainted by errors. In this case, delay a bug to // results is tainted by errors. In this case, delay a bug to
// ensure compilation is doomed. // ensure compilation is doomed.
qcx.dep_context().sess().dcx().span_delayed_bug( qcx.dep_context().sess().dcx().delayed_bug(format!(
DUMMY_SP, "Computed query value for {:?}({:?}) is inconsistent with fed value,\n\
format!(
"Computed query value for {:?}({:?}) is inconsistent with fed value,\n\
computed={:#?}\nfed={:#?}", computed={:#?}\nfed={:#?}",
query.dep_kind(), query.dep_kind(),
key, key,
formatter(&result), formatter(&result),
formatter(&cached_result), formatter(&cached_result),
), ));
);
} }
} }
} }

View file

@ -341,10 +341,7 @@ impl Session {
if self.dcx().err_count() == old_count { if self.dcx().err_count() == old_count {
Ok(result) Ok(result)
} else { } else {
Err(self.dcx().span_delayed_bug( Err(self.dcx().delayed_bug("`self.err_count()` changed but an error was not emitted"))
rustc_span::DUMMY_SP,
"`self.err_count()` changed but an error was not emitted",
))
} }
} }

View file

@ -14,7 +14,7 @@ use rustc_middle::ty::{self, GenericParamDefKind, TyCtxt};
use rustc_parse_format::{ParseMode, Parser, Piece, Position}; use rustc_parse_format::{ParseMode, Parser, Piece, Position};
use rustc_session::lint::builtin::UNKNOWN_OR_MALFORMED_DIAGNOSTIC_ATTRIBUTES; use rustc_session::lint::builtin::UNKNOWN_OR_MALFORMED_DIAGNOSTIC_ATTRIBUTES;
use rustc_span::symbol::{kw, sym, Symbol}; use rustc_span::symbol::{kw, sym, Symbol};
use rustc_span::{Span, DUMMY_SP}; use rustc_span::Span;
use std::iter; use std::iter;
use crate::errors::{ use crate::errors::{
@ -657,9 +657,7 @@ impl<'tcx> OnUnimplementedDirective {
Ok(None) Ok(None)
} else { } else {
let reported = tcx let reported = tcx.dcx().delayed_bug("of_item: neither meta_item_list nor value_str");
.dcx()
.span_delayed_bug(DUMMY_SP, "of_item: neither meta_item_list nor value_str");
return Err(reported); return Err(reported);
}; };
debug!("of_item({:?}) = {:?}", item_def_id, result); debug!("of_item({:?}) = {:?}", item_def_id, result);

View file

@ -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 /// Reports that an overflow has occurred and halts compilation. We

View file

@ -14,7 +14,6 @@ use rustc_infer::traits::Normalized;
use rustc_middle::ty::fold::{FallibleTypeFolder, TypeFoldable, TypeSuperFoldable}; use rustc_middle::ty::fold::{FallibleTypeFolder, TypeFoldable, TypeSuperFoldable};
use rustc_middle::ty::visit::{TypeSuperVisitable, TypeVisitable, TypeVisitableExt}; use rustc_middle::ty::visit::{TypeSuperVisitable, TypeVisitable, TypeVisitableExt};
use rustc_middle::ty::{self, Ty, TyCtxt, TypeVisitor}; use rustc_middle::ty::{self, Ty, TyCtxt, TypeVisitor};
use rustc_span::DUMMY_SP;
use std::ops::ControlFlow; use std::ops::ControlFlow;
@ -286,10 +285,8 @@ impl<'cx, 'tcx> FallibleTypeFolder<TyCtxt<'tcx>> for QueryNormalizer<'cx, 'tcx>
// Rustdoc normalizes possibly not well-formed types, so only // Rustdoc normalizes possibly not well-formed types, so only
// treat this as a bug if we're not in rustdoc. // treat this as a bug if we're not in rustdoc.
if !tcx.sess.opts.actually_rustdoc { if !tcx.sess.opts.actually_rustdoc {
tcx.dcx().span_delayed_bug( tcx.dcx()
DUMMY_SP, .delayed_bug(format!("unexpected ambiguity: {c_data:?} {result:?}"));
format!("unexpected ambiguity: {c_data:?} {result:?}"),
);
} }
return Err(NoSolution); return Err(NoSolution);
} }

View file

@ -6,7 +6,7 @@ use rustc_errors::ErrorGuaranteed;
use rustc_infer::infer::region_constraints::RegionConstraintData; use rustc_infer::infer::region_constraints::RegionConstraintData;
use rustc_middle::traits::query::NoSolution; use rustc_middle::traits::query::NoSolution;
use rustc_middle::ty::{TyCtxt, TypeFoldable}; use rustc_middle::ty::{TyCtxt, TypeFoldable};
use rustc_span::{Span, DUMMY_SP}; use rustc_span::Span;
use std::fmt; use std::fmt;
@ -88,10 +88,9 @@ where
if errors.is_empty() { if errors.is_empty() {
Ok(value) Ok(value)
} else { } else {
Err(infcx.dcx().span_delayed_bug( Err(infcx
DUMMY_SP, .dcx()
format!("errors selecting obligation during MIR typeck: {errors:?}"), .delayed_bug(format!("errors selecting obligation during MIR typeck: {errors:?}")))
))
} }
})?; })?;

View file

@ -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_middle::ty::{self, AdtDef, EarlyBinder, GenericArgsRef, Ty, TyCtxt, TypeVisitableExt};
use rustc_session::{DataTypeKind, FieldInfo, FieldKind, SizeKind, VariantInfo}; use rustc_session::{DataTypeKind, FieldInfo, FieldKind, SizeKind, VariantInfo};
use rustc_span::symbol::Symbol; use rustc_span::symbol::Symbol;
use rustc_span::DUMMY_SP;
use rustc_target::abi::*; use rustc_target::abi::*;
use std::fmt::Debug; use std::fmt::Debug;
@ -91,7 +90,7 @@ fn univariant_uninterned<'tcx>(
let dl = cx.data_layout(); let dl = cx.data_layout();
let pack = repr.pack; let pack = repr.pack;
if pack.is_some() && repr.align.is_some() { 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))); 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() => { ty::Adt(def, args) if def.repr().simd() => {
if !def.is_struct() { if !def.is_struct() {
// Should have yielded E0517 by now. // Should have yielded E0517 by now.
tcx.dcx().span_delayed_bug( tcx.dcx().delayed_bug("#[repr(simd)] was applied to an ADT that is not a struct");
DUMMY_SP,
"#[repr(simd)] was applied to an ADT that is not a struct",
);
return Err(error(cx, LayoutError::Unknown(ty))); return Err(error(cx, LayoutError::Unknown(ty)));
} }
@ -374,8 +370,7 @@ fn layout_of_uncached<'tcx>(
// (should be caught by typeck) // (should be caught by typeck)
for fi in fields { for fi in fields {
if fi.ty(tcx, args) != f0_ty { if fi.ty(tcx, args) != f0_ty {
tcx.dcx().span_delayed_bug( tcx.dcx().delayed_bug(
DUMMY_SP,
"#[repr(simd)] was applied to an ADT with heterogeneous field type", "#[repr(simd)] was applied to an ADT with heterogeneous field type",
); );
return Err(error(cx, LayoutError::Unknown(ty))); return Err(error(cx, LayoutError::Unknown(ty)));