]> git.lizzy.rs Git - rust.git/commitdiff
Compiletest should parse suggestions from the spans
authorOliver Schneider <git-spam-no-reply9815368754983@oli-obk.de>
Wed, 25 Oct 2017 06:33:02 +0000 (08:33 +0200)
committerOliver Schneider <git-spam-no-reply9815368754983@oli-obk.de>
Wed, 25 Oct 2017 06:33:02 +0000 (08:33 +0200)
src/test/compile-fail/issue-27842.rs
src/tools/compiletest/src/json.rs

index 8c71761df2fb8f21819f4a7c3fd3629dd068c289..eb28e36dc076e540783104ff4123cca59012e9da 100644 (file)
@@ -14,7 +14,7 @@ fn main() {
     let _ = tup[0];
     //~^ ERROR cannot index into a value of type
     //~| HELP to access tuple elements, use
-    //~| SUGGESTION let _ = tup.0
+    //~| SUGGESTION tup.0
 
     // the case where we show just a general hint
     let i = 0_usize;
index 77ee93c30078b3b0d8908dfadc46c813cb67b40f..8e9cd1a12faacf79d96fa2f1bb6b909cf3e9d7f6 100644 (file)
@@ -36,6 +36,7 @@ struct DiagnosticSpan {
     column_end: usize,
     is_primary: bool,
     label: Option<String>,
+    suggested_replacement: Option<String>,
     expansion: Option<Box<DiagnosticSpanMacroExpansion>>,
 }
 
@@ -164,15 +165,15 @@ fn push_expected_errors(expected_errors: &mut Vec<Error>,
     }
 
     // If the message has a suggestion, register that.
-    if let Some(ref rendered) = diagnostic.rendered {
-        let start_line = primary_spans.iter().map(|s| s.line_start).min().expect("\
-            every suggestion should have at least one span");
-        for (index, line) in rendered.lines().enumerate() {
-            expected_errors.push(Error {
-                line_num: start_line + index,
-                kind: Some(ErrorKind::Suggestion),
-                msg: line.to_string(),
-            });
+    for span in primary_spans {
+        if let Some(ref suggested_replacement) = span.suggested_replacement {
+            for (index, line) in suggested_replacement.lines().enumerate() {
+                expected_errors.push(Error {
+                    line_num: span.line_start + index,
+                    kind: Some(ErrorKind::Suggestion),
+                    msg: line.to_string(),
+                });
+            }
         }
     }