Skip to content

Commit 3e9747a

Browse files
author
Jonathan Turner
committed
De-emph minimized spans, add better debugging output
1 parent ae1e73a commit 3e9747a

File tree

4 files changed

+37
-17
lines changed

4 files changed

+37
-17
lines changed

src/libsyntax/errors/emitter.rs

+4
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,10 @@ impl Destination {
526526
}
527527
Style::OldSkoolNote => {
528528
self.start_attr(term::Attr::Bold)?;
529+
self.start_attr(term::Attr::ForegroundColor(term::color::BRIGHT_GREEN))?;
530+
}
531+
Style::OldSkoolNoteText => {
532+
self.start_attr(term::Attr::Bold)?;
529533
}
530534
Style::UnderlinePrimary | Style::LabelPrimary => {
531535
self.start_attr(term::Attr::Bold)?;

src/libsyntax/errors/snippet/mod.rs

+23-10
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ struct Annotation {
5858
/// Is this annotation derived from primary span
5959
is_primary: bool,
6060

61+
/// Is this a large span minimized down to a smaller span
62+
is_minimized: bool,
63+
6164
/// Optional label to display adjacent to the annotation.
6265
label: Option<String>,
6366
}
@@ -90,6 +93,7 @@ pub enum Style {
9093
UnderlineSecondary,
9194
LabelPrimary,
9295
LabelSecondary,
96+
OldSkoolNoteText,
9397
OldSkoolNote,
9498
NoStyle,
9599
}
@@ -383,10 +387,10 @@ impl FileInfo {
383387
// Basically, although this loses information, multi-line spans just
384388
// never look good.
385389

386-
let (line, start_col, mut end_col) = if lines.len() == 1 {
387-
(lines[0].line_index, lines[0].start_col, lines[0].end_col)
390+
let (line, start_col, mut end_col, is_minimized) = if lines.len() == 1 {
391+
(lines[0].line_index, lines[0].start_col, lines[0].end_col, false)
388392
} else {
389-
(lines[0].line_index, lines[0].start_col, CharPos(lines[0].start_col.0 + 1))
393+
(lines[0].line_index, lines[0].start_col, CharPos(lines[0].start_col.0 + 1), true)
390394
};
391395

392396
// Watch out for "empty spans". If we get a span like 6..6, we
@@ -402,6 +406,7 @@ impl FileInfo {
402406
self.lines[index].push_annotation(start_col,
403407
end_col,
404408
is_primary,
409+
is_minimized,
405410
label);
406411
}
407412

@@ -498,6 +503,7 @@ impl FileInfo {
498503
match self.primary_span {
499504
Some(span) => {
500505
let lo = codemap.lookup_char_pos(span.lo);
506+
let hi = codemap.lookup_char_pos(span.hi);
501507
//Before each secondary line in old skool-mode, print the label
502508
//as an old-style note
503509
if !line.annotations[0].is_primary {
@@ -507,14 +513,15 @@ impl FileInfo {
507513
text: lo.file.name.clone(),
508514
style: Style::FileNameStyle,
509515
}, StyledString {
510-
text: format!(":{}:{}: ", lo.line, lo.col.0 + 1),
516+
text: format!(":{}:{}: {}:{} ", lo.line, lo.col.0 + 1,
517+
hi.line, hi.col.0+1),
511518
style: Style::LineAndColumn,
512519
}, StyledString {
513520
text: format!("note: "),
514-
style: Style::LabelSecondary,
521+
style: Style::OldSkoolNote,
515522
}, StyledString {
516523
text: format!("{}", ann),
517-
style: Style::OldSkoolNote,
524+
style: Style::OldSkoolNoteText,
518525
}],
519526
kind: RenderedLineKind::Annotations,
520527
});
@@ -621,15 +628,15 @@ impl FileInfo {
621628
if annotation.is_primary {
622629
Style::UnderlinePrimary
623630
} else {
624-
Style::UnderlineSecondary
631+
Style::OldSkoolNote
625632
});
626633
}
627634
else {
628635
styled_buffer.putc(1, p, '~',
629636
if annotation.is_primary {
630637
Style::UnderlinePrimary
631638
} else {
632-
Style::UnderlineSecondary
639+
Style::OldSkoolNote
633640
});
634641
}
635642
}
@@ -638,10 +645,14 @@ impl FileInfo {
638645
for p in annotation.start_col .. annotation.end_col {
639646
if annotation.is_primary {
640647
styled_buffer.putc(1, p, '^', Style::UnderlinePrimary);
641-
styled_buffer.set_style(0, p, Style::UnderlinePrimary);
648+
if !annotation.is_minimized {
649+
styled_buffer.set_style(0, p, Style::UnderlinePrimary);
650+
}
642651
} else {
643652
styled_buffer.putc(1, p, '-', Style::UnderlineSecondary);
644-
styled_buffer.set_style(0, p, Style::UnderlineSecondary);
653+
if !annotation.is_minimized {
654+
styled_buffer.set_style(0, p, Style::UnderlineSecondary);
655+
}
645656
}
646657
}
647658
}
@@ -842,11 +853,13 @@ impl Line {
842853
start: CharPos,
843854
end: CharPos,
844855
is_primary: bool,
856+
is_minimized: bool,
845857
label: Option<String>) {
846858
self.annotations.push(Annotation {
847859
start_col: start.0,
848860
end_col: end.0,
849861
is_primary: is_primary,
862+
is_minimized: is_minimized,
850863
label: label,
851864
});
852865
}

src/tools/compiletest/src/json.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use errors::{Error, ErrorKind};
1212
use rustc_serialize::json;
1313
use std::str::FromStr;
1414
use std::path::Path;
15+
use runtest::{fatal_proc_rec, ProcRes};
1516

1617
// These structs are a subset of the ones found in
1718
// `syntax::errors::json`.
@@ -55,13 +56,13 @@ struct DiagnosticCode {
5556
explanation: Option<String>,
5657
}
5758

58-
pub fn parse_output(file_name: &str, output: &str) -> Vec<Error> {
59+
pub fn parse_output(file_name: &str, output: &str, proc_res: &ProcRes) -> Vec<Error> {
5960
output.lines()
60-
.flat_map(|line| parse_line(file_name, line))
61+
.flat_map(|line| parse_line(file_name, line, output, proc_res))
6162
.collect()
6263
}
6364

64-
fn parse_line(file_name: &str, line: &str) -> Vec<Error> {
65+
fn parse_line(file_name: &str, line: &str, output: &str, proc_res: &ProcRes) -> Vec<Error> {
6566
// The compiler sometimes intermingles non-JSON stuff into the
6667
// output. This hack just skips over such lines. Yuck.
6768
if line.chars().next() == Some('{') {
@@ -72,7 +73,9 @@ fn parse_line(file_name: &str, line: &str) -> Vec<Error> {
7273
expected_errors
7374
}
7475
Err(error) => {
75-
panic!("failed to decode compiler output as json: `{}`", error);
76+
fatal_proc_rec(None, &format!(
77+
"failed to decode compiler output as json: `{}`\noutput: {}\nline: {}",
78+
error, line, output), proc_res);
7679
}
7780
}
7881
} else {

src/tools/compiletest/src/runtest.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1001,7 +1001,7 @@ actual:\n\
10011001
let expect_note = expected_errors.iter().any(|ee| ee.kind == Some(ErrorKind::Note));
10021002

10031003
// Parse the JSON output from the compiler and extract out the messages.
1004-
let actual_errors = json::parse_output(&file_name, &proc_res.stderr);
1004+
let actual_errors = json::parse_output(&file_name, &proc_res.stderr, &proc_res);
10051005
let mut unexpected = 0;
10061006
let mut not_found = 0;
10071007
let mut found = vec![false; expected_errors.len()];
@@ -1528,7 +1528,7 @@ actual:\n\
15281528
self.error(err); panic!();
15291529
}
15301530

1531-
fn fatal_proc_rec(&self, err: &str, proc_res: &ProcRes) -> ! {
1531+
pub fn fatal_proc_rec(&self, err: &str, proc_res: &ProcRes) -> ! {
15321532
self.error(err);
15331533
print!("\
15341534
status: {}\n\
@@ -2197,7 +2197,7 @@ struct ProcArgs {
21972197
args: Vec<String>,
21982198
}
21992199

2200-
struct ProcRes {
2200+
pub struct ProcRes {
22012201
status: Status,
22022202
stdout: String,
22032203
stderr: String,

0 commit comments

Comments
 (0)