]> git.lizzy.rs Git - rust.git/commit
Guard against overflow in `codemap::span_to_lines`.
authorFelix S. Klock II <pnkfelix@pnkfx.org>
Thu, 30 Apr 2015 08:23:50 +0000 (10:23 +0200)
committerFelix S. Klock II <pnkfelix@pnkfx.org>
Tue, 5 May 2015 10:51:09 +0000 (12:51 +0200)
commit939e4c9ea9e63b4da1033d66a72a044279036e6f
tree167acffb65c6cf5ce3111cf1234453a744bf03e6
parent42cb2de1393b067f1078f0c8b55322620e6058ef
Guard against overflow in `codemap::span_to_lines`.

Make `span_to_lines` to return a `Result`.
(This is better than just asserting internally, since it allows caller
to decide if they can recover from the problem.)

Added type alias for `FileLinesResult` returned by `span_to_lines`.

Update embedded unit test to reflect `span_to_lines` signature change.

In diagnostic, catch `Err` from `span_to_lines` and print
`"(internal compiler error: unprintable span)"` instead.

----

There a number of recent issues that report the bug here.  See
e.g. #24761 and #24954.

This change *might* fix them. However, that is not its main goal.
The main goals are:

 1. Make it possible for callers to recover from an error here, and

 2. Insert a more conservative check, in that we are
    also checking that the files match up.
src/libsyntax/codemap.rs
src/libsyntax/diagnostic.rs