Skip to content

Commit a8e19be

Browse files
Move span_bug and bug helper functions to util
1 parent ed246fc commit a8e19be

File tree

4 files changed

+54
-40
lines changed

4 files changed

+54
-40
lines changed

src/librustc/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ pub mod util {
166166
pub mod nodemap;
167167
pub mod time_graph;
168168
pub mod profiling;
169+
pub mod bug;
169170
}
170171

171172
// A private module so that macro-expanded idents like

src/librustc/macros.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,14 @@ macro_rules! enum_from_u32 {
5151
macro_rules! bug {
5252
() => ( bug!("impossible case reached") );
5353
($($message:tt)*) => ({
54-
$crate::session::bug_fmt(file!(), line!(), format_args!($($message)*))
54+
$crate::util::bug::bug_fmt(file!(), line!(), format_args!($($message)*))
5555
})
5656
}
5757

5858
#[macro_export]
5959
macro_rules! span_bug {
6060
($span:expr, $($message:tt)*) => ({
61-
$crate::session::span_bug_fmt(file!(), line!(), $span, format_args!($($message)*))
61+
$crate::util::bug::span_bug_fmt(file!(), line!(), $span, format_args!($($message)*))
6262
})
6363
}
6464

src/librustc/session/mod.rs

-38
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ use middle::allocator::AllocatorKind;
2020
use middle::dependency_format;
2121
use session::search_paths::PathKind;
2222
use session::config::{OutputType, Lto};
23-
use ty::tls;
2423
use util::nodemap::{FxHashMap, FxHashSet};
2524
use util::common::{duration_to_secs_str, ErrorReported};
2625
use util::common::ProfileQueriesMsg;
@@ -49,7 +48,6 @@ use std;
4948
use std::cell::{self, Cell, RefCell};
5049
use std::collections::HashMap;
5150
use std::env;
52-
use std::fmt;
5351
use std::io::Write;
5452
use std::path::{Path, PathBuf};
5553
use std::time::Duration;
@@ -1301,39 +1299,3 @@ pub fn compile_result_from_err_count(err_count: usize) -> CompileResult {
13011299
Err(CompileIncomplete::Errored(ErrorReported))
13021300
}
13031301
}
1304-
1305-
#[cold]
1306-
#[inline(never)]
1307-
pub fn bug_fmt(file: &'static str, line: u32, args: fmt::Arguments) -> ! {
1308-
// this wrapper mostly exists so I don't have to write a fully
1309-
// qualified path of None::<Span> inside the bug!() macro definition
1310-
opt_span_bug_fmt(file, line, None::<Span>, args);
1311-
}
1312-
1313-
#[cold]
1314-
#[inline(never)]
1315-
pub fn span_bug_fmt<S: Into<MultiSpan>>(
1316-
file: &'static str,
1317-
line: u32,
1318-
span: S,
1319-
args: fmt::Arguments,
1320-
) -> ! {
1321-
opt_span_bug_fmt(file, line, Some(span), args);
1322-
}
1323-
1324-
fn opt_span_bug_fmt<S: Into<MultiSpan>>(
1325-
file: &'static str,
1326-
line: u32,
1327-
span: Option<S>,
1328-
args: fmt::Arguments,
1329-
) -> ! {
1330-
tls::with_opt(move |tcx| {
1331-
let msg = format!("{}:{}: {}", file, line, args);
1332-
match (tcx, span) {
1333-
(Some(tcx), Some(span)) => tcx.sess.diagnostic().span_bug(span, &msg),
1334-
(Some(tcx), None) => tcx.sess.diagnostic().bug(&msg),
1335-
(None, _) => panic!(msg),
1336-
}
1337-
});
1338-
unreachable!();
1339-
}

src/librustc/util/bug.rs

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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+
}

0 commit comments

Comments
 (0)