diff options
Diffstat (limited to 'src/librustc_errors')
| -rw-r--r-- | src/librustc_errors/diagnostic.rs | 7 | ||||
| -rw-r--r-- | src/librustc_errors/emitter.rs | 65 | ||||
| -rw-r--r-- | src/librustc_errors/lib.rs | 14 |
3 files changed, 26 insertions, 60 deletions
diff --git a/src/librustc_errors/diagnostic.rs b/src/librustc_errors/diagnostic.rs index c7e9c8268f0..221c75186e9 100644 --- a/src/librustc_errors/diagnostic.rs +++ b/src/librustc_errors/diagnostic.rs @@ -12,7 +12,6 @@ use CodeSuggestion; use SubstitutionPart; use Substitution; use Level; -use RenderSpan; use std::fmt; use syntax_pos::{MultiSpan, Span}; use snippet::Style; @@ -40,7 +39,7 @@ pub struct SubDiagnostic { pub level: Level, pub message: Vec<(String, Style)>, pub span: MultiSpan, - pub render_span: Option<RenderSpan>, + pub render_span: Option<MultiSpan>, } #[derive(PartialEq, Eq)] @@ -307,7 +306,7 @@ impl Diagnostic { level: Level, message: &str, span: MultiSpan, - render_span: Option<RenderSpan>) { + render_span: Option<MultiSpan>) { let sub = SubDiagnostic { level, message: vec![(message.to_owned(), Style::NoStyle)], @@ -323,7 +322,7 @@ impl Diagnostic { level: Level, message: Vec<(String, Style)>, span: MultiSpan, - render_span: Option<RenderSpan>) { + render_span: Option<MultiSpan>) { let sub = SubDiagnostic { level, message, diff --git a/src/librustc_errors/emitter.rs b/src/librustc_errors/emitter.rs index 0e39f29204d..57523d2c058 100644 --- a/src/librustc_errors/emitter.rs +++ b/src/librustc_errors/emitter.rs @@ -13,7 +13,6 @@ use self::Destination::*; use syntax_pos::{DUMMY_SP, FileMap, Span, MultiSpan}; use {Level, CodeSuggestion, DiagnosticBuilder, SubDiagnostic, CodeMapper, DiagnosticId}; -use RenderSpan::*; use snippet::{Annotation, AnnotationType, Line, MultilineAnnotation, StyledString, Style}; use styled_buffer::StyledBuffer; @@ -35,6 +34,7 @@ impl Emitter for EmitterWriter { fn emit(&mut self, db: &DiagnosticBuilder) { let mut primary_span = db.span.clone(); let mut children = db.children.clone(); + let mut suggestions: &[_] = &[]; if let Some((sugg, rest)) = db.suggestions.split_first() { if rest.is_empty() && @@ -60,14 +60,7 @@ impl Emitter for EmitterWriter { // to be consistent. We could try to figure out if we can // make one (or the first one) inline, but that would give // undue importance to a semi-random suggestion - for sugg in &db.suggestions { - children.push(SubDiagnostic { - level: Level::Help, - message: Vec::new(), - span: MultiSpan::new(), - render_span: Some(Suggestion(sugg.clone())), - }); - } + suggestions = &db.suggestions; } } @@ -76,7 +69,8 @@ impl Emitter for EmitterWriter { &db.styled_message(), &db.code, &primary_span, - &children); + &children, + &suggestions); } } @@ -1179,7 +1173,8 @@ impl EmitterWriter { message: &Vec<(String, Style)>, code: &Option<DiagnosticId>, span: &MultiSpan, - children: &Vec<SubDiagnostic>) { + children: &Vec<SubDiagnostic>, + suggestions: &[CodeSuggestion]) { let max_line_num = self.get_max_line_num(span, children); let max_line_num_len = max_line_num.to_string().len(); @@ -1198,37 +1193,23 @@ impl EmitterWriter { } if !self.short_message { for child in children { - match child.render_span { - Some(FullSpan(ref msp)) => { - match self.emit_message_default(msp, - &child.styled_message(), - &None, - &child.level, - max_line_num_len, - true) { - Err(e) => panic!("failed to emit error: {}", e), - _ => () - } - } - Some(Suggestion(ref cs)) => { - match self.emit_suggestion_default(cs, - &child.level, - max_line_num_len) { - Err(e) => panic!("failed to emit error: {}", e), - _ => () - } - } - None => { - match self.emit_message_default(&child.span, - &child.styled_message(), - &None, - &child.level, - max_line_num_len, - true) { - Err(e) => panic!("failed to emit error: {}", e), - _ => (), - } - } + let span = child.render_span.as_ref().unwrap_or(&child.span); + match self.emit_message_default(&span, + &child.styled_message(), + &None, + &child.level, + max_line_num_len, + true) { + Err(e) => panic!("failed to emit error: {}", e), + _ => () + } + } + for sugg in suggestions { + match self.emit_suggestion_default(sugg, + &Level::Help, + max_line_num_len) { + Err(e) => panic!("failed to emit error: {}", e), + _ => () } } } diff --git a/src/librustc_errors/lib.rs b/src/librustc_errors/lib.rs index 7bf64d24325..e83ac8831de 100644 --- a/src/librustc_errors/lib.rs +++ b/src/librustc_errors/lib.rs @@ -53,20 +53,6 @@ mod lock; use syntax_pos::{BytePos, Loc, FileLinesResult, FileMap, FileName, MultiSpan, Span, NO_EXPANSION}; #[derive(Clone, Debug, PartialEq, Hash, RustcEncodable, RustcDecodable)] -pub enum RenderSpan { - /// A FullSpan renders with both with an initial line for the - /// message, prefixed by file:linenum, followed by a summary of - /// the source code covered by the span. - FullSpan(MultiSpan), - - /// A suggestion renders with both with an initial line for the - /// message, prefixed by file:linenum, followed by a summary - /// of hypothetical source code, where each `String` is spliced - /// into the lines in place of the code covered by each span. - Suggestion(CodeSuggestion), -} - -#[derive(Clone, Debug, PartialEq, Hash, RustcEncodable, RustcDecodable)] pub struct CodeSuggestion { /// Each substitute can have multiple variants due to multiple /// applicable suggestions |
