Skip to content

Commit cb498cc

Browse files
committed
auto merge of #12627 : alexcrichton/rust/issue-12623, r=brson
This helps prevent the unfortunate interleavings found in #12623.
2 parents 567201e + 0e1a860 commit cb498cc

File tree

8 files changed

+155
-116
lines changed

8 files changed

+155
-116
lines changed

src/librustc/driver/driver.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -930,7 +930,7 @@ pub fn build_session(sopts: @session::Options,
930930
-> Session {
931931
let codemap = @codemap::CodeMap::new();
932932
let diagnostic_handler =
933-
diagnostic::mk_handler();
933+
diagnostic::default_handler();
934934
let span_diagnostic_handler =
935935
diagnostic::mk_span_handler(diagnostic_handler, codemap);
936936

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

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

src/librustc/lib.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,8 @@ pub fn monitor(f: proc()) {
384384
Err(value) => {
385385
// Task failed without emitting a fatal diagnostic
386386
if !value.is::<diagnostic::FatalError>() {
387-
diagnostic::DefaultEmitter.emit(
387+
let mut emitter = diagnostic::EmitterWriter::stderr();
388+
emitter.emit(
388389
None,
389390
diagnostic::ice_msg("unexpected failure"),
390391
diagnostic::Error);
@@ -394,9 +395,7 @@ pub fn monitor(f: proc()) {
394395
this is a bug",
395396
];
396397
for note in xs.iter() {
397-
diagnostic::DefaultEmitter.emit(None,
398-
*note,
399-
diagnostic::Note)
398+
emitter.emit(None, *note, diagnostic::Note)
400399
}
401400

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

src/librustdoc/core.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ fn get_ast_and_resolve(cpath: &Path,
5858
};
5959

6060

61-
let diagnostic_handler = syntax::diagnostic::mk_handler();
61+
let diagnostic_handler = syntax::diagnostic::default_handler();
6262
let span_diagnostic_handler =
6363
syntax::diagnostic::mk_span_handler(diagnostic_handler, parsesess.cm);
6464

src/librustdoc/html/highlight.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use t = syntax::parse::token;
2828
/// Highlights some source code, returning the HTML output.
2929
pub fn highlight(src: &str) -> ~str {
3030
let sess = parse::new_parse_sess();
31-
let handler = diagnostic::mk_handler();
31+
let handler = diagnostic::default_handler();
3232
let span_handler = diagnostic::mk_span_handler(handler, sess.cm);
3333
let fm = parse::string_to_filemap(sess, src.to_owned(), ~"<stdin>");
3434

src/librustdoc/test.rs

+31-4
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 diagnostic_handler = diagnostic::mk_handler();
52+
let cm = @CodeMap::new();
53+
let diagnostic_handler = diagnostic::default_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),
@@ -112,7 +115,30 @@ fn runtest(test: &str, cratename: &str, libs: HashSet<Path>, should_fail: bool)
112115
.. (*session::basic_options()).clone()
113116
};
114117

115-
let diagnostic_handler = diagnostic::mk_handler();
118+
// Shuffle around a few input and output handles here. We're going to pass
119+
// an explicit handle into rustc to collect output messages, but we also
120+
// want to catch the error message that rustc prints when it fails.
121+
//
122+
// We take our task-local stderr (likely set by the test runner), and move
123+
// it into another task. This helper task then acts as a sink for both the
124+
// stderr of this task and stderr of rustc itself, copying all the info onto
125+
// the stderr channel we originally started with.
126+
//
127+
// The basic idea is to not use a default_handler() for rustc, and then also
128+
// not print things by default to the actual stderr.
129+
let (p, c) = Chan::new();
130+
let w1 = io::ChanWriter::new(c);
131+
let w2 = w1.clone();
132+
let old = io::stdio::set_stderr(~w1);
133+
spawn(proc() {
134+
let mut p = io::PortReader::new(p);
135+
let mut err = old.unwrap_or(~io::stderr() as ~Writer);
136+
io::util::copy(&mut p, &mut err).unwrap();
137+
});
138+
let emitter = diagnostic::EmitterWriter::new(~w2);
139+
140+
// Compile the code
141+
let diagnostic_handler = diagnostic::mk_handler(~emitter);
116142
let span_diagnostic_handler =
117143
diagnostic::mk_span_handler(diagnostic_handler, parsesess.cm);
118144

@@ -126,6 +152,7 @@ fn runtest(test: &str, cratename: &str, libs: HashSet<Path>, should_fail: bool)
126152
let cfg = driver::build_configuration(sess);
127153
driver::compile_input(sess, cfg, &input, &out, &None);
128154

155+
// Run the code!
129156
let exe = outdir.path().join("rust_out");
130157
let out = Process::output(exe.as_str().unwrap(), []);
131158
match out {

0 commit comments

Comments
 (0)