]> git.lizzy.rs Git - rust.git/commitdiff
Simplify source_string and block-format methods
authorPhilipp Hansch <dev@phansch.net>
Mon, 3 Jun 2019 05:38:19 +0000 (07:38 +0200)
committerPhilipp Hansch <dev@phansch.net>
Tue, 4 Jun 2019 16:46:00 +0000 (18:46 +0200)
src/librustc_errors/annotate_rs_emitter.rs

index a5699035deac8c0de9243abb92db44ae3d6b17f8..f3c55ae79f7927ba8631a9fdfb2f9e9c1a483468 100644 (file)
@@ -138,13 +138,11 @@ fn annotation_to_source_annotation(
     }
 
     /// 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`
@@ -184,13 +182,14 @@ pub fn ui_testing(mut self, ui_testing: bool) -> Self {
         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(),