diff options
Diffstat (limited to 'compiler/rustc_middle/src')
20 files changed, 42 insertions, 37 deletions
diff --git a/compiler/rustc_middle/src/macros.rs b/compiler/rustc_middle/src/macros.rs index 8c1e58fefc5..26ca90db018 100644 --- a/compiler/rustc_middle/src/macros.rs +++ b/compiler/rustc_middle/src/macros.rs @@ -4,10 +4,10 @@ /// /// 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::span_delayed_bug`] +/// If the bug should only be emitted when compilation didn't fail, [`DiagCtxt::span_delayed_bug`] /// may be useful. /// -/// [`Session::span_delayed_bug`]: rustc_session::Session::span_delayed_bug +/// [`DiagCtxt::span_delayed_bug`]: rustc_errors::DiagCtxt::span_delayed_bug /// [`span_bug`]: crate::span_bug #[macro_export] macro_rules! bug { @@ -24,10 +24,10 @@ 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::span_delayed_bug`] +/// If the bug should only be emitted when compilation didn't fail, [`DiagCtxt::span_delayed_bug`] /// may be useful. /// -/// [`Session::span_delayed_bug`]: rustc_session::Session::span_delayed_bug +/// [`DiagCtxt::span_delayed_bug`]: rustc_errors::DiagCtxt::span_delayed_bug #[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/lang_items.rs b/compiler/rustc_middle/src/middle/lang_items.rs index 2899e629d79..f92c72c8a58 100644 --- a/compiler/rustc_middle/src/middle/lang_items.rs +++ b/compiler/rustc_middle/src/middle/lang_items.rs @@ -19,7 +19,7 @@ impl<'tcx> TyCtxt<'tcx> { /// If not found, fatally aborts compilation. pub fn require_lang_item(self, lang_item: LangItem, span: Option<Span>) -> DefId { self.lang_items().get(lang_item).unwrap_or_else(|| { - self.sess.emit_fatal(crate::error::RequiresLangItem { span, name: lang_item.name() }); + self.dcx().emit_fatal(crate::error::RequiresLangItem { span, name: lang_item.name() }); }) } diff --git a/compiler/rustc_middle/src/middle/limits.rs b/compiler/rustc_middle/src/middle/limits.rs index b29be92ae26..344ea38192e 100644 --- a/compiler/rustc_middle/src/middle/limits.rs +++ b/compiler/rustc_middle/src/middle/limits.rs @@ -64,7 +64,7 @@ fn get_limit(krate_attrs: &[Attribute], sess: &Session, name: Symbol, default: u IntErrorKind::Zero => bug!("zero is a valid `limit`"), kind => bug!("unimplemented IntErrorKind variant: {:?}", kind), }; - sess.emit_err(LimitInvalid { span: attr.span, value_span, error_str }); + sess.dcx().emit_err(LimitInvalid { span: attr.span, value_span, error_str }); } } } diff --git a/compiler/rustc_middle/src/middle/stability.rs b/compiler/rustc_middle/src/middle/stability.rs index 0cba6d5b52a..b2d1124b2ed 100644 --- a/compiler/rustc_middle/src/middle/stability.rs +++ b/compiler/rustc_middle/src/middle/stability.rs @@ -565,7 +565,7 @@ 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.span_delayed_bug(span, format!("encountered unmarked API: {def_id:?}")); + self.dcx().span_delayed_bug(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 2a9e0847f43..a92b85a716f 100644 --- a/compiler/rustc_middle/src/mir/interpret/allocation.rs +++ b/compiler/rustc_middle/src/mir/interpret/allocation.rs @@ -315,7 +315,7 @@ impl<Prov: Provenance, Bytes: AllocBytes> Allocation<Prov, (), Bytes> { pub fn try_uninit<'tcx>(size: Size, align: Align) -> InterpResult<'tcx, Self> { Self::uninit_inner(size, align, || { ty::tls::with(|tcx| { - tcx.sess.span_delayed_bug(DUMMY_SP, "exhausted memory during interpretation") + tcx.dcx().span_delayed_bug(DUMMY_SP, "exhausted memory during interpretation") }); InterpError::ResourceExhaustion(ResourceExhaustionInfo::MemoryExhausted).into() }) diff --git a/compiler/rustc_middle/src/mir/interpret/error.rs b/compiler/rustc_middle/src/mir/interpret/error.rs index 2cd2fcca9d5..e6536074f35 100644 --- a/compiler/rustc_middle/src/mir/interpret/error.rs +++ b/compiler/rustc_middle/src/mir/interpret/error.rs @@ -47,7 +47,7 @@ impl ErrorHandled { match self { &ErrorHandled::Reported(err, span) => { if !err.is_tainted_by_errors && !span.is_dummy() { - tcx.sess.emit_note(error::ErroneousConstant { span }); + tcx.dcx().emit_note(error::ErroneousConstant { span }); } } &ErrorHandled::TooGeneric(_) => {} @@ -91,7 +91,7 @@ pub type EvalToConstValueResult<'tcx> = Result<ConstValue<'tcx>, ErrorHandled>; pub type EvalToValTreeResult<'tcx> = Result<Option<ValTree<'tcx>>, ErrorHandled>; pub fn struct_error<'tcx>(tcx: TyCtxtAt<'tcx>, msg: &str) -> DiagnosticBuilder<'tcx> { - struct_span_err!(tcx.sess, tcx.span, E0080, "{}", msg) + struct_span_err!(tcx.dcx(), tcx.span, E0080, "{}", msg) } #[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))] diff --git a/compiler/rustc_middle/src/query/plumbing.rs b/compiler/rustc_middle/src/query/plumbing.rs index 0d1f3c1f8b5..d2ff1e3c094 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.sess.span_delayed_bug(DUMMY_SP, format!( + tcx.dcx().span_delayed_bug(DUMMY_SP, 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/traits/query.rs b/compiler/rustc_middle/src/traits/query.rs index 34c56eb0d7b..5f02dd22961 100644 --- a/compiler/rustc_middle/src/traits/query.rs +++ b/compiler/rustc_middle/src/traits/query.rs @@ -105,7 +105,7 @@ pub struct DropckOutlivesResult<'tcx> { impl<'tcx> DropckOutlivesResult<'tcx> { pub fn report_overflows(&self, tcx: TyCtxt<'tcx>, span: Span, ty: Ty<'tcx>) { if let Some(overflow_ty) = self.overflows.get(0) { - tcx.sess.emit_err(DropCheckOverflow { span, ty, overflow_ty: *overflow_ty }); + tcx.dcx().emit_err(DropCheckOverflow { span, ty, overflow_ty: *overflow_ty }); } } } diff --git a/compiler/rustc_middle/src/traits/specialization_graph.rs b/compiler/rustc_middle/src/traits/specialization_graph.rs index 6db427064d1..898258445dc 100644 --- a/compiler/rustc_middle/src/traits/specialization_graph.rs +++ b/compiler/rustc_middle/src/traits/specialization_graph.rs @@ -76,7 +76,7 @@ impl OverlapMode { }) .find(|attr| attr.has_name(sym::rustc_strict_coherence)) .map(|attr| attr.span); - tcx.sess.emit_err(StrictCoherenceNeedsNegativeCoherence { + tcx.dcx().emit_err(StrictCoherenceNeedsNegativeCoherence { span: tcx.def_span(trait_id), attr_span, }); diff --git a/compiler/rustc_middle/src/ty/adt.rs b/compiler/rustc_middle/src/ty/adt.rs index 1d9a25628b0..b95ae5881e2 100644 --- a/compiler/rustc_middle/src/ty/adt.rs +++ b/compiler/rustc_middle/src/ty/adt.rs @@ -470,7 +470,7 @@ impl<'tcx> AdtDef<'tcx> { Some(Discr { val: b, ty }) } else { info!("invalid enum discriminant: {:#?}", val); - tcx.sess.emit_err(crate::error::ConstEvalNonIntError { + tcx.dcx().emit_err(crate::error::ConstEvalNonIntError { span: tcx.def_span(expr_did), }); None @@ -481,7 +481,7 @@ impl<'tcx> AdtDef<'tcx> { ErrorHandled::Reported(..) => "enum discriminant evaluation failed", ErrorHandled::TooGeneric(..) => "enum discriminant depends on generics", }; - tcx.sess.span_delayed_bug(tcx.def_span(expr_did), msg); + tcx.dcx().span_delayed_bug(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 2d3ee33489e..6ec1dec9781 100644 --- a/compiler/rustc_middle/src/ty/consts.rs +++ b/compiler/rustc_middle/src/ty/consts.rs @@ -159,7 +159,7 @@ impl<'tcx> Const<'tcx> { span: S, msg: &'static str, ) -> Const<'tcx> { - let reported = tcx.sess.span_delayed_bug(span, msg); + let reported = tcx.dcx().span_delayed_bug(span, msg); Const::new_error(tcx, reported, ty) } @@ -223,7 +223,7 @@ impl<'tcx> Const<'tcx> { match tcx.at(expr.span).lit_to_const(lit_input) { Ok(c) => return Some(c), Err(e) => { - tcx.sess.span_delayed_bug( + tcx.dcx().span_delayed_bug( expr.span, format!("Const::from_anon_const: couldn't lit_to_const {e:?}"), ); @@ -322,7 +322,7 @@ impl<'tcx> Const<'tcx> { let Some(c) = tcx.const_eval_resolve_for_typeck(param_env, unevaluated, span)? else { // This can happen when we run on ill-typed code. - let e = tcx.sess.span_delayed_bug( + let e = tcx.dcx().span_delayed_bug( span.unwrap_or(DUMMY_SP), "`ty::Const::eval` called on a non-valtree-compatible type", ); diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs index 655dde1d9c9..ac675a70b54 100644 --- a/compiler/rustc_middle/src/ty/context.rs +++ b/compiler/rustc_middle/src/ty/context.rs @@ -44,7 +44,7 @@ use rustc_data_structures::sync::{self, FreezeReadGuard, Lock, WorkerLocal}; use rustc_data_structures::sync::{DynSend, DynSync}; use rustc_data_structures::unord::UnordSet; use rustc_errors::{ - DecorateLint, DiagnosticBuilder, DiagnosticMessage, ErrorGuaranteed, MultiSpan, + DecorateLint, DiagCtxt, DiagnosticBuilder, DiagnosticMessage, ErrorGuaranteed, MultiSpan, }; use rustc_hir as hir; use rustc_hir::def::DefKind; @@ -747,7 +747,7 @@ impl<'tcx> TyCtxt<'tcx> { { Bound::Included(a) } else { - self.sess.span_delayed_bug( + self.dcx().span_delayed_bug( attr.span, "invalid rustc_layout_scalar_valid_range attribute", ); @@ -783,7 +783,7 @@ impl<'tcx> TyCtxt<'tcx> { hooks: crate::hooks::Providers, ) -> GlobalCtxt<'tcx> { let data_layout = s.target.parse_data_layout().unwrap_or_else(|err| { - s.emit_fatal(err); + s.dcx().emit_fatal(err); }); let interners = CtxtInterners::new(arena); let common_types = CommonTypes::new(&interners, s, &untracked); @@ -1018,6 +1018,10 @@ impl<'tcx> TyCtxt<'tcx> { self.def_path(def_id).to_string_no_crate_verbose() ) } + + pub fn dcx(self) -> &'tcx DiagCtxt { + self.sess.dcx() + } } impl<'tcx> TyCtxtAt<'tcx> { diff --git a/compiler/rustc_middle/src/ty/layout.rs b/compiler/rustc_middle/src/ty/layout.rs index 5ae758edfa3..8a02914b435 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.sess.span_delayed_bug(DUMMY_SP, txt); + self.tcx.dcx().span_delayed_bug(DUMMY_SP, txt); } fn current_data_layout(&self) -> Self::TargetDataLayoutRef { diff --git a/compiler/rustc_middle/src/ty/mod.rs b/compiler/rustc_middle/src/ty/mod.rs index 36b8d387d69..9f1ff4538aa 100644 --- a/compiler/rustc_middle/src/ty/mod.rs +++ b/compiler/rustc_middle/src/ty/mod.rs @@ -1495,7 +1495,7 @@ impl<'tcx> OpaqueHiddenType<'tcx> { } else { TypeMismatchReason::PreviousUse { span: self.span } }; - tcx.sess.create_err(OpaqueHiddenTypeMismatch { + tcx.dcx().create_err(OpaqueHiddenTypeMismatch { self_ty: self.ty, other_ty: other.ty, other_span: other.span, diff --git a/compiler/rustc_middle/src/ty/opaque_types.rs b/compiler/rustc_middle/src/ty/opaque_types.rs index 1305f63bdbc..71fe7d15a6c 100644 --- a/compiler/rustc_middle/src/ty/opaque_types.rs +++ b/compiler/rustc_middle/src/ty/opaque_types.rs @@ -130,7 +130,7 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for ReverseMapper<'tcx> { None => { let e = self .tcx - .sess + .dcx() .struct_span_err(self.span, "non-defining opaque type use in defining scope") .span_label( self.span, @@ -174,7 +174,7 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for ReverseMapper<'tcx> { debug!(?param, ?self.map); if !self.ignore_errors { self.tcx - .sess + .dcx() .struct_span_err( self.span, format!( @@ -208,7 +208,7 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for ReverseMapper<'tcx> { None => { let guar = self .tcx - .sess + .dcx() .create_err(ConstNotUsedTraitAlias { ct: ct.to_string(), span: self.span, diff --git a/compiler/rustc_middle/src/ty/sty.rs b/compiler/rustc_middle/src/ty/sty.rs index a0debc8a165..5b9dff8e3f2 100644 --- a/compiler/rustc_middle/src/ty/sty.rs +++ b/compiler/rustc_middle/src/ty/sty.rs @@ -1557,7 +1557,7 @@ impl<'tcx> Region<'tcx> { span: S, msg: &'static str, ) -> Region<'tcx> { - let reported = tcx.sess.span_delayed_bug(span, msg); + let reported = tcx.dcx().span_delayed_bug(span, msg); Region::new_error(tcx, reported) } @@ -2004,7 +2004,7 @@ impl<'tcx> Ty<'tcx> { span: S, msg: impl Into<DiagnosticMessage>, ) -> Ty<'tcx> { - let reported = tcx.sess.span_delayed_bug(span, msg); + let reported = tcx.dcx().span_delayed_bug(span, msg); Ty::new(tcx, Error(reported)) } diff --git a/compiler/rustc_middle/src/ty/typeck_results.rs b/compiler/rustc_middle/src/ty/typeck_results.rs index d372c1cd604..58699c934b6 100644 --- a/compiler/rustc_middle/src/ty/typeck_results.rs +++ b/compiler/rustc_middle/src/ty/typeck_results.rs @@ -391,7 +391,7 @@ impl<'tcx> TypeckResults<'tcx> { pub fn extract_binding_mode(&self, s: &Session, id: HirId, sp: Span) -> Option<BindingMode> { self.pat_binding_modes().get(id).copied().or_else(|| { - s.span_delayed_bug(sp, "missing binding mode"); + s.dcx().span_delayed_bug(sp, "missing binding mode"); None }) } diff --git a/compiler/rustc_middle/src/ty/util.rs b/compiler/rustc_middle/src/ty/util.rs index ab2488f2e91..55dc72b19d3 100644 --- a/compiler/rustc_middle/src/ty/util.rs +++ b/compiler/rustc_middle/src/ty/util.rs @@ -223,8 +223,9 @@ impl<'tcx> TyCtxt<'tcx> { Limit(0) => Limit(2), limit => limit * 2, }; - let reported = - self.sess.emit_err(crate::error::RecursionLimitReached { ty, suggested_limit }); + let reported = self + .dcx() + .emit_err(crate::error::RecursionLimitReached { ty, suggested_limit }); return Ty::new_error(self, reported); } match *ty.kind() { @@ -360,13 +361,13 @@ impl<'tcx> TyCtxt<'tcx> { } let Some(item_id) = self.associated_item_def_ids(impl_did).first() else { - self.sess + self.dcx() .span_delayed_bug(self.def_span(impl_did), "Drop impl without drop function"); return; }; if let Some((old_item_id, _)) = dtor_candidate { - self.sess + self.dcx() .struct_span_err(self.def_span(item_id), "multiple drop impls found") .span_note(self.def_span(old_item_id), "other impl here") .delay_as_bug(); diff --git a/compiler/rustc_middle/src/util/bug.rs b/compiler/rustc_middle/src/util/bug.rs index 5c9dd18aeac..d1a3dbbf5d3 100644 --- a/compiler/rustc_middle/src/util/bug.rs +++ b/compiler/rustc_middle/src/util/bug.rs @@ -31,8 +31,8 @@ fn opt_span_bug_fmt<S: Into<MultiSpan>>( tls::with_opt(move |tcx| { let msg = format!("{location}: {args}"); match (tcx, span) { - (Some(tcx), Some(span)) => tcx.sess.dcx().span_bug(span, msg), - (Some(tcx), None) => tcx.sess.dcx().bug(msg), + (Some(tcx), Some(span)) => tcx.dcx().span_bug(span, msg), + (Some(tcx), None) => tcx.dcx().bug(msg), (None, _) => panic_any(msg), } }) @@ -42,7 +42,7 @@ fn opt_span_bug_fmt<S: Into<MultiSpan>>( /// `span_delayed_bug`, so what is the point of this? It exists to help us test `span_delayed_bug`'s /// interactions with the query system and incremental. pub fn trigger_span_delayed_bug(tcx: TyCtxt<'_>, key: rustc_hir::def_id::DefId) { - tcx.sess.span_delayed_bug( + tcx.dcx().span_delayed_bug( tcx.def_span(key), "delayed span bug triggered by #[rustc_error(span_delayed_bug_from_inside_query)]", ); diff --git a/compiler/rustc_middle/src/values.rs b/compiler/rustc_middle/src/values.rs index 3224f2f26df..a85296d886d 100644 --- a/compiler/rustc_middle/src/values.rs +++ b/compiler/rustc_middle/src/values.rs @@ -191,7 +191,7 @@ pub fn recursive_type_error( s }; let mut err = struct_span_err!( - tcx.sess, + tcx.dcx(), err_span, E0072, "recursive type{} {} {} infinite size", |
