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

Account for unicode char width when calculating vertical label lines #66552

Closed
estebank opened this issue Nov 19, 2019 · 3 comments · Fixed by #66589
Closed

Account for unicode char width when calculating vertical label lines #66552

estebank opened this issue Nov 19, 2019 · 3 comments · Fixed by #66589
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-Unicode Area: Unicode E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@estebank
Copy link
Contributor

In ui/terminal-width/non-whitespace-trimming-unicode.stderr we account for the visible char width when calculating the label and span positions, but we do not do so for the vertical bar tying them together, causing the following output:

error[E0308]: mismatched types
  --> $DIR/non-whitespace-trimming-unicode.rs:4:415
   |
LL | ...♬♭♮♯♰♱♲♳♴♵♶♷♸♹♺♻♼♽♾♿⚀⚁⚂⚃⚄⚅⚆⚈⚉4"; let _: () = 42;  let _: &str = "🦀☀☁☂☃☄★☆☇☈☉☊☋☌☍☎☏☐☑☒☓  ☖☗☘☙☚☛☜☝☞☟☠☡☢☣☤☥☦☧☨☩☪☫☬☭☮☯☰☱☲☳☴☵☶☷☸☹☺☻☼☽☾☿♀♁♂♃...
   |                                             --   ^^ expected (), found integer
   |                                                      |
   |                                             expected due to this
   |
   = note: expected type `()`
              found type `{integer}`

error: aborting due to previous error

where it should be

error[E0308]: mismatched types
  --> $DIR/non-whitespace-trimming-unicode.rs:4:415
   |
LL | ...♬♭♮♯♰♱♲♳♴♵♶♷♸♹♺♻♼♽♾♿⚀⚁⚂⚃⚄⚅⚆⚈⚉4"; let _: () = 42;  let _: &str = "🦀☀☁☂☃☄★☆☇☈☉☊☋☌☍☎☏☐☑☒☓  ☖☗☘☙☚☛☜☝☞☟☠☡☢☣☤☥☦☧☨☩☪☫☬☭☮☯☰☱☲☳☴☵☶☷☸☹☺☻☼☽☾☿♀♁♂♃...
   |                                             --   ^^ expected (), found integer
   |                                             |
   |                                             expected due to this
   |
   = note: expected type `()`
              found type `{integer}`

error: aborting due to previous error

(Found during #66539)

@estebank estebank added E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. A-diagnostics Area: Messages for errors, warnings, and lints A-Unicode Area: Unicode T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Nov 19, 2019
@TheSamsa
Copy link
Contributor

I would like to solve this as a first time issue. Best with some pointers where to start :)

@estebank
Copy link
Contributor Author

estebank commented Nov 19, 2019

@TheSamsa the code that draws the vertical lines is at

// Write the vertical lines for labels that are on a different line as the underline.
//
// After this we will have:
//
// 2 | fn foo() {
// | __________
// | | |
// | |
// 3 |
// 4 | | }
// | |_
for &(pos, annotation) in &annotations_position {
let style = if annotation.is_primary {
Style::UnderlinePrimary
} else {
Style::UnderlineSecondary
};
let pos = pos + 1;
if pos > 1 && (annotation.has_label() || annotation.takes_space()) {
for p in line_offset + 1..=line_offset + pos {
buffer.putc(p,
code_offset + annotation.start_col - margin.computed_left,
'|',
style);
}
}

and the one that draws the span labels is right below

// Write the labels on the annotations that actually have a label.
//
// After this we will have:
//
// 2 | fn foo() {
// | __________
// | |
// | something about `foo`
// 3 |
// 4 | }
// | _ test
for &(pos, annotation) in &annotations_position {
let style = if annotation.is_primary {
Style::LabelPrimary
} else {
Style::LabelSecondary
};
let (pos, col) = if pos == 0 {
(pos + 1, (annotation.end_col + 1).saturating_sub(left))
} else {
(pos + 2, annotation.start_col.saturating_sub(left))
};
if let Some(ref label) = annotation.label {
buffer.puts(line_offset + pos, code_offset + col, &label, style);
}
}

I think the error might be using margin.computed_left instead of left, but I'm not entirely certain.

If this is your first time compiling rustc, you probably want to read the rustc guide, but the TL;DR: is "run ./x.py test src/test/ui --stage 1 --bless to build the compiler up to the first stage and update the stderr test output files".

You might also want to wait until the linked PR is merged so you have a test case, unless you wish to come up with a new one (look for a test that has multiple labels in the same span and pad the source to the left with unicode chars on non-1 width).

@TheSamsa
Copy link
Contributor

Thank you!
I did read the rustc guide, and even compiled it on my own once. But thanks for the direction, and the note to the PR.
I'll do my best 😉

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 A-Unicode Area: Unicode E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. 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.

2 participants