2018-08-04 12:51:33 +00:00
|
|
|
// These functions are used by macro expansion for bug! and span_bug!
|
|
|
|
|
2020-03-12 23:07:58 +00:00
|
|
|
use crate::ty::{tls, TyCtxt};
|
2022-03-24 02:03:04 +00:00
|
|
|
use rustc_errors::MultiSpan;
|
|
|
|
use rustc_span::Span;
|
2018-08-04 12:51:33 +00:00
|
|
|
use std::fmt;
|
2021-02-01 23:17:51 +00:00
|
|
|
use std::panic::{panic_any, Location};
|
2018-08-04 12:51:33 +00:00
|
|
|
|
|
|
|
#[cold]
|
|
|
|
#[inline(never)]
|
2020-06-15 14:17:58 +00:00
|
|
|
#[track_caller]
|
|
|
|
pub fn bug_fmt(args: fmt::Arguments<'_>) -> ! {
|
2018-08-04 12:51:33 +00:00
|
|
|
// this wrapper mostly exists so I don't have to write a fully
|
|
|
|
// qualified path of None::<Span> inside the bug!() macro definition
|
2020-06-15 14:17:58 +00:00
|
|
|
opt_span_bug_fmt(None::<Span>, args, Location::caller());
|
2018-08-04 12:51:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[cold]
|
|
|
|
#[inline(never)]
|
2020-06-15 14:17:58 +00:00
|
|
|
#[track_caller]
|
|
|
|
pub fn span_bug_fmt<S: Into<MultiSpan>>(span: S, args: fmt::Arguments<'_>) -> ! {
|
|
|
|
opt_span_bug_fmt(Some(span), args, Location::caller());
|
2018-08-04 12:51:33 +00:00
|
|
|
}
|
|
|
|
|
2020-12-30 04:16:40 +00:00
|
|
|
#[track_caller]
|
2018-08-04 12:51:33 +00:00
|
|
|
fn opt_span_bug_fmt<S: Into<MultiSpan>>(
|
|
|
|
span: Option<S>,
|
2018-08-30 05:02:42 +00:00
|
|
|
args: fmt::Arguments<'_>,
|
2020-06-15 14:17:58 +00:00
|
|
|
location: &Location<'_>,
|
2018-08-04 12:51:33 +00:00
|
|
|
) -> ! {
|
|
|
|
tls::with_opt(move |tcx| {
|
2023-07-25 20:00:13 +00:00
|
|
|
let msg = format!("{location}: {args}");
|
2018-08-04 12:51:33 +00:00
|
|
|
match (tcx, span) {
|
2023-12-17 19:21:26 +00:00
|
|
|
(Some(tcx), Some(span)) => tcx.sess.dcx().span_bug(span, msg),
|
|
|
|
(Some(tcx), None) => tcx.sess.dcx().bug(msg),
|
2021-02-01 23:17:51 +00:00
|
|
|
(None, _) => panic_any(msg),
|
2018-08-04 12:51:33 +00:00
|
|
|
}
|
2022-12-30 12:38:34 +00:00
|
|
|
})
|
2018-08-04 12:51:33 +00:00
|
|
|
}
|
2020-03-12 23:07:58 +00:00
|
|
|
|
2023-11-30 04:01:11 +00:00
|
|
|
/// A query to trigger a `span_delayed_bug`. Clearly, if one has a `tcx` one can already trigger a
|
|
|
|
/// `span_delayed_bug`, so what is the point of this? It exists to help us test `span_delayed_bug`'s
|
2020-03-12 23:07:58 +00:00
|
|
|
/// interactions with the query system and incremental.
|
2023-11-30 04:01:11 +00:00
|
|
|
pub fn trigger_span_delayed_bug(tcx: TyCtxt<'_>, key: rustc_hir::def_id::DefId) {
|
|
|
|
tcx.sess.span_delayed_bug(
|
2020-03-12 23:07:58 +00:00
|
|
|
tcx.def_span(key),
|
2023-11-30 04:01:11 +00:00
|
|
|
"delayed span bug triggered by #[rustc_error(span_delayed_bug_from_inside_query)]",
|
2020-03-12 23:07:58 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2023-05-15 04:24:45 +00:00
|
|
|
pub fn provide(providers: &mut crate::query::Providers) {
|
2023-11-30 04:01:11 +00:00
|
|
|
*providers = crate::query::Providers { trigger_span_delayed_bug, ..*providers };
|
2020-03-12 23:07:58 +00:00
|
|
|
}
|