diff options
| author | bors <bors@rust-lang.org> | 2016-05-18 21:19:07 -0700 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2016-05-18 21:19:07 -0700 |
| commit | 0c5d651d0bb9e0471795bd743c8ecfd8f9a89844 (patch) | |
| tree | 21cd95b19248dbff4d36634c6922fcb40463e765 /src/libsyntax/errors | |
| parent | 9c6904ca1e4ab95f6c48973dea718326735ad564 (diff) | |
| parent | b0a317dc6f8f9ecc973645f2d00f304f96eaf8b8 (diff) | |
| download | rust-0c5d651d0bb9e0471795bd743c8ecfd8f9a89844.tar.gz rust-0c5d651d0bb9e0471795bd743c8ecfd8f9a89844.zip | |
Auto merge of #33688 - jonathandturner:fix_old_school, r=nikomatsakis
Fix for old school error issues, improvements to new school This PR: * Fixes some old school error issues, specifically #33559, #33543, #33366 * Improves wording borrowck errors with match patterns * De-emphasize multi-line spans, so we don't color the single source character when we're trying to say "span starts here" * Rollup of #33392 (which should help fix #33390) r? @nikomatsakis
Diffstat (limited to 'src/libsyntax/errors')
| -rw-r--r-- | src/libsyntax/errors/emitter.rs | 10 | ||||
| -rw-r--r-- | src/libsyntax/errors/mod.rs | 4 | ||||
| -rw-r--r-- | src/libsyntax/errors/snippet/mod.rs | 50 |
3 files changed, 54 insertions, 10 deletions
diff --git a/src/libsyntax/errors/emitter.rs b/src/libsyntax/errors/emitter.rs index e7007fb0568..8d0c93f21b2 100644 --- a/src/libsyntax/errors/emitter.rs +++ b/src/libsyntax/errors/emitter.rs @@ -367,7 +367,8 @@ impl EmitterWriter { let mut output_vec = vec![]; for span_label in msp.span_labels() { - let mut snippet_data = snippet_data.clone(); + let mut snippet_data = SnippetData::new(self.cm.clone(), + Some(span_label.span)); snippet_data.push(span_label.span, span_label.is_primary, @@ -524,6 +525,13 @@ impl Destination { } Style::Quotation => { } + Style::OldSkoolNote => { + self.start_attr(term::Attr::Bold)?; + self.start_attr(term::Attr::ForegroundColor(term::color::BRIGHT_GREEN))?; + } + Style::OldSkoolNoteText => { + self.start_attr(term::Attr::Bold)?; + } Style::UnderlinePrimary | Style::LabelPrimary => { self.start_attr(term::Attr::Bold)?; self.start_attr(term::Attr::ForegroundColor(lvl.color()))?; diff --git a/src/libsyntax/errors/mod.rs b/src/libsyntax/errors/mod.rs index 2ca61ba76d4..f06672fe111 100644 --- a/src/libsyntax/errors/mod.rs +++ b/src/libsyntax/errors/mod.rs @@ -699,13 +699,13 @@ pub fn expect<T, M>(diag: &Handler, opt: Option<T>, msg: M) -> T where /// /// FIXME(#33240) #[cfg(not(test))] -fn check_old_skool() -> bool { +pub fn check_old_skool() -> bool { use std::env; env::var("RUST_NEW_ERROR_FORMAT").is_err() } /// For unit tests, use the new format. #[cfg(test)] -fn check_old_skool() -> bool { +pub fn check_old_skool() -> bool { false } diff --git a/src/libsyntax/errors/snippet/mod.rs b/src/libsyntax/errors/snippet/mod.rs index 092effbb2f6..188e676e7df 100644 --- a/src/libsyntax/errors/snippet/mod.rs +++ b/src/libsyntax/errors/snippet/mod.rs @@ -58,6 +58,9 @@ struct Annotation { /// Is this annotation derived from primary span is_primary: bool, + /// Is this a large span minimized down to a smaller span + is_minimized: bool, + /// Optional label to display adjacent to the annotation. label: Option<String>, } @@ -90,6 +93,8 @@ pub enum Style { UnderlineSecondary, LabelPrimary, LabelSecondary, + OldSkoolNoteText, + OldSkoolNote, NoStyle, } @@ -382,10 +387,10 @@ impl FileInfo { // Basically, although this loses information, multi-line spans just // never look good. - let (line, start_col, mut end_col) = if lines.len() == 1 { - (lines[0].line_index, lines[0].start_col, lines[0].end_col) + let (line, start_col, mut end_col, is_minimized) = if lines.len() == 1 { + (lines[0].line_index, lines[0].start_col, lines[0].end_col, false) } else { - (lines[0].line_index, lines[0].start_col, CharPos(lines[0].start_col.0 + 1)) + (lines[0].line_index, lines[0].start_col, CharPos(lines[0].start_col.0 + 1), true) }; // Watch out for "empty spans". If we get a span like 6..6, we @@ -401,6 +406,7 @@ impl FileInfo { self.lines[index].push_annotation(start_col, end_col, is_primary, + is_minimized, label); } @@ -497,6 +503,30 @@ impl FileInfo { match self.primary_span { Some(span) => { let lo = codemap.lookup_char_pos(span.lo); + let hi = codemap.lookup_char_pos(span.hi); + //Before each secondary line in old skool-mode, print the label + //as an old-style note + if !line.annotations[0].is_primary { + if let Some(ann) = line.annotations[0].label.clone() { + output.push(RenderedLine { + text: vec![StyledString { + text: lo.file.name.clone(), + style: Style::FileNameStyle, + }, StyledString { + text: format!(":{}:{}: {}:{} ", lo.line, lo.col.0 + 1, + hi.line, hi.col.0+1), + style: Style::LineAndColumn, + }, StyledString { + text: format!("note: "), + style: Style::OldSkoolNote, + }, StyledString { + text: format!("{}", ann), + style: Style::OldSkoolNoteText, + }], + kind: RenderedLineKind::Annotations, + }); + } + } rendered_lines[0].text.insert(0, StyledString { text: format!(":{} ", lo.line), style: Style::LineAndColumn, @@ -598,7 +628,7 @@ impl FileInfo { if annotation.is_primary { Style::UnderlinePrimary } else { - Style::UnderlineSecondary + Style::OldSkoolNote }); } else { @@ -606,7 +636,7 @@ impl FileInfo { if annotation.is_primary { Style::UnderlinePrimary } else { - Style::UnderlineSecondary + Style::OldSkoolNote }); } } @@ -615,10 +645,14 @@ impl FileInfo { for p in annotation.start_col .. annotation.end_col { if annotation.is_primary { styled_buffer.putc(1, p, '^', Style::UnderlinePrimary); - styled_buffer.set_style(0, p, Style::UnderlinePrimary); + if !annotation.is_minimized { + styled_buffer.set_style(0, p, Style::UnderlinePrimary); + } } else { styled_buffer.putc(1, p, '-', Style::UnderlineSecondary); - styled_buffer.set_style(0, p, Style::UnderlineSecondary); + if !annotation.is_minimized { + styled_buffer.set_style(0, p, Style::UnderlineSecondary); + } } } } @@ -819,11 +853,13 @@ impl Line { start: CharPos, end: CharPos, is_primary: bool, + is_minimized: bool, label: Option<String>) { self.annotations.push(Annotation { start_col: start.0, end_col: end.0, is_primary: is_primary, + is_minimized: is_minimized, label: label, }); } |
