Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replicate clang's formatting for tabs in error message printing #44618

Closed
est31 opened this issue Sep 15, 2017 · 0 comments
Closed

Replicate clang's formatting for tabs in error message printing #44618

est31 opened this issue Sep 15, 2017 · 0 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one. WG-diagnostics Working group: Diagnostics

Comments

@est31
Copy link
Member

est31 commented Sep 15, 2017

This is a follow-up of #38384 which was fixed by my PR #44386. The basic question: how to handle tabs in error messages? E.g. you want to underline something with ^ or you show markers like __^. The problem is that you don't know which tab width the viewer has (whether its a terminal or an online tool like travis or a text editor if you've stored the output into a file and now opened it), so you might end up producing misaligned output if you just copy the tabs.

The strategy chosen before my PR was trying to replicate tabs in the line below, but it still misaligned when the underlined stuff has tabs of its own, and it also didn't really work in other cases.

Now my PR has fixed the misalignment by implementing GCC's (very simple) fix to the problem, replacing each tab with one space in the code printed. But the output is still not beautiful. A better strategy is the one clang uses, which emulates a tabstop algorithm by filling in spaces in place of tabs, with a tabstop existing at all 4 spaces.

I've opened this issue to remember that adopting clang's strategy might be something worth pursuing for rustc.

@Mark-Simulacrum Mark-Simulacrum added A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one. labels Sep 18, 2017
bors added a commit that referenced this issue Dec 6, 2017
Display `\t` in diagnostics code as four spaces

Follow up to #44386 using the unicode variable width machinery from #45711 to replace tabs in the source code when displaying a diagnostic error with four spaces (instead of only one), while properly accounting for this when calculating underlines.

Partly addresses #44618.
@estebank estebank added the WG-diagnostics Working group: Diagnostics label Dec 6, 2017
@est31 est31 closed this as completed Oct 19, 2018
@rust-lang rust-lang locked and limited conversation to collaborators Oct 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one. WG-diagnostics Working group: Diagnostics
Projects
None yet
Development

No branches or pull requests

3 participants