]> git.proxmox.com Git - rustc.git/blob - src/librustc/util/bug.rs
New upstream version 1.34.2+dfsg1
[rustc.git] / src / librustc / util / bug.rs
1 // These functions are used by macro expansion for bug! and span_bug!
2
3 use crate::ty::tls;
4 use std::fmt;
5 use syntax_pos::{Span, MultiSpan};
6
7 #[cold]
8 #[inline(never)]
9 pub fn bug_fmt(file: &'static str, line: u32, args: fmt::Arguments<'_>) -> ! {
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)]
17 pub fn span_bug_fmt<S: Into<MultiSpan>>(
18 file: &'static str,
19 line: u32,
20 span: S,
21 args: fmt::Arguments<'_>,
22 ) -> ! {
23 opt_span_bug_fmt(file, line, Some(span), args);
24 }
25
26 fn opt_span_bug_fmt<S: Into<MultiSpan>>(
27 file: &'static str,
28 line: u32,
29 span: Option<S>,
30 args: fmt::Arguments<'_>,
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 }