]> git.lizzy.rs Git - rust.git/blob - src/librustc/util/bug.rs
don't elide lifetimes in paths in librustc/
[rust.git] / src / librustc / util / bug.rs
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.
4 //
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.
10
11 // These functions are used by macro expansion for bug! and span_bug!
12
13 use ty::tls;
14 use std::fmt;
15 use syntax_pos::{Span, MultiSpan};
16
17 #[cold]
18 #[inline(never)]
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);
23 }
24
25 #[cold]
26 #[inline(never)]
27 pub fn span_bug_fmt<S: Into<MultiSpan>>(
28     file: &'static str,
29     line: u32,
30     span: S,
31     args: fmt::Arguments<'_>,
32 ) -> ! {
33     opt_span_bug_fmt(file, line, Some(span), args);
34 }
35
36 fn opt_span_bug_fmt<S: Into<MultiSpan>>(
37     file: &'static str,
38     line: u32,
39     span: Option<S>,
40     args: fmt::Arguments<'_>,
41 ) -> ! {
42     tls::with_opt(move |tcx| {
43         let msg = format!("{}:{}: {}", file, line, args);
44         match (tcx, span) {
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),
48         }
49     });
50     unreachable!();
51 }