Move a bunch of stuff from Session to syntax::errors
The intention here is that Session is a very thin wrapper over the error handling infra.
This commit is contained in:
parent
6309b0f5bb
commit
a478811822
5 changed files with 19 additions and 68 deletions
|
@ -64,14 +64,10 @@ pub struct Session {
|
||||||
pub crate_metadata: RefCell<Vec<String>>,
|
pub crate_metadata: RefCell<Vec<String>>,
|
||||||
pub features: RefCell<feature_gate::Features>,
|
pub features: RefCell<feature_gate::Features>,
|
||||||
|
|
||||||
pub delayed_span_bug: RefCell<Option<(codemap::Span, String)>>,
|
|
||||||
|
|
||||||
/// The maximum recursion limit for potentially infinitely recursive
|
/// The maximum recursion limit for potentially infinitely recursive
|
||||||
/// operations such as auto-dereference and monomorphization.
|
/// operations such as auto-dereference and monomorphization.
|
||||||
pub recursion_limit: Cell<usize>,
|
pub recursion_limit: Cell<usize>,
|
||||||
|
|
||||||
pub can_print_warnings: bool,
|
|
||||||
|
|
||||||
/// The metadata::creader module may inject an allocator dependency if it
|
/// The metadata::creader module may inject an allocator dependency if it
|
||||||
/// didn't already find one, and this tracks what was injected.
|
/// didn't already find one, and this tracks what was injected.
|
||||||
pub injected_allocator: Cell<Option<ast::CrateNum>>,
|
pub injected_allocator: Cell<Option<ast::CrateNum>>,
|
||||||
|
@ -85,21 +81,12 @@ pub struct Session {
|
||||||
|
|
||||||
impl Session {
|
impl Session {
|
||||||
pub fn span_fatal(&self, sp: Span, msg: &str) -> ! {
|
pub fn span_fatal(&self, sp: Span, msg: &str) -> ! {
|
||||||
if self.opts.treat_err_as_bug {
|
|
||||||
self.span_bug(sp, msg);
|
|
||||||
}
|
|
||||||
panic!(self.diagnostic().span_fatal(sp, msg))
|
panic!(self.diagnostic().span_fatal(sp, msg))
|
||||||
}
|
}
|
||||||
pub fn span_fatal_with_code(&self, sp: Span, msg: &str, code: &str) -> ! {
|
pub fn span_fatal_with_code(&self, sp: Span, msg: &str, code: &str) -> ! {
|
||||||
if self.opts.treat_err_as_bug {
|
|
||||||
self.span_bug(sp, msg);
|
|
||||||
}
|
|
||||||
panic!(self.diagnostic().span_fatal_with_code(sp, msg, code))
|
panic!(self.diagnostic().span_fatal_with_code(sp, msg, code))
|
||||||
}
|
}
|
||||||
pub fn fatal(&self, msg: &str) -> ! {
|
pub fn fatal(&self, msg: &str) -> ! {
|
||||||
if self.opts.treat_err_as_bug {
|
|
||||||
self.bug(msg);
|
|
||||||
}
|
|
||||||
panic!(self.diagnostic().fatal(msg))
|
panic!(self.diagnostic().fatal(msg))
|
||||||
}
|
}
|
||||||
pub fn span_err_or_warn(&self, is_warning: bool, sp: Span, msg: &str) {
|
pub fn span_err_or_warn(&self, is_warning: bool, sp: Span, msg: &str) {
|
||||||
|
@ -110,9 +97,6 @@ impl Session {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn span_err(&self, sp: Span, msg: &str) {
|
pub fn span_err(&self, sp: Span, msg: &str) {
|
||||||
if self.opts.treat_err_as_bug {
|
|
||||||
self.span_bug(sp, msg);
|
|
||||||
}
|
|
||||||
match split_msg_into_multilines(msg) {
|
match split_msg_into_multilines(msg) {
|
||||||
Some(msg) => self.diagnostic().span_err(sp, &msg[..]),
|
Some(msg) => self.diagnostic().span_err(sp, &msg[..]),
|
||||||
None => self.diagnostic().span_err(sp, msg)
|
None => self.diagnostic().span_err(sp, msg)
|
||||||
|
@ -126,18 +110,12 @@ impl Session {
|
||||||
See RFC 1214 for details."));
|
See RFC 1214 for details."));
|
||||||
}
|
}
|
||||||
pub fn span_err_with_code(&self, sp: Span, msg: &str, code: &str) {
|
pub fn span_err_with_code(&self, sp: Span, msg: &str, code: &str) {
|
||||||
if self.opts.treat_err_as_bug {
|
|
||||||
self.span_bug(sp, msg);
|
|
||||||
}
|
|
||||||
match split_msg_into_multilines(msg) {
|
match split_msg_into_multilines(msg) {
|
||||||
Some(msg) => self.diagnostic().span_err_with_code(sp, &msg[..], code),
|
Some(msg) => self.diagnostic().span_err_with_code(sp, &msg[..], code),
|
||||||
None => self.diagnostic().span_err_with_code(sp, msg, code)
|
None => self.diagnostic().span_err_with_code(sp, msg, code)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn err(&self, msg: &str) {
|
pub fn err(&self, msg: &str) {
|
||||||
if self.opts.treat_err_as_bug {
|
|
||||||
self.bug(msg);
|
|
||||||
}
|
|
||||||
self.diagnostic().err(msg)
|
self.diagnostic().err(msg)
|
||||||
}
|
}
|
||||||
pub fn err_count(&self) -> usize {
|
pub fn err_count(&self) -> usize {
|
||||||
|
@ -148,14 +126,6 @@ impl Session {
|
||||||
}
|
}
|
||||||
pub fn abort_if_errors(&self) {
|
pub fn abort_if_errors(&self) {
|
||||||
self.diagnostic().abort_if_errors();
|
self.diagnostic().abort_if_errors();
|
||||||
|
|
||||||
let delayed_bug = self.delayed_span_bug.borrow();
|
|
||||||
match *delayed_bug {
|
|
||||||
Some((span, ref errmsg)) => {
|
|
||||||
self.diagnostic().span_bug(span, errmsg);
|
|
||||||
},
|
|
||||||
_ => {}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
pub fn abort_if_new_errors<F>(&self, mut f: F)
|
pub fn abort_if_new_errors<F>(&self, mut f: F)
|
||||||
where F: FnMut()
|
where F: FnMut()
|
||||||
|
@ -167,19 +137,13 @@ impl Session {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn span_warn(&self, sp: Span, msg: &str) {
|
pub fn span_warn(&self, sp: Span, msg: &str) {
|
||||||
if self.can_print_warnings {
|
self.diagnostic().span_warn(sp, msg)
|
||||||
self.diagnostic().span_warn(sp, msg)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
pub fn span_warn_with_code(&self, sp: Span, msg: &str, code: &str) {
|
pub fn span_warn_with_code(&self, sp: Span, msg: &str, code: &str) {
|
||||||
if self.can_print_warnings {
|
self.diagnostic().span_warn_with_code(sp, msg, code)
|
||||||
self.diagnostic().span_warn_with_code(sp, msg, code)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
pub fn warn(&self, msg: &str) {
|
pub fn warn(&self, msg: &str) {
|
||||||
if self.can_print_warnings {
|
self.diagnostic().warn(msg)
|
||||||
self.diagnostic().warn(msg)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
pub fn opt_span_warn(&self, opt_sp: Option<Span>, msg: &str) {
|
pub fn opt_span_warn(&self, opt_sp: Option<Span>, msg: &str) {
|
||||||
match opt_sp {
|
match opt_sp {
|
||||||
|
@ -223,8 +187,7 @@ impl Session {
|
||||||
}
|
}
|
||||||
/// Delay a span_bug() call until abort_if_errors()
|
/// Delay a span_bug() call until abort_if_errors()
|
||||||
pub fn delay_span_bug(&self, sp: Span, msg: &str) {
|
pub fn delay_span_bug(&self, sp: Span, msg: &str) {
|
||||||
let mut delayed = self.delayed_span_bug.borrow_mut();
|
self.diagnostic().delay_span_bug(sp, msg)
|
||||||
*delayed = Some((sp, msg.to_string()));
|
|
||||||
}
|
}
|
||||||
pub fn span_bug(&self, sp: Span, msg: &str) -> ! {
|
pub fn span_bug(&self, sp: Span, msg: &str) -> ! {
|
||||||
self.diagnostic().span_bug(sp, msg)
|
self.diagnostic().span_bug(sp, msg)
|
||||||
|
@ -270,8 +233,7 @@ impl Session {
|
||||||
// This exists to help with refactoring to eliminate impossible
|
// This exists to help with refactoring to eliminate impossible
|
||||||
// cases later on
|
// cases later on
|
||||||
pub fn impossible_case(&self, sp: Span, msg: &str) -> ! {
|
pub fn impossible_case(&self, sp: Span, msg: &str) -> ! {
|
||||||
self.span_bug(sp,
|
self.span_bug(sp, &format!("impossible case reached: {}", msg));
|
||||||
&format!("impossible case reached: {}", msg));
|
|
||||||
}
|
}
|
||||||
pub fn verbose(&self) -> bool { self.opts.debugging_opts.verbose }
|
pub fn verbose(&self) -> bool { self.opts.debugging_opts.verbose }
|
||||||
pub fn time_passes(&self) -> bool { self.opts.debugging_opts.time_passes }
|
pub fn time_passes(&self) -> bool { self.opts.debugging_opts.time_passes }
|
||||||
|
@ -414,10 +376,15 @@ pub fn build_session(sopts: config::Options,
|
||||||
.map(|&(_, ref level)| *level != lint::Allow)
|
.map(|&(_, ref level)| *level != lint::Allow)
|
||||||
.last()
|
.last()
|
||||||
.unwrap_or(true);
|
.unwrap_or(true);
|
||||||
|
let treat_err_as_bug = sopts.treat_err_as_bug;
|
||||||
|
|
||||||
let codemap = Rc::new(codemap::CodeMap::new());
|
let codemap = Rc::new(codemap::CodeMap::new());
|
||||||
let diagnostic_handler =
|
let diagnostic_handler =
|
||||||
errors::Handler::new(sopts.color, Some(registry), can_print_warnings, codemap.clone());
|
errors::Handler::new(sopts.color,
|
||||||
|
Some(registry),
|
||||||
|
can_print_warnings,
|
||||||
|
treat_err_as_bug,
|
||||||
|
codemap.clone());
|
||||||
|
|
||||||
build_session_(sopts, local_crate_source_file, diagnostic_handler, codemap, cstore)
|
build_session_(sopts, local_crate_source_file, diagnostic_handler, codemap, cstore)
|
||||||
}
|
}
|
||||||
|
@ -450,13 +417,6 @@ pub fn build_session_(sopts: config::Options,
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
let can_print_warnings = sopts.lint_opts
|
|
||||||
.iter()
|
|
||||||
.filter(|&&(ref key, _)| *key == "warnings")
|
|
||||||
.map(|&(_, ref level)| *level != lint::Allow)
|
|
||||||
.last()
|
|
||||||
.unwrap_or(true);
|
|
||||||
|
|
||||||
let sess = Session {
|
let sess = Session {
|
||||||
target: target_cfg,
|
target: target_cfg,
|
||||||
host: host,
|
host: host,
|
||||||
|
@ -477,10 +437,8 @@ pub fn build_session_(sopts: config::Options,
|
||||||
crate_types: RefCell::new(Vec::new()),
|
crate_types: RefCell::new(Vec::new()),
|
||||||
dependency_formats: RefCell::new(FnvHashMap()),
|
dependency_formats: RefCell::new(FnvHashMap()),
|
||||||
crate_metadata: RefCell::new(Vec::new()),
|
crate_metadata: RefCell::new(Vec::new()),
|
||||||
delayed_span_bug: RefCell::new(None),
|
|
||||||
features: RefCell::new(feature_gate::Features::new()),
|
features: RefCell::new(feature_gate::Features::new()),
|
||||||
recursion_limit: Cell::new(64),
|
recursion_limit: Cell::new(64),
|
||||||
can_print_warnings: can_print_warnings,
|
|
||||||
next_node_id: Cell::new(1),
|
next_node_id: Cell::new(1),
|
||||||
injected_allocator: Cell::new(None),
|
injected_allocator: Cell::new(None),
|
||||||
available_macros: RefCell::new(HashSet::new()),
|
available_macros: RefCell::new(HashSet::new()),
|
||||||
|
@ -489,13 +447,6 @@ pub fn build_session_(sopts: config::Options,
|
||||||
sess
|
sess
|
||||||
}
|
}
|
||||||
|
|
||||||
// Seems out of place, but it uses session, so I'm putting it here
|
|
||||||
pub fn expect<T, M>(sess: &Session, opt: Option<T>, msg: M) -> T where
|
|
||||||
M: FnOnce() -> String,
|
|
||||||
{
|
|
||||||
errors::expect(sess.diagnostic(), opt, msg)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn early_error(color: errors::ColorConfig, msg: &str) -> ! {
|
pub fn early_error(color: errors::ColorConfig, msg: &str) -> ! {
|
||||||
let mut emitter = BasicEmitter::stderr(color);
|
let mut emitter = BasicEmitter::stderr(color);
|
||||||
emitter.emit(None, msg, None, errors::Level::Fatal);
|
emitter.emit(None, msg, None, errors::Level::Fatal);
|
||||||
|
|
|
@ -862,7 +862,7 @@ fn run_work_multithreaded(sess: &Session,
|
||||||
futures.push(rx);
|
futures.push(rx);
|
||||||
|
|
||||||
thread::Builder::new().name(format!("codegen-{}", i)).spawn(move || {
|
thread::Builder::new().name(format!("codegen-{}", i)).spawn(move || {
|
||||||
let diag_handler = Handler::with_emitter(true, box diag_emitter);
|
let diag_handler = Handler::with_emitter(true, false, box diag_emitter);
|
||||||
|
|
||||||
// Must construct cgcx inside the proc because it has non-Send
|
// Must construct cgcx inside the proc because it has non-Send
|
||||||
// fields.
|
// fields.
|
||||||
|
|
|
@ -20,7 +20,6 @@ pub use self::CallArgs::*;
|
||||||
|
|
||||||
use arena::TypedArena;
|
use arena::TypedArena;
|
||||||
use back::link;
|
use back::link;
|
||||||
use session;
|
|
||||||
use llvm::{self, ValueRef, get_params};
|
use llvm::{self, ValueRef, get_params};
|
||||||
use middle::cstore::LOCAL_CRATE;
|
use middle::cstore::LOCAL_CRATE;
|
||||||
use middle::def;
|
use middle::def;
|
||||||
|
@ -57,6 +56,7 @@ use rustc_front::hir;
|
||||||
|
|
||||||
use syntax::abi as synabi;
|
use syntax::abi as synabi;
|
||||||
use syntax::ast;
|
use syntax::ast;
|
||||||
|
use syntax::errors;
|
||||||
use syntax::ptr::P;
|
use syntax::ptr::P;
|
||||||
|
|
||||||
#[derive(Copy, Clone)]
|
#[derive(Copy, Clone)]
|
||||||
|
@ -412,8 +412,8 @@ pub fn trans_fn_ref_with_substs<'a, 'tcx>(
|
||||||
Some(n) => n,
|
Some(n) => n,
|
||||||
None => { return false; }
|
None => { return false; }
|
||||||
};
|
};
|
||||||
let map_node = session::expect(
|
let map_node = errors::expect(
|
||||||
&tcx.sess,
|
&tcx.sess.diagnostic(),
|
||||||
tcx.map.find(node_id),
|
tcx.map.find(node_id),
|
||||||
|| "local item should be in ast map".to_string());
|
|| "local item should be in ast map".to_string());
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,6 @@
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
use back::link::exported_name;
|
use back::link::exported_name;
|
||||||
use session;
|
|
||||||
use llvm::ValueRef;
|
use llvm::ValueRef;
|
||||||
use llvm;
|
use llvm;
|
||||||
use middle::def_id::DefId;
|
use middle::def_id::DefId;
|
||||||
|
@ -32,6 +31,7 @@ use rustc_front::hir;
|
||||||
use syntax::abi;
|
use syntax::abi;
|
||||||
use syntax::ast;
|
use syntax::ast;
|
||||||
use syntax::attr;
|
use syntax::attr;
|
||||||
|
use syntax::errors;
|
||||||
use std::hash::{Hasher, Hash, SipHasher};
|
use std::hash::{Hasher, Hash, SipHasher};
|
||||||
|
|
||||||
pub fn monomorphic_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
|
pub fn monomorphic_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
|
||||||
|
@ -83,8 +83,8 @@ pub fn monomorphic_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
|
||||||
hash_id);
|
hash_id);
|
||||||
|
|
||||||
|
|
||||||
let map_node = session::expect(
|
let map_node = errors::expect(
|
||||||
ccx.sess(),
|
ccx.sess().diagnostic(),
|
||||||
ccx.tcx().map.find(fn_node_id),
|
ccx.tcx().map.find(fn_node_id),
|
||||||
|| {
|
|| {
|
||||||
format!("while monomorphizing {:?}, couldn't find it in \
|
format!("while monomorphizing {:?}, couldn't find it in \
|
||||||
|
|
|
@ -49,7 +49,7 @@ pub struct ParseSess {
|
||||||
impl ParseSess {
|
impl ParseSess {
|
||||||
pub fn new() -> ParseSess {
|
pub fn new() -> ParseSess {
|
||||||
let cm = Rc::new(CodeMap::new());
|
let cm = Rc::new(CodeMap::new());
|
||||||
let handler = Handler::new(ColorConfig::Auto, None, true, cm.clone());
|
let handler = Handler::new(ColorConfig::Auto, None, true, false, cm.clone());
|
||||||
ParseSess::with_span_handler(handler, cm)
|
ParseSess::with_span_handler(handler, cm)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue