Skip to content

Commit a1c7ebe

Browse files
committed
auto merge of #12874 : huonw/rust/printier-rustc, r=alexcrichton
rustc: make stack traces print for .span_bug/.bug. Previously a call to either of those to diagnostic printers would defer to the `fatal` equivalents, which explicitly silence the stderr printing, including a stack trace from `RUST_LOG=std::rt::backtrace`. This splits the bug printers out to their own diagnostic type so that things work properly. Also, this removes the `Ok(...)` that was being printed around the subtask's stderr output.
2 parents d367482 + edb6b02 commit a1c7ebe

File tree

2 files changed

+32
-17
lines changed

2 files changed

+32
-17
lines changed

src/librustc/lib.rs

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,9 @@ pub mod lib {
134134
pub mod llvmdeps;
135135
}
136136

137+
static BUG_REPORT_URL: &'static str =
138+
"http://static.rust-lang.org/doc/master/complement-bugreport.html";
139+
137140
pub fn version(argv0: &str) {
138141
let vers = match option_env!("CFG_VERSION") {
139142
Some(vers) => vers,
@@ -393,20 +396,31 @@ pub fn monitor(f: proc()) {
393396
// Task failed without emitting a fatal diagnostic
394397
if !value.is::<diagnostic::FatalError>() {
395398
let mut emitter = diagnostic::EmitterWriter::stderr();
396-
emitter.emit(
397-
None,
398-
diagnostic::ice_msg("unexpected failure"),
399-
diagnostic::Error);
399+
400+
// a .span_bug or .bug call has already printed what
401+
// it wants to print.
402+
if !value.is::<diagnostic::ExplicitBug>() {
403+
emitter.emit(
404+
None,
405+
"unexpected failure",
406+
diagnostic::Bug);
407+
}
400408

401409
let xs = [
402-
~"the compiler hit an unexpected failure path. \
403-
this is a bug",
410+
~"the compiler hit an unexpected failure path. this is a bug.",
411+
"we would appreciate a bug report: " + BUG_REPORT_URL,
412+
~"run with `RUST_LOG=std::rt::backtrace` for a backtrace",
404413
];
405414
for note in xs.iter() {
406415
emitter.emit(None, *note, diagnostic::Note)
407416
}
408417

409-
println!("{}", r.read_to_str());
418+
match r.read_to_str() {
419+
Ok(s) => println!("{}", s),
420+
Err(e) => emitter.emit(None,
421+
format!("failed to read internal stderr: {}", e),
422+
diagnostic::Error),
423+
}
410424
}
411425

412426
// Fail so the process returns a failure code, but don't pollute the

src/libsyntax/diagnostic.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ use std::io;
1717
use std::iter::range;
1818
use term;
1919

20-
static BUG_REPORT_URL: &'static str =
21-
"http://static.rust-lang.org/doc/master/complement-bugreport.html";
2220
// maximum number of lines we will print for each error; arbitrary.
2321
static MAX_LINES: uint = 6u;
2422

@@ -34,6 +32,10 @@ pub trait Emitter {
3432
/// how a rustc task died (if so desired).
3533
pub struct FatalError;
3634

35+
/// Signifies that the compiler died with an explicit call to `.bug`
36+
/// or `.span_bug` rather than a failed assertion, etc.
37+
pub struct ExplicitBug;
38+
3739
// a span-handler is like a handler but also
3840
// accepts span information for source-location
3941
// reporting.
@@ -61,7 +63,8 @@ impl SpanHandler {
6163
self.handler.custom_emit(&*self.cm, sp, msg, Note);
6264
}
6365
pub fn span_bug(&self, sp: Span, msg: &str) -> ! {
64-
self.span_fatal(sp, ice_msg(msg));
66+
self.handler.emit(Some((&*self.cm, sp)), msg, Bug);
67+
fail!(ExplicitBug);
6568
}
6669
pub fn span_unimpl(&self, sp: Span, msg: &str) -> ! {
6770
self.span_bug(sp, ~"unimplemented " + msg);
@@ -116,7 +119,8 @@ impl Handler {
116119
self.emit.borrow_mut().get().emit(None, msg, Note);
117120
}
118121
pub fn bug(&self, msg: &str) -> ! {
119-
self.fatal(ice_msg(msg));
122+
self.emit.borrow_mut().get().emit(None, msg, Bug);
123+
fail!(ExplicitBug);
120124
}
121125
pub fn unimpl(&self, msg: &str) -> ! {
122126
self.bug(~"unimplemented " + msg);
@@ -133,11 +137,6 @@ impl Handler {
133137
}
134138
}
135139
136-
pub fn ice_msg(msg: &str) -> ~str {
137-
format!("internal compiler error: {}\nThis message reflects a bug in the Rust compiler. \
138-
\nWe would appreciate a bug report: {}", msg, BUG_REPORT_URL)
139-
}
140-
141140
pub fn mk_span_handler(handler: @Handler, cm: @codemap::CodeMap)
142141
-> @SpanHandler {
143142
@SpanHandler {
@@ -159,6 +158,7 @@ pub fn mk_handler(e: ~Emitter) -> @Handler {
159158
160159
#[deriving(Eq)]
161160
pub enum Level {
161+
Bug,
162162
Fatal,
163163
Error,
164164
Warning,
@@ -170,6 +170,7 @@ impl fmt::Show for Level {
170170
use std::fmt::Show;
171171
172172
match *self {
173+
Bug => "error: internal compiler error".fmt(f),
173174
Fatal | Error => "error".fmt(f),
174175
Warning => "warning".fmt(f),
175176
Note => "note".fmt(f),
@@ -180,7 +181,7 @@ impl fmt::Show for Level {
180181
impl Level {
181182
fn color(self) -> term::color::Color {
182183
match self {
183-
Fatal | Error => term::color::BRIGHT_RED,
184+
Bug | Fatal | Error => term::color::BRIGHT_RED,
184185
Warning => term::color::BRIGHT_YELLOW,
185186
Note => term::color::BRIGHT_GREEN
186187
}

0 commit comments

Comments
 (0)