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