]> git.proxmox.com Git - rustc.git/blame - src/librustc/util/bug.rs
New upstream version 1.34.2+dfsg1
[rustc.git] / src / librustc / util / bug.rs
CommitLineData
b7449926
XL
1// These functions are used by macro expansion for bug! and span_bug!
2
9fa01778 3use crate::ty::tls;
b7449926
XL
4use std::fmt;
5use syntax_pos::{Span, MultiSpan};
6
7#[cold]
8#[inline(never)]
0bf4aa26 9pub fn bug_fmt(file: &'static str, line: u32, args: fmt::Arguments<'_>) -> ! {
b7449926
XL
10 // this wrapper mostly exists so I don't have to write a fully
11 // qualified path of None::<Span> inside the bug!() macro definition
12 opt_span_bug_fmt(file, line, None::<Span>, args);
13}
14
15#[cold]
16#[inline(never)]
17pub fn span_bug_fmt<S: Into<MultiSpan>>(
18 file: &'static str,
19 line: u32,
20 span: S,
0bf4aa26 21 args: fmt::Arguments<'_>,
b7449926
XL
22) -> ! {
23 opt_span_bug_fmt(file, line, Some(span), args);
24}
25
26fn opt_span_bug_fmt<S: Into<MultiSpan>>(
27 file: &'static str,
28 line: u32,
29 span: Option<S>,
0bf4aa26 30 args: fmt::Arguments<'_>,
b7449926
XL
31) -> ! {
32 tls::with_opt(move |tcx| {
33 let msg = format!("{}:{}: {}", file, line, args);
34 match (tcx, span) {
35 (Some(tcx), Some(span)) => tcx.sess.diagnostic().span_bug(span, &msg),
36 (Some(tcx), None) => tcx.sess.diagnostic().bug(&msg),
37 (None, _) => panic!(msg),
38 }
39 });
40 unreachable!();
41}