Skip to content

Commit a478811

Browse files
committed
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.
1 parent 6309b0f commit a478811

File tree

5 files changed

+19
-68
lines changed

5 files changed

+19
-68
lines changed

src/librustc/session/mod.rs

+11-60
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,10 @@ pub struct Session {
6464
pub crate_metadata: RefCell<Vec<String>>,
6565
pub features: RefCell<feature_gate::Features>,
6666

67-
pub delayed_span_bug: RefCell<Option<(codemap::Span, String)>>,
68-
6967
/// The maximum recursion limit for potentially infinitely recursive
7068
/// operations such as auto-dereference and monomorphization.
7169
pub recursion_limit: Cell<usize>,
7270

73-
pub can_print_warnings: bool,
74-
7571
/// The metadata::creader module may inject an allocator dependency if it
7672
/// didn't already find one, and this tracks what was injected.
7773
pub injected_allocator: Cell<Option<ast::CrateNum>>,
@@ -85,21 +81,12 @@ pub struct Session {
8581

8682
impl Session {
8783
pub fn span_fatal(&self, sp: Span, msg: &str) -> ! {
88-
if self.opts.treat_err_as_bug {
89-
self.span_bug(sp, msg);
90-
}
9184
panic!(self.diagnostic().span_fatal(sp, msg))
9285
}
9386
pub fn span_fatal_with_code(&self, sp: Span, msg: &str, code: &str) -> ! {
94-
if self.opts.treat_err_as_bug {
95-
self.span_bug(sp, msg);
96-
}
9787
panic!(self.diagnostic().span_fatal_with_code(sp, msg, code))
9888
}
9989
pub fn fatal(&self, msg: &str) -> ! {
100-
if self.opts.treat_err_as_bug {
101-
self.bug(msg);
102-
}
10390
panic!(self.diagnostic().fatal(msg))
10491
}
10592
pub fn span_err_or_warn(&self, is_warning: bool, sp: Span, msg: &str) {
@@ -110,9 +97,6 @@ impl Session {
11097
}
11198
}
11299
pub fn span_err(&self, sp: Span, msg: &str) {
113-
if self.opts.treat_err_as_bug {
114-
self.span_bug(sp, msg);
115-
}
116100
match split_msg_into_multilines(msg) {
117101
Some(msg) => self.diagnostic().span_err(sp, &msg[..]),
118102
None => self.diagnostic().span_err(sp, msg)
@@ -126,18 +110,12 @@ impl Session {
126110
See RFC 1214 for details."));
127111
}
128112
pub fn span_err_with_code(&self, sp: Span, msg: &str, code: &str) {
129-
if self.opts.treat_err_as_bug {
130-
self.span_bug(sp, msg);
131-
}
132113
match split_msg_into_multilines(msg) {
133114
Some(msg) => self.diagnostic().span_err_with_code(sp, &msg[..], code),
134115
None => self.diagnostic().span_err_with_code(sp, msg, code)
135116
}
136117
}
137118
pub fn err(&self, msg: &str) {
138-
if self.opts.treat_err_as_bug {
139-
self.bug(msg);
140-
}
141119
self.diagnostic().err(msg)
142120
}
143121
pub fn err_count(&self) -> usize {
@@ -148,14 +126,6 @@ impl Session {
148126
}
149127
pub fn abort_if_errors(&self) {
150128
self.diagnostic().abort_if_errors();
151-
152-
let delayed_bug = self.delayed_span_bug.borrow();
153-
match *delayed_bug {
154-
Some((span, ref errmsg)) => {
155-
self.diagnostic().span_bug(span, errmsg);
156-
},
157-
_ => {}
158-
}
159129
}
160130
pub fn abort_if_new_errors<F>(&self, mut f: F)
161131
where F: FnMut()
@@ -167,19 +137,13 @@ impl Session {
167137
}
168138
}
169139
pub fn span_warn(&self, sp: Span, msg: &str) {
170-
if self.can_print_warnings {
171-
self.diagnostic().span_warn(sp, msg)
172-
}
140+
self.diagnostic().span_warn(sp, msg)
173141
}
174142
pub fn span_warn_with_code(&self, sp: Span, msg: &str, code: &str) {
175-
if self.can_print_warnings {
176-
self.diagnostic().span_warn_with_code(sp, msg, code)
177-
}
143+
self.diagnostic().span_warn_with_code(sp, msg, code)
178144
}
179145
pub fn warn(&self, msg: &str) {
180-
if self.can_print_warnings {
181-
self.diagnostic().warn(msg)
182-
}
146+
self.diagnostic().warn(msg)
183147
}
184148
pub fn opt_span_warn(&self, opt_sp: Option<Span>, msg: &str) {
185149
match opt_sp {
@@ -223,8 +187,7 @@ impl Session {
223187
}
224188
/// Delay a span_bug() call until abort_if_errors()
225189
pub fn delay_span_bug(&self, sp: Span, msg: &str) {
226-
let mut delayed = self.delayed_span_bug.borrow_mut();
227-
*delayed = Some((sp, msg.to_string()));
190+
self.diagnostic().delay_span_bug(sp, msg)
228191
}
229192
pub fn span_bug(&self, sp: Span, msg: &str) -> ! {
230193
self.diagnostic().span_bug(sp, msg)
@@ -270,8 +233,7 @@ impl Session {
270233
// This exists to help with refactoring to eliminate impossible
271234
// cases later on
272235
pub fn impossible_case(&self, sp: Span, msg: &str) -> ! {
273-
self.span_bug(sp,
274-
&format!("impossible case reached: {}", msg));
236+
self.span_bug(sp, &format!("impossible case reached: {}", msg));
275237
}
276238
pub fn verbose(&self) -> bool { self.opts.debugging_opts.verbose }
277239
pub fn time_passes(&self) -> bool { self.opts.debugging_opts.time_passes }
@@ -414,10 +376,15 @@ pub fn build_session(sopts: config::Options,
414376
.map(|&(_, ref level)| *level != lint::Allow)
415377
.last()
416378
.unwrap_or(true);
379+
let treat_err_as_bug = sopts.treat_err_as_bug;
417380

418381
let codemap = Rc::new(codemap::CodeMap::new());
419382
let diagnostic_handler =
420-
errors::Handler::new(sopts.color, Some(registry), can_print_warnings, codemap.clone());
383+
errors::Handler::new(sopts.color,
384+
Some(registry),
385+
can_print_warnings,
386+
treat_err_as_bug,
387+
codemap.clone());
421388

422389
build_session_(sopts, local_crate_source_file, diagnostic_handler, codemap, cstore)
423390
}
@@ -450,13 +417,6 @@ pub fn build_session_(sopts: config::Options,
450417
}
451418
);
452419

453-
let can_print_warnings = sopts.lint_opts
454-
.iter()
455-
.filter(|&&(ref key, _)| *key == "warnings")
456-
.map(|&(_, ref level)| *level != lint::Allow)
457-
.last()
458-
.unwrap_or(true);
459-
460420
let sess = Session {
461421
target: target_cfg,
462422
host: host,
@@ -477,10 +437,8 @@ pub fn build_session_(sopts: config::Options,
477437
crate_types: RefCell::new(Vec::new()),
478438
dependency_formats: RefCell::new(FnvHashMap()),
479439
crate_metadata: RefCell::new(Vec::new()),
480-
delayed_span_bug: RefCell::new(None),
481440
features: RefCell::new(feature_gate::Features::new()),
482441
recursion_limit: Cell::new(64),
483-
can_print_warnings: can_print_warnings,
484442
next_node_id: Cell::new(1),
485443
injected_allocator: Cell::new(None),
486444
available_macros: RefCell::new(HashSet::new()),
@@ -489,13 +447,6 @@ pub fn build_session_(sopts: config::Options,
489447
sess
490448
}
491449

492-
// Seems out of place, but it uses session, so I'm putting it here
493-
pub fn expect<T, M>(sess: &Session, opt: Option<T>, msg: M) -> T where
494-
M: FnOnce() -> String,
495-
{
496-
errors::expect(sess.diagnostic(), opt, msg)
497-
}
498-
499450
pub fn early_error(color: errors::ColorConfig, msg: &str) -> ! {
500451
let mut emitter = BasicEmitter::stderr(color);
501452
emitter.emit(None, msg, None, errors::Level::Fatal);

src/librustc_trans/back/write.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -862,7 +862,7 @@ fn run_work_multithreaded(sess: &Session,
862862
futures.push(rx);
863863

864864
thread::Builder::new().name(format!("codegen-{}", i)).spawn(move || {
865-
let diag_handler = Handler::with_emitter(true, box diag_emitter);
865+
let diag_handler = Handler::with_emitter(true, false, box diag_emitter);
866866

867867
// Must construct cgcx inside the proc because it has non-Send
868868
// fields.

src/librustc_trans/trans/callee.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ pub use self::CallArgs::*;
2020

2121
use arena::TypedArena;
2222
use back::link;
23-
use session;
2423
use llvm::{self, ValueRef, get_params};
2524
use middle::cstore::LOCAL_CRATE;
2625
use middle::def;
@@ -57,6 +56,7 @@ use rustc_front::hir;
5756

5857
use syntax::abi as synabi;
5958
use syntax::ast;
59+
use syntax::errors;
6060
use syntax::ptr::P;
6161

6262
#[derive(Copy, Clone)]
@@ -412,8 +412,8 @@ pub fn trans_fn_ref_with_substs<'a, 'tcx>(
412412
Some(n) => n,
413413
None => { return false; }
414414
};
415-
let map_node = session::expect(
416-
&tcx.sess,
415+
let map_node = errors::expect(
416+
&tcx.sess.diagnostic(),
417417
tcx.map.find(node_id),
418418
|| "local item should be in ast map".to_string());
419419

src/librustc_trans/trans/monomorphize.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
// except according to those terms.
1010

1111
use back::link::exported_name;
12-
use session;
1312
use llvm::ValueRef;
1413
use llvm;
1514
use middle::def_id::DefId;
@@ -32,6 +31,7 @@ use rustc_front::hir;
3231
use syntax::abi;
3332
use syntax::ast;
3433
use syntax::attr;
34+
use syntax::errors;
3535
use std::hash::{Hasher, Hash, SipHasher};
3636

3737
pub fn monomorphic_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
@@ -83,8 +83,8 @@ pub fn monomorphic_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
8383
hash_id);
8484

8585

86-
let map_node = session::expect(
87-
ccx.sess(),
86+
let map_node = errors::expect(
87+
ccx.sess().diagnostic(),
8888
ccx.tcx().map.find(fn_node_id),
8989
|| {
9090
format!("while monomorphizing {:?}, couldn't find it in \

src/libsyntax/parse/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ pub struct ParseSess {
4949
impl ParseSess {
5050
pub fn new() -> ParseSess {
5151
let cm = Rc::new(CodeMap::new());
52-
let handler = Handler::new(ColorConfig::Auto, None, true, cm.clone());
52+
let handler = Handler::new(ColorConfig::Auto, None, true, false, cm.clone());
5353
ParseSess::with_span_handler(handler, cm)
5454
}
5555

0 commit comments

Comments
 (0)