]> git.lizzy.rs Git - rust.git/commit
Fix mispositioned error indicators
authorest31 <MTest31@outlook.com>
Thu, 7 Sep 2017 06:47:13 +0000 (08:47 +0200)
committerest31 <MTest31@outlook.com>
Thu, 7 Sep 2017 08:26:27 +0000 (10:26 +0200)
commitd58281097a3bf14fe1b199c8ba6aee00793e111e
tree71d6084a9f3e870110a6d5da0359c46927767b52
parent05e3c96d36b5281e969b5e79b92d671c7872bf83
Fix mispositioned error indicators

Fixes #38384

Most of the Rust community uses 4 spaces for indentation,
but there are also tab users of Rust (including myself!).

This patch fixes a bug in error printing which mispositions
error indicators when near code with tabs.

The code attempted to fix the issue by replacing spaces
with tabs, but it sadly wasn't enough, as sometimes
you may not print spaces but _ or ^ instead.

This patch employs the reverse strategy: it replaces each
tab with a space, so that the number of _ and ^ and spaces
in error indicators below the code snippet line up
perfectly.

In a study [1] preceeding this patch, we could see that
this strategy is also chosen by gcc version 6.3.0.

Its not perfect, as the output is not beautiful, but its
the easiest to implement. If anyone wants to improve on
this, be my guest! This patch is meant as improvement of
the status quo, not as perfect end status. It fixes the
actual issue of mispositioning error indicators.

[1]: https://github.com/rust-lang/rust/issues/38384#issuecomment-326813710
src/librustc_errors/styled_buffer.rs
src/test/ui/codemap_tests/tab.rs
src/test/ui/codemap_tests/tab.stderr
src/test/ui/codemap_tests/tab_2.rs [new file with mode: 0644]
src/test/ui/codemap_tests/tab_2.stderr [new file with mode: 0644]
src/test/ui/codemap_tests/tab_3.rs [new file with mode: 0644]
src/test/ui/codemap_tests/tab_3.stderr [new file with mode: 0644]