Print error lines and highlight error span #660
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This isn't necessarily a request to pull, but more a request for feedback. This branch gives output like:
../src/test/compile-fail/forgot-ret.rs:8:19:12:1: note: In function f, not all control paths return a value ../src/test/compile-fail/forgot-ret.rs:8 fn f(int a) -> int { ../src/test/compile-fail/forgot-ret.rs:9 if (god_exists(a)) { ../src/test/compile-fail/forgot-ret.rs:10 ret 5; ...
../src/test/compile-fail/for-loop-decl.rs:13:40:13:44: error: mismatched types: expected @tup(uint,tup(uint,uint)) but found @tup(uint,var_info) (types differ) ../src/test/compile-fail/for-loop-decl.rs:13 for each (@tup(uint, tup(uint, uint)) p in enclosing.vars.items()) { ^~~~
The ^~~~ extends for the full width of the error span, so it's easier to see when spans are larger than they should be as well.
The downside here is that I took the easy route for obtaining the file contents and just read in the entire file on demand whenever we print an error. I fully acknowledge that that's an awful thing to do, but I was having trouble figuring out a better way to acquire the file contents from the lexer from all the different possible places we could be throwing errors.