Add dump-syntax fallback error message

This commit is contained in:
David Tolnay 2019-03-02 00:34:44 -08:00
parent c2ddaaf1c0
commit 2e7bd2581c
No known key found for this signature in database
GPG Key ID: F9BA143B95FF6D82

View File

@ -91,12 +91,12 @@ fn render_location(
let mut end = err.span().end();
if start.line == end.line && start.column == end.column {
return Ok(());
return render_fallback(formatter, err);
}
let code_line = match code.lines().nth(start.line - 1) {
Some(line) => line,
None => return Ok(()),
None => return render_fallback(formatter, err),
};
if end.line > start.line {
@ -128,3 +128,7 @@ fn render_location(
message = err,
)
}
fn render_fallback(formatter: &mut fmt::Formatter, err: &syn::Error) -> fmt::Result {
write!(formatter, "Unable to parse file: {}", err)
}