1
Fork 0

Compiletest should parse suggestions from the spans

This commit is contained in:
Oliver Schneider 2017-10-25 08:33:02 +02:00
parent 7bb05dbdef
commit 014100df49
No known key found for this signature in database
GPG key ID: A69F8D225B3AD7D9
2 changed files with 11 additions and 10 deletions

View 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;

View 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(),
});
}
}
}