From ae1e73affed86261c25d78a83559ece534bbde21 Mon Sep 17 00:00:00 2001 From: Jonathan Turner Date: Mon, 16 May 2016 08:50:01 -0400 Subject: [PATCH] Print secondary labels as notes in old skool mode --- src/libsyntax/errors/emitter.rs | 3 +++ src/libsyntax/errors/snippet/mod.rs | 23 +++++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/src/libsyntax/errors/emitter.rs b/src/libsyntax/errors/emitter.rs index e7007fb0568..d797c6541e3 100644 --- a/src/libsyntax/errors/emitter.rs +++ b/src/libsyntax/errors/emitter.rs @@ -524,6 +524,9 @@ impl Destination { } Style::Quotation => { } + Style::OldSkoolNote => { + 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/snippet/mod.rs b/src/libsyntax/errors/snippet/mod.rs index 092effbb2f6..3b7e2f30706 100644 --- a/src/libsyntax/errors/snippet/mod.rs +++ b/src/libsyntax/errors/snippet/mod.rs @@ -90,6 +90,7 @@ pub enum Style { UnderlineSecondary, LabelPrimary, LabelSecondary, + OldSkoolNote, NoStyle, } @@ -497,6 +498,28 @@ impl FileInfo { match self.primary_span { Some(span) => { let lo = codemap.lookup_char_pos(span.lo); + //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), + style: Style::LineAndColumn, + }, StyledString { + text: format!("note: "), + style: Style::LabelSecondary, + }, StyledString { + text: format!("{}", ann), + style: Style::OldSkoolNote, + }], + kind: RenderedLineKind::Annotations, + }); + } + } rendered_lines[0].text.insert(0, StyledString { text: format!(":{} ", lo.line), style: Style::LineAndColumn,