1 // These functions are used by macro expansion for bug! and span_bug!
3 use crate::ty
::{tls, TyCtxt}
;
4 use rustc_span
::{MultiSpan, Span}
;
6 use std
::panic
::Location
;
11 pub fn bug_fmt(args
: fmt
::Arguments
<'_
>) -> ! {
12 // this wrapper mostly exists so I don't have to write a fully
13 // qualified path of None::<Span> inside the bug!() macro definition
14 opt_span_bug_fmt(None
::<Span
>, args
, Location
::caller());
20 pub fn span_bug_fmt
<S
: Into
<MultiSpan
>>(span
: S
, args
: fmt
::Arguments
<'_
>) -> ! {
21 opt_span_bug_fmt(Some(span
), args
, Location
::caller());
24 fn opt_span_bug_fmt
<S
: Into
<MultiSpan
>>(
26 args
: fmt
::Arguments
<'_
>,
27 location
: &Location
<'_
>,
29 tls
::with_opt(move |tcx
| {
30 let msg
= format
!("{}: {}", location
, args
);
32 (Some(tcx
), Some(span
)) => tcx
.sess
.diagnostic().span_bug(span
, &msg
),
33 (Some(tcx
), None
) => tcx
.sess
.diagnostic().bug(&msg
),
34 (None
, _
) => panic
!(msg
),
40 /// A query to trigger a `delay_span_bug`. Clearly, if one has a `tcx` one can already trigger a
41 /// `delay_span_bug`, so what is the point of this? It exists to help us test `delay_span_bug`'s
42 /// interactions with the query system and incremental.
43 pub fn trigger_delay_span_bug(tcx
: TyCtxt
<'_
>, key
: rustc_hir
::def_id
::DefId
) {
44 tcx
.sess
.delay_span_bug(
46 "delayed span bug triggered by #[rustc_error(delay_span_bug_from_inside_query)]",
50 pub fn provide(providers
: &mut crate::ty
::query
::Providers
) {
51 *providers
= crate::ty
::query
::Providers { trigger_delay_span_bug, ..*providers }
;