Skip to content

Commit 99d85b7

Browse files
Jonathan Turnernikomatsakis
Jonathan Turner
authored andcommitted
Finish up with 'old school' error mode
1 parent 935a0d8 commit 99d85b7

File tree

2 files changed

+65
-13
lines changed

2 files changed

+65
-13
lines changed

src/librustc_trans/back/write.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,8 @@ impl CoreEmitter for SharedEmitter {
106106
msg: &str,
107107
code: Option<&str>,
108108
lvl: Level,
109-
_is_header: bool) {
109+
_is_header: bool,
110+
_show_snippet: bool) {
110111
self.buffer.lock().unwrap().push(Diagnostic {
111112
msg: msg.to_string(),
112113
code: code.map(|s| s.to_string()),

src/libsyntax/errors/emitter.rs

Lines changed: 63 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ pub trait CoreEmitter {
4040
msg: &str,
4141
code: Option<&str>,
4242
lvl: Level,
43-
is_header: bool);
43+
is_header: bool,
44+
show_snippet: bool);
4445
}
4546

4647
impl<T: CoreEmitter> Emitter for T {
@@ -53,25 +54,47 @@ impl<T: CoreEmitter> Emitter for T {
5354
msg,
5455
code,
5556
lvl,
57+
true,
5658
true);
5759
}
5860

5961
fn emit_struct(&mut self, db: &DiagnosticBuilder) {
62+
let old_school = match ::std::env::var("RUST_NEW_ERROR_FORMAT") {
63+
Ok(_) => false,
64+
Err(_) => true,
65+
};
66+
let db_span = FullSpan(db.span.clone());
6067
self.emit_message(&FullSpan(db.span.clone()),
6168
&db.message,
6269
db.code.as_ref().map(|s| &**s),
6370
db.level,
71+
true,
6472
true);
6573
for child in &db.children {
6674
let render_span = child.render_span
6775
.clone()
6876
.unwrap_or_else(
6977
|| FullSpan(child.span.clone()));
70-
self.emit_message(&render_span,
71-
&child.message,
72-
None,
73-
child.level,
74-
false);
78+
79+
if !old_school {
80+
self.emit_message(&render_span,
81+
&child.message,
82+
None,
83+
child.level,
84+
false,
85+
true);
86+
} else {
87+
let (render_span, show_snippet) = match render_span.span().primary_span() {
88+
None => (db_span.clone(), false),
89+
_ => (render_span, true)
90+
};
91+
self.emit_message(&render_span,
92+
&child.message,
93+
None,
94+
child.level,
95+
false,
96+
show_snippet);
97+
}
7598
}
7699
}
77100
}
@@ -108,7 +131,8 @@ impl CoreEmitter for BasicEmitter {
108131
msg: &str,
109132
code: Option<&str>,
110133
lvl: Level,
111-
_is_header: bool) {
134+
_is_header: bool,
135+
_show_snippet: bool) {
112136
// we ignore the span as we have no access to a codemap at this point
113137
if let Err(e) = print_diagnostic(&mut self.dst, "", lvl, msg, code) {
114138
panic!("failed to print diagnostics: {:?}", e);
@@ -146,8 +170,9 @@ impl CoreEmitter for EmitterWriter {
146170
msg: &str,
147171
code: Option<&str>,
148172
lvl: Level,
149-
is_header: bool) {
150-
match self.emit_message_(rsp, msg, code, lvl, is_header) {
173+
is_header: bool,
174+
show_snippet: bool) {
175+
match self.emit_message_(rsp, msg, code, lvl, is_header, show_snippet) {
151176
Ok(()) => { }
152177
Err(e) => panic!("failed to emit error: {}", e)
153178
}
@@ -213,7 +238,8 @@ impl EmitterWriter {
213238
msg: &str,
214239
code: Option<&str>,
215240
lvl: Level,
216-
is_header: bool)
241+
is_header: bool,
242+
show_snippet: bool)
217243
-> io::Result<()> {
218244
if is_header {
219245
if self.first {
@@ -243,10 +269,24 @@ impl EmitterWriter {
243269
}
244270
}
245271
_ => {
246-
print_diagnostic(&mut self.dst, "", lvl, msg, code)?
272+
if self.old_school {
273+
let loc = match rsp.span().primary_span() {
274+
Some(COMMAND_LINE_SP) | Some(DUMMY_SP) => "".to_string(),
275+
Some(ps) => self.cm.span_to_string(ps),
276+
None => "".to_string()
277+
};
278+
print_diagnostic(&mut self.dst, &loc, lvl, msg, code)?
279+
}
280+
else {
281+
print_diagnostic(&mut self.dst, "", lvl, msg, code)?
282+
}
247283
}
248284
}
249285

286+
if !show_snippet {
287+
return Ok(());
288+
}
289+
250290
// Watch out for various nasty special spans; don't try to
251291
// print any filename or anything for those.
252292
match rsp.span().primary_span() {
@@ -333,8 +373,10 @@ impl EmitterWriter {
333373
msp.primary_span());
334374
if self.old_school {
335375
let mut output_vec = vec![];
376+
336377
for span_label in msp.span_labels() {
337378
let mut snippet_data = snippet_data.clone();
379+
338380
snippet_data.push(span_label.span,
339381
span_label.is_primary,
340382
span_label.label);
@@ -412,7 +454,16 @@ fn print_diagnostic(dst: &mut Destination,
412454
code: Option<&str>)
413455
-> io::Result<()> {
414456
if !topic.is_empty() {
415-
write!(dst, "{}: ", topic)?;
457+
let old_school = match ::std::env::var("RUST_NEW_ERROR_FORMAT") {
458+
Ok(_) => false,
459+
Err(_) => true,
460+
};
461+
if !old_school {
462+
write!(dst, "{}: ", topic)?;
463+
}
464+
else {
465+
write!(dst, "{} ", topic)?;
466+
}
416467
dst.reset_attrs()?;
417468
}
418469
dst.start_attr(term::Attr::Bold)?;

0 commit comments

Comments
 (0)