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

Display \t in diagnostics code as four spaces #45953

Merged
merged 1 commit into from
Dec 6, 2017
Merged

Conversation

estebank
Copy link
Contributor

@estebank estebank commented Nov 13, 2017

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
Copy link
Contributor Author

r? @pnkfelix
CC @est31 @tirr-c

@est31
Copy link
Member

est31 commented Nov 13, 2017

@estebank nice PR! It definitely improves the behaviour of rustc regarding tabs :).

However, tab == 4 spaces replacements (what this PR is doing) are not a emulation of what clang is doing. Instead, clang emulates a tabstop algorithm, meaning that a tab character jumps to the next tabstop. Tabstops are being placed at all 4 spaces. The basic algorithm is: add 1 space, then add another 0 < n < 3 spaces such that the column number is divisible by 4.

The difference is not observable if you only use tabs at the start of a line and once you have a non tab character you never use them again (which is how I structure all of my own code). You can only see the difference when there is a mix of tabs and spaces.

With the tabs == 4 spaces algorithm, ab\tc and abc\td would become:

a    b
ab    c
abc    d

With the tabstops algorithm that clang is using, the sequences would become:

a   b
ab  c
abc d

As I've said above, it wouldn't make any difference for my own code, but it would maybe make a difference for other users.

@estebank
Copy link
Contributor Author

@est31 I understand. I've changed the description from fixing the bug to merely CCing it.

Supporting the proper tab stop algorithm will require some extra code in order for underlines to be correct as well. I feel that for now this is a good stop gap improvement on your code, even if not entirely correct as you point out.

@est31
Copy link
Member

est31 commented Nov 13, 2017

I feel that for now this is a good stop gap improvement on your code

Definitely! Really like this PR :)

@kennytm kennytm added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Nov 13, 2017
@shepmaster
Copy link
Member

Ping from triage, @pnkfelix — will you have time to look at this soon?

@bors
Copy link
Contributor

bors commented Nov 24, 2017

☔ The latest upstream changes (presumably #46116) made this pull request unmergeable. Please resolve the merge conflicts.

@kennytm
Copy link
Member

kennytm commented Nov 29, 2017

Triage ping — @pnkfelix could you take a look at this PR? Thanks!

cc @rust-lang/compiler

@estebank
Copy link
Contributor Author

r? @arielb1

@rust-highfive rust-highfive assigned arielb1 and unassigned pnkfelix Nov 29, 2017
@kennytm
Copy link
Member

kennytm commented Dec 6, 2017

Triage ping — @arielb1 could you take a look at this PR? Thanks!

@arielb1
Copy link
Contributor

arielb1 commented Dec 6, 2017

I don't know this code. r? @nikomatsakis

@rust-highfive rust-highfive assigned nikomatsakis and unassigned arielb1 Dec 6, 2017
tab_pos.push(pos);
}
}
// start with the tabs at the end of the line to replace them with 4 space chars
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Am I missing something...? Why is it useful/important to go in reverse? (Doesn't seem harmful, but also not imp't.)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh, I see, duh. Otherwise the indices are invalid.

Copy link
Contributor

@nikomatsakis nikomatsakis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. r=me.

@nikomatsakis
Copy link
Contributor

@bors r+

@bors
Copy link
Contributor

bors commented Dec 6, 2017

📌 Commit 9d80e22 has been approved by nikomatsakis

@kennytm kennytm added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Dec 6, 2017
@bors
Copy link
Contributor

bors commented Dec 6, 2017

⌛ Testing commit 9d80e22 with merge 5a2465e...

bors added a commit that referenced this pull request 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.
@bors
Copy link
Contributor

bors commented Dec 6, 2017

☀️ Test successful - status-appveyor, status-travis
Approved by: nikomatsakis
Pushing 5a2465e to master...

@bors bors merged commit 9d80e22 into rust-lang:master Dec 6, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants