Skip to content

Commit

Permalink
Simplify source_string and block-format methods
Browse files Browse the repository at this point in the history
  • Loading branch information
phansch committed Jun 4, 2019
1 parent 94c8aa6 commit 4a6b91c
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions src/librustc_errors/annotate_rs_emitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,13 +138,11 @@ impl<'a> DiagnosticConverter<'a> {
}

/// Provides the source string for the given `line` of `file`
fn source_string(file: Lrc<SourceFile>,
line: &Line) -> String {
let source_string = match file.get_line(line.line_index - 1) {
Some(s) => s.clone(),
None => return String::new(),
};
source_string.to_string()
fn source_string(
file: Lrc<SourceFile>,
line: &Line
) -> String {
file.get_line(line.line_index - 1).map(|a| a.to_string()).unwrap_or(String::new())
}

/// Maps `Diagnostic::Level` to `snippet::AnnotationType`
Expand Down Expand Up @@ -184,13 +182,14 @@ impl AnnotateRsEmitterWriter {
self
}

fn emit_messages_default(&mut self,
level: &Level,
message: String,
code: &Option<DiagnosticId>,
msp: &MultiSpan,
children: &[SubDiagnostic],
suggestions: &[CodeSuggestion]
fn emit_messages_default(
&mut self,
level: &Level,
message: String,
code: &Option<DiagnosticId>,
msp: &MultiSpan,
children: &[SubDiagnostic],
suggestions: &[CodeSuggestion]
) {
let converter = DiagnosticConverter {
source_map: self.source_map.clone(),
Expand Down

0 comments on commit 4a6b91c

Please sign in to comment.