Skip to content

Commit a86c8d0

Browse files
committed
---
yaml --- r: 110156 b: refs/heads/auto c: 1599d22 h: refs/heads/master v: v3
1 parent 3945c90 commit a86c8d0

File tree

3 files changed

+46
-9
lines changed

3 files changed

+46
-9
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ refs/heads/try3: 9387340aab40a73e8424c48fd42f0c521a4875c0
1313
refs/tags/release-0.3.1: 495bae036dfe5ec6ceafd3312b4dca48741e845b
1414
refs/tags/release-0.4: e828ea2080499553b97dfe33b3f4d472b4562ad7
1515
refs/tags/release-0.5: 7e3bcfbf21278251ee936ad53e92e9b719702d73
16-
refs/heads/auto: 3ccbffac40958159c571ee515b85146397c0a35f
16+
refs/heads/auto: 1599d2260347046e6d8841493ffc64cc876fda07
1717
refs/heads/servo: af82457af293e2a842ba6b7759b70288da276167
1818
refs/tags/release-0.6: b4ebcfa1812664df5e142f0134a5faea3918544c
1919
refs/tags/0.1: b19db808c2793fe2976759b85a355c3ad8c8b336

branches/auto/src/librustc/driver/session.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,9 @@ impl Session {
232232
pub fn span_end_note(&self, sp: Span, msg: &str) {
233233
self.diagnostic().span_end_note(sp, msg)
234234
}
235+
pub fn fileline_note(&self, sp: Span, msg: &str) {
236+
self.diagnostic().fileline_note(sp, msg)
237+
}
235238
pub fn note(&self, msg: &str) {
236239
self.diagnostic().handler().note(msg)
237240
}

branches/auto/src/libsyntax/diagnostic.rs

Lines changed: 42 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,37 @@ use term;
2020
// maximum number of lines we will print for each error; arbitrary.
2121
static MAX_LINES: uint = 6u;
2222

23+
#[deriving(Clone)]
24+
pub enum RenderSpan {
25+
/// A FullSpan renders with both with an initial line for the
26+
/// message, prefixed by file:linenum, followed by a summary of
27+
/// the source code covered by the span.
28+
FullSpan(Span),
29+
30+
/// A FileLine renders with just a line for the message prefixed
31+
/// by file:linenum.
32+
FileLine(Span),
33+
}
34+
35+
impl RenderSpan {
36+
fn span(self) -> Span {
37+
match self {
38+
FullSpan(s) | FileLine(s) => s
39+
}
40+
}
41+
fn is_full_span(&self) -> bool {
42+
match self {
43+
&FullSpan(..) => true,
44+
&FileLine(..) => false,
45+
}
46+
}
47+
}
48+
2349
pub trait Emitter {
2450
fn emit(&mut self, cmsp: Option<(&codemap::CodeMap, Span)>,
2551
msg: &str, lvl: Level);
2652
fn custom_emit(&mut self, cm: &codemap::CodeMap,
27-
sp: Span, msg: &str, lvl: Level);
53+
sp: RenderSpan, msg: &str, lvl: Level);
2854
}
2955

3056
/// This structure is used to signify that a task has failed with a fatal error
@@ -60,7 +86,10 @@ impl SpanHandler {
6086
self.handler.emit(Some((&self.cm, sp)), msg, Note);
6187
}
6288
pub fn span_end_note(&self, sp: Span, msg: &str) {
63-
self.handler.custom_emit(&self.cm, sp, msg, Note);
89+
self.handler.custom_emit(&self.cm, FullSpan(sp), msg, Note);
90+
}
91+
pub fn fileline_note(&self, sp: Span, msg: &str) {
92+
self.handler.custom_emit(&self.cm, FileLine(sp), msg, Note);
6493
}
6594
pub fn span_bug(&self, sp: Span, msg: &str) -> ! {
6695
self.handler.emit(Some((&self.cm, sp)), msg, Bug);
@@ -132,7 +161,7 @@ impl Handler {
132161
self.emit.borrow_mut().emit(cmsp, msg, lvl);
133162
}
134163
pub fn custom_emit(&self, cm: &codemap::CodeMap,
135-
sp: Span, msg: &str, lvl: Level) {
164+
sp: RenderSpan, msg: &str, lvl: Level) {
136165
self.emit.borrow_mut().custom_emit(cm, sp, msg, lvl);
137166
}
138167
}
@@ -258,7 +287,7 @@ impl Emitter for EmitterWriter {
258287
msg: &str,
259288
lvl: Level) {
260289
let error = match cmsp {
261-
Some((cm, sp)) => emit(self, cm, sp, msg, lvl, false),
290+
Some((cm, sp)) => emit(self, cm, FullSpan(sp), msg, lvl, false),
262291
None => print_diagnostic(self, "", lvl, msg),
263292
};
264293

@@ -269,16 +298,17 @@ impl Emitter for EmitterWriter {
269298
}
270299

271300
fn custom_emit(&mut self, cm: &codemap::CodeMap,
272-
sp: Span, msg: &str, lvl: Level) {
301+
sp: RenderSpan, msg: &str, lvl: Level) {
273302
match emit(self, cm, sp, msg, lvl, true) {
274303
Ok(()) => {}
275304
Err(e) => fail!("failed to print diagnostics: {}", e),
276305
}
277306
}
278307
}
279308

280-
fn emit(dst: &mut EmitterWriter, cm: &codemap::CodeMap, sp: Span,
309+
fn emit(dst: &mut EmitterWriter, cm: &codemap::CodeMap, rsp: RenderSpan,
281310
msg: &str, lvl: Level, custom: bool) -> io::IoResult<()> {
311+
let sp = rsp.span();
282312
let ss = cm.span_to_str(sp);
283313
let lines = cm.span_to_lines(sp);
284314
if custom {
@@ -288,10 +318,14 @@ fn emit(dst: &mut EmitterWriter, cm: &codemap::CodeMap, sp: Span,
288318
let span_end = Span { lo: sp.hi, hi: sp.hi, expn_info: sp.expn_info};
289319
let ses = cm.span_to_str(span_end);
290320
try!(print_diagnostic(dst, ses, lvl, msg));
291-
try!(custom_highlight_lines(dst, cm, sp, lvl, lines));
321+
if rsp.is_full_span() {
322+
try!(custom_highlight_lines(dst, cm, sp, lvl, lines));
323+
}
292324
} else {
293325
try!(print_diagnostic(dst, ss, lvl, msg));
294-
try!(highlight_lines(dst, cm, sp, lvl, lines));
326+
if rsp.is_full_span() {
327+
try!(highlight_lines(dst, cm, sp, lvl, lines));
328+
}
295329
}
296330
print_macro_backtrace(dst, cm, sp)
297331
}

0 commit comments

Comments
 (0)