Skip to content

Display \t in diagnostics code as four spaces - #45953

Merged
bors merged 1 commit into
rust-lang:masterfrom
estebank:tab-4
Dec 6, 2017
Merged

Display \t in diagnostics code as four spaces#45953
bors merged 1 commit into
rust-lang:masterfrom
estebank:tab-4

Conversation

@estebank

@estebankestebank commented Nov 13, 2017

Copy link
Copy Markdown
Contributor

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
Copy Markdown
ContributorAuthor

r? @pnkfelix
CC @est31@tirr-c

@est31

Copy link
Copy Markdown
Member

@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
Copy Markdown
ContributorAuthor

@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
Copy Markdown
Member

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

Definitely! Really like this PR :)

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

Copy link
Copy Markdown
Member

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

@bors

bors commented Nov 24, 2017

Copy link
Copy Markdown
Collaborator

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

@kennytm

Copy link
Copy Markdown
Member

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

cc @rust-lang/compiler

@estebank

Copy link
Copy Markdown
ContributorAuthor

r? @arielb1

@kennytm

Copy link
Copy Markdown
Member

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

@arielb1

Copy link
Copy Markdown
Contributor

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

tab_pos.push(pos);
}
}
// start with the tabs at the end of the line to replace them with 4 space chars

Copy link
Copy Markdown
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
Copy Markdown
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.

@nikomatsakisnikomatsakis left a comment

Copy link
Copy Markdown
Contributor

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
Copy Markdown
Contributor

@bors r+

@bors

bors commented Dec 6, 2017

Copy link
Copy Markdown
Collaborator

📌 Commit 9d80e22 has been approved by nikomatsakis

@kennytmkennytm 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

bors commented Dec 6, 2017

Copy link
Copy Markdown
Collaborator

⌛ 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

bors commented Dec 6, 2017

Copy link
Copy Markdown
Collaborator

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

@bors
bors merged commit 9d80e22 into rust-lang:masterDec 6, 2017
@estebank
estebank deleted the tab-4 branch November 9, 2023 05:25
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-borsStatus: 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

@estebank@est31@shepmaster@bors@kennytm@arielb1@nikomatsakis@pnkfelix