This approach avoids double panic caused by unwrap. First panic is
caused by unwrap of Result with Err, second one by destructor of
DiagnosticBuilder stored in Err - it requires that diagnostic is either
emitted or cancelled.
To give one example where this is useful, consider '|' used incorrectly instead
of '/'. Previously this would cause following error:
error: internal compiler error: Error constructed but not emitted
thread panicked while panicking. aborting.
After introduced changes, this results in more useful error message:
src/main.rs:138:7: 138:8 error: expected ident, found `|`
src/main.rs:138 | LPAREN ty RPAREN > ty
^~
error: aborting due to previous error
Error message itself is not necessarily perfect, but at least it is possible to
locate the error.
Thank you for improving the quality of the error messages (including fixing several typos). Your changes are clean and easy to read so I'm going to merge this pull-request and upgrade the Cargo package now.
Return fatal parsing errors using Result.
This approach avoids double panic caused by unwrap. First panic is caused by unwrap of Result with Err, second one by destructor of DiagnosticBuilder stored in Err - it requires that diagnostic is either emitted or cancelled.
To give one example where this is useful, consider '|' used incorrectly instead of '/'. Previously this would cause following error:
After introduced changes, this results in more useful error message:
Error message itself is not necessarily perfect, but at least it is possible to locate the error.