Skip to content

Commit 3245471

Browse files
committed
syntax: Refactor diagnostics to focus on Writers
This commit alters the diagnostic emission machinery to be focused around a Writer for emitting errors. This allows it to not hard-code emission of errors to stderr (useful for other applications).
1 parent 9b1be3d commit 3245471

File tree

5 files changed

+122
-111
lines changed

5 files changed

+122
-111
lines changed

src/librustc/driver/driver.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -931,7 +931,7 @@ pub fn build_session(sopts: @session::Options,
931931
-> Session {
932932
let codemap = @codemap::CodeMap::new();
933933
let diagnostic_handler =
934-
diagnostic::mk_handler();
934+
diagnostic::default_handler();
935935
let span_diagnostic_handler =
936936
diagnostic::mk_span_handler(diagnostic_handler, codemap);
937937

@@ -1149,7 +1149,8 @@ pub fn build_output_filenames(input: &Input,
11491149
}
11501150

11511151
pub fn early_error(msg: &str) -> ! {
1152-
diagnostic::DefaultEmitter.emit(None, msg, diagnostic::Fatal);
1152+
let mut emitter = diagnostic::EmitterWriter::stderr();
1153+
emitter.emit(None, msg, diagnostic::Fatal);
11531154
fail!(diagnostic::FatalError);
11541155
}
11551156

src/librustc/lib.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,8 @@ pub fn monitor(f: proc()) {
394394
Err(value) => {
395395
// Task failed without emitting a fatal diagnostic
396396
if !value.is::<diagnostic::FatalError>() {
397-
diagnostic::DefaultEmitter.emit(
397+
let mut emitter = diagnostic::EmitterWriter::stderr();
398+
emitter.emit(
398399
None,
399400
diagnostic::ice_msg("unexpected failure"),
400401
diagnostic::Error);
@@ -404,9 +405,7 @@ pub fn monitor(f: proc()) {
404405
this is a bug",
405406
];
406407
for note in xs.iter() {
407-
diagnostic::DefaultEmitter.emit(None,
408-
*note,
409-
diagnostic::Note)
408+
emitter.emit(None, *note, diagnostic::Note)
410409
}
411410

412411
println!("{}", r.read_to_str());

src/librustdoc/test.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ use rustc::metadata::creader::Loader;
2525
use getopts;
2626
use syntax::diagnostic;
2727
use syntax::parse;
28+
use syntax::codemap::CodeMap;
2829

2930
use core;
3031
use clean;
@@ -35,7 +36,6 @@ use passes;
3536
use visit_ast::RustdocVisitor;
3637

3738
pub fn run(input: &str, matches: &getopts::Matches) -> int {
38-
let parsesess = parse::new_parse_sess();
3939
let input_path = Path::new(input);
4040
let input = driver::FileInput(input_path.clone());
4141
let libs = matches.opt_strs("L").map(|s| Path::new(s.as_slice()));
@@ -49,9 +49,12 @@ pub fn run(input: &str, matches: &getopts::Matches) -> int {
4949
};
5050

5151

52+
let cm = @CodeMap::new();
5253
let diagnostic_handler = diagnostic::mk_handler();
5354
let span_diagnostic_handler =
54-
diagnostic::mk_span_handler(diagnostic_handler, parsesess.cm);
55+
diagnostic::mk_span_handler(diagnostic_handler, cm);
56+
let parsesess = parse::new_parse_sess_special_handler(span_diagnostic_handler,
57+
cm);
5558

5659
let sess = driver::build_session_(sessopts,
5760
Some(input_path),

0 commit comments

Comments
 (0)