about summary refs log tree commit diff
diff options
context:
space:
mode:
authorOliver Schneider <git-spam-no-reply9815368754983@oli-obk.de>2017-10-25 08:33:02 +0200
committerOliver Schneider <git-spam-no-reply9815368754983@oli-obk.de>2017-10-25 08:33:02 +0200
commit014100df49a9f6926a52ecd4576b99e11a42033b (patch)
treedfdb882cd92b57a0bc2e8777b93f40a6edcd7d67
parent7bb05dbdef8a37dfa6b62d06a257fa9611564c84 (diff)
downloadrust-014100df49a9f6926a52ecd4576b99e11a42033b.tar.gz
rust-014100df49a9f6926a52ecd4576b99e11a42033b.zip
Compiletest should parse suggestions from the spans
-rw-r--r--src/test/compile-fail/issue-27842.rs2
-rw-r--r--src/tools/compiletest/src/json.rs19
2 files changed, 11 insertions, 10 deletions
diff --git a/src/test/compile-fail/issue-27842.rs b/src/test/compile-fail/issue-27842.rs
index 8c71761df2f..eb28e36dc07 100644
--- a/src/test/compile-fail/issue-27842.rs
+++ b/src/test/compile-fail/issue-27842.rs
@@ -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;
diff --git a/src/tools/compiletest/src/json.rs b/src/tools/compiletest/src/json.rs
index 77ee93c3007..8e9cd1a12fa 100644
--- a/src/tools/compiletest/src/json.rs
+++ b/src/tools/compiletest/src/json.rs
@@ -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(),
+                });
+            }
         }
     }