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

Long line printing doesn't support tabs #78438

Closed
est31 opened this issue Oct 27, 2020 · 2 comments · Fixed by #79757
Closed

Long line printing doesn't support tabs #78438

est31 opened this issue Oct 27, 2020 · 2 comments · Fixed by #79757
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@est31
Copy link
Member

est31 commented Oct 27, 2020

The code that truncates long lines doesn't take (hard) tabs into account, so the lines printed are off.

Example code:

								fn main() {
									let money = 42i32;
									match money {
										v @ 1 | 2 | 3 => panic!("You gave me too little money {}", v), // Long text here: TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT
										v => println!("Enough money {}", v),
									}
								}

Gives the following error:

error[E0408]: variable `v` is not bound in all patterns
 --> src/main.rs:4:19
  |
4 | ...            v @ 1 | 2 | 3 => panic!("You gave me too little money {}", v), // Long text here: TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT...
  |                                     -       ^   ^ pattern doesn't bind `v`
  |                                     |       |
  |                                     |       pattern doesn't bind `v`
  |                                     variable not in all patterns

error: aborting due to previous error

If you use four spaces instead of each tab

                                fn main() {
                                    let money = 42i32;
                                    match money {
                                        v @ 1 | 2 | 3 => panic!("You gave me too little money {}", v), // Long text here: TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT
                                        v => println!("Enough money {}", v),
                                    }
                                }

it works as expected:

error[E0408]: variable `v` is not bound in all patterns
 --> src/main.rs:4:49
  |
4 | ...   v @ 1 | 2 | 3 => panic!("You gave me too little money {}", v), // Long text here: TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT...
  |       -       ^   ^ pattern doesn't bind `v`
  |       |       |
  |       |       pattern doesn't bind `v`
  |       variable not in all patterns

cc #45953 and #63402

cc @estebank

@est31 est31 added the C-bug Category: This is a bug. label Oct 27, 2020
@jonas-schievink jonas-schievink added the A-diagnostics Area: Messages for errors, warnings, and lints label Oct 27, 2020
@estebank estebank added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Oct 27, 2020
@estebank
Copy link
Contributor

I thought we were already accounting for tabs, but looking we rely on unicode-width which considers '\t' to not have a width, which we then assume to be 1.

@estebank estebank assigned estebank and unassigned estebank Oct 27, 2020
@jryans
Copy link
Contributor

jryans commented Dec 1, 2020

@rustbot claim

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants