Move span_bug and bug helper functions to util
This commit is contained in:
parent
ed246fcc95
commit
a8e19bec37
4 changed files with 54 additions and 40 deletions
|
@ -166,6 +166,7 @@ pub mod util {
|
||||||
pub mod nodemap;
|
pub mod nodemap;
|
||||||
pub mod time_graph;
|
pub mod time_graph;
|
||||||
pub mod profiling;
|
pub mod profiling;
|
||||||
|
pub mod bug;
|
||||||
}
|
}
|
||||||
|
|
||||||
// A private module so that macro-expanded idents like
|
// A private module so that macro-expanded idents like
|
||||||
|
|
|
@ -51,14 +51,14 @@ macro_rules! enum_from_u32 {
|
||||||
macro_rules! bug {
|
macro_rules! bug {
|
||||||
() => ( bug!("impossible case reached") );
|
() => ( bug!("impossible case reached") );
|
||||||
($($message:tt)*) => ({
|
($($message:tt)*) => ({
|
||||||
$crate::session::bug_fmt(file!(), line!(), format_args!($($message)*))
|
$crate::util::bug::bug_fmt(file!(), line!(), format_args!($($message)*))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! span_bug {
|
macro_rules! span_bug {
|
||||||
($span:expr, $($message:tt)*) => ({
|
($span:expr, $($message:tt)*) => ({
|
||||||
$crate::session::span_bug_fmt(file!(), line!(), $span, format_args!($($message)*))
|
$crate::util::bug::span_bug_fmt(file!(), line!(), $span, format_args!($($message)*))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,6 @@ use middle::allocator::AllocatorKind;
|
||||||
use middle::dependency_format;
|
use middle::dependency_format;
|
||||||
use session::search_paths::PathKind;
|
use session::search_paths::PathKind;
|
||||||
use session::config::{OutputType, Lto};
|
use session::config::{OutputType, Lto};
|
||||||
use ty::tls;
|
|
||||||
use util::nodemap::{FxHashMap, FxHashSet};
|
use util::nodemap::{FxHashMap, FxHashSet};
|
||||||
use util::common::{duration_to_secs_str, ErrorReported};
|
use util::common::{duration_to_secs_str, ErrorReported};
|
||||||
use util::common::ProfileQueriesMsg;
|
use util::common::ProfileQueriesMsg;
|
||||||
|
@ -49,7 +48,6 @@ use std;
|
||||||
use std::cell::{self, Cell, RefCell};
|
use std::cell::{self, Cell, RefCell};
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::env;
|
use std::env;
|
||||||
use std::fmt;
|
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
@ -1301,39 +1299,3 @@ pub fn compile_result_from_err_count(err_count: usize) -> CompileResult {
|
||||||
Err(CompileIncomplete::Errored(ErrorReported))
|
Err(CompileIncomplete::Errored(ErrorReported))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cold]
|
|
||||||
#[inline(never)]
|
|
||||||
pub fn bug_fmt(file: &'static str, line: u32, args: fmt::Arguments) -> ! {
|
|
||||||
// this wrapper mostly exists so I don't have to write a fully
|
|
||||||
// qualified path of None::<Span> inside the bug!() macro definition
|
|
||||||
opt_span_bug_fmt(file, line, None::<Span>, args);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cold]
|
|
||||||
#[inline(never)]
|
|
||||||
pub fn span_bug_fmt<S: Into<MultiSpan>>(
|
|
||||||
file: &'static str,
|
|
||||||
line: u32,
|
|
||||||
span: S,
|
|
||||||
args: fmt::Arguments,
|
|
||||||
) -> ! {
|
|
||||||
opt_span_bug_fmt(file, line, Some(span), args);
|
|
||||||
}
|
|
||||||
|
|
||||||
fn opt_span_bug_fmt<S: Into<MultiSpan>>(
|
|
||||||
file: &'static str,
|
|
||||||
line: u32,
|
|
||||||
span: Option<S>,
|
|
||||||
args: fmt::Arguments,
|
|
||||||
) -> ! {
|
|
||||||
tls::with_opt(move |tcx| {
|
|
||||||
let msg = format!("{}:{}: {}", file, line, args);
|
|
||||||
match (tcx, span) {
|
|
||||||
(Some(tcx), Some(span)) => tcx.sess.diagnostic().span_bug(span, &msg),
|
|
||||||
(Some(tcx), None) => tcx.sess.diagnostic().bug(&msg),
|
|
||||||
(None, _) => panic!(msg),
|
|
||||||
}
|
|
||||||
});
|
|
||||||
unreachable!();
|
|
||||||
}
|
|
||||||
|
|
51
src/librustc/util/bug.rs
Normal file
51
src/librustc/util/bug.rs
Normal file
|
@ -0,0 +1,51 @@
|
||||||
|
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
|
||||||
|
// file at the top-level directory of this distribution and at
|
||||||
|
// http://rust-lang.org/COPYRIGHT.
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||||
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||||
|
// option. This file may not be copied, modified, or distributed
|
||||||
|
// except according to those terms.
|
||||||
|
|
||||||
|
// These functions are used by macro expansion for bug! and span_bug!
|
||||||
|
|
||||||
|
use ty::tls;
|
||||||
|
use std::fmt;
|
||||||
|
use syntax_pos::{Span, MultiSpan};
|
||||||
|
|
||||||
|
#[cold]
|
||||||
|
#[inline(never)]
|
||||||
|
pub fn bug_fmt(file: &'static str, line: u32, args: fmt::Arguments) -> ! {
|
||||||
|
// this wrapper mostly exists so I don't have to write a fully
|
||||||
|
// qualified path of None::<Span> inside the bug!() macro definition
|
||||||
|
opt_span_bug_fmt(file, line, None::<Span>, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cold]
|
||||||
|
#[inline(never)]
|
||||||
|
pub fn span_bug_fmt<S: Into<MultiSpan>>(
|
||||||
|
file: &'static str,
|
||||||
|
line: u32,
|
||||||
|
span: S,
|
||||||
|
args: fmt::Arguments,
|
||||||
|
) -> ! {
|
||||||
|
opt_span_bug_fmt(file, line, Some(span), args);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn opt_span_bug_fmt<S: Into<MultiSpan>>(
|
||||||
|
file: &'static str,
|
||||||
|
line: u32,
|
||||||
|
span: Option<S>,
|
||||||
|
args: fmt::Arguments,
|
||||||
|
) -> ! {
|
||||||
|
tls::with_opt(move |tcx| {
|
||||||
|
let msg = format!("{}:{}: {}", file, line, args);
|
||||||
|
match (tcx, span) {
|
||||||
|
(Some(tcx), Some(span)) => tcx.sess.diagnostic().span_bug(span, &msg),
|
||||||
|
(Some(tcx), None) => tcx.sess.diagnostic().bug(&msg),
|
||||||
|
(None, _) => panic!(msg),
|
||||||
|
}
|
||||||
|
});
|
||||||
|
unreachable!();
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue