1 // Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
11 // These functions are used by macro expansion for bug! and span_bug!
15 use syntax_pos::{Span, MultiSpan};
19 pub fn bug_fmt(file: &'static str, line: u32, args: fmt::Arguments<'_>) -> ! {
20 // this wrapper mostly exists so I don't have to write a fully
21 // qualified path of None::<Span> inside the bug!() macro definition
22 opt_span_bug_fmt(file, line, None::<Span>, args);
27 pub fn span_bug_fmt<S: Into<MultiSpan>>(
31 args: fmt::Arguments<'_>,
33 opt_span_bug_fmt(file, line, Some(span), args);
36 fn opt_span_bug_fmt<S: Into<MultiSpan>>(
40 args: fmt::Arguments<'_>,
42 tls::with_opt(move |tcx| {
43 let msg = format!("{}:{}: {}", file, line, args);
45 (Some(tcx), Some(span)) => tcx.sess.diagnostic().span_bug(span, &msg),
46 (Some(tcx), None) => tcx.sess.diagnostic().bug(&msg),
47 (None, _) => panic!(msg),