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

On long spans, trim the middle of them to make them fit in the terminal width #137757

Merged
merged 7 commits into from
Mar 8, 2025

Conversation

estebank
Copy link
Contributor

When encountering a single line span that is wider than the terminal, we keep context at the start and end of the span but otherwise remove the code from the middle. This is somewhat independent from whether the left and right margins of the output have been trimmed as well.

error[E0308]: mismatched types
  --> $DIR/long-span.rs:6:15
   |
LL | ... = [0, 0, 0, 0, ..., 0, 0];
   |       ^^^^^^^^^^^^^...^^^^^^^ expected `u8`, found `[{integer}; 1681]`

Address part of #137680 (missing handling of the long suggestion). Fix #125581.


Change the way that underline positions are calculated by delaying using the "visual" column position until the last possible moment, instead using the "file"/byte position in the file, and then calculating visual positioning as late as possible. This should make the underlines more resilient to non-1-width unicode chars.

Unfortunately, as part of this change (which fixes some visual bugs) comes with the loss of some eager tab codepoint handling, but the output remains legible despite some minor regression on the "margin trimming" logic.


-Zteach is perma-unstable, barely used, the highlighting logic buggy and the flag being passed around is tech-debt. We should likely remove -Zteach in its entirely.

@rustbot
Copy link
Collaborator

rustbot commented Feb 27, 2025

r? @lcnr

rustbot has assigned @lcnr.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. labels Feb 27, 2025
@rust-log-analyzer

This comment has been minimized.

@lcnr
Copy link
Contributor

lcnr commented Mar 5, 2025

Looked through it but don't have a good understanding of how the diagnostics emitter works

r? compiler

@rustbot rustbot assigned davidtwco and unassigned lcnr Mar 5, 2025
@davidtwco
Copy link
Member

@bors r+

@bors
Copy link
Contributor

bors commented Mar 7, 2025

📌 Commit bf334c2 has been approved by davidtwco

It is now in the queue for this repository.

@bors bors 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 Mar 7, 2025
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Mar 7, 2025
On long spans, trim the middle of them to make them fit in the terminal width

When encountering a single line span that is wider than the terminal, we keep context at the start and end of the span but otherwise remove the code from the middle. This is somewhat independent from whether the left and right margins of the output have been trimmed as well.

```
error[E0308]: mismatched types
  --> $DIR/long-span.rs:6:15
   |
LL | ... = [0, 0, 0, 0, ..., 0, 0];
   |       ^^^^^^^^^^^^^...^^^^^^^ expected `u8`, found `[{integer}; 1681]`
```

Address part of rust-lang#137680 (missing handling of the long suggestion). Fix rust-lang#125581.

---

Change the way that underline positions are calculated by delaying using the "visual" column position until the last possible moment, instead using the "file"/byte position in the file, and then calculating visual positioning as late as possible. This should make the underlines more resilient to non-1-width unicode chars.

Unfortunately, as part of this change (which fixes some visual bugs) comes with the loss of some eager tab codepoint handling, but the output remains legible despite some minor regression on the "margin trimming" logic.

---

`-Zteach` is perma-unstable, barely used, the highlighting logic buggy and the flag being passed around is tech-debt. We should likely remove `-Zteach` in its entirely.
@matthiaskrgr
Copy link
Member

this failed locally 🤔 may need rebase

estebank added 7 commits March 7, 2025 17:55
`-Zteach` is perma-unstable, barely used, the highlighting logic buggy and the flag being passed around is tech-debt. We should likely remove `-Zteach` in its entirely.
…al width

When encountering a single line span that is wider than the terminal, we keep context at the start and end of the span but otherwise remove the code from the middle. This is somewhat independent from whether the left and right margins of the output have been trimmed as well.

```
error[E0308]: mismatched types
  --> $DIR/long-span.rs:6:15
   |
LL | ... = [0, 0, 0, 0, ..., 0, 0];
   |       ^^^^^^^^^^^^^...^^^^^^^ expected `u8`, found `[{integer}; 1681]`
```

Address part of rust-lang#137680 (missing handling of the long suggestion). Fix rust-lang#125581.
Change the way that underline positions are calculated by delaying using
the "visual" column position until the last possible moment, instead
using the "file"/byte position in the file, and then calculating visual
positioning as late as possible. This should make the underlines more
resilient to non-1-width unicode chars.

Unfortunately, as part of this change (which fixes some visual bugs)
comes with the loss of some eager tab codepoint handling, but the output
remains legible despite some minor regression on the "margin trimming"
logic.
@estebank
Copy link
Contributor Author

estebank commented Mar 7, 2025

@bors r=davidtwco

@bors
Copy link
Contributor

bors commented Mar 7, 2025

📌 Commit db2fb71 has been approved by davidtwco

It is now in the queue for this repository.

bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 8, 2025
Rollup of 5 pull requests

Successful merges:

 - rust-lang#136642 (Put the alloc unit tests in a separate alloctests package)
 - rust-lang#137528 (Windows: Fix error in `fs::rename` on Windows 1607)
 - rust-lang#137685 (self-contained linker: conservatively default to `-znostart-stop-gc` on x64 linux)
 - rust-lang#137757 (On long spans, trim the middle of them to make them fit in the terminal width)
 - rust-lang#138189 (Mention `env` and `option_env` macros in `std::env::var` docs)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 2c374e3 into rust-lang:master Mar 8, 2025
6 checks passed
@rustbot rustbot added this to the 1.87.0 milestone Mar 8, 2025
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Mar 8, 2025
Rollup merge of rust-lang#137757 - estebank:trim-spans, r=davidtwco

On long spans, trim the middle of them to make them fit in the terminal width

When encountering a single line span that is wider than the terminal, we keep context at the start and end of the span but otherwise remove the code from the middle. This is somewhat independent from whether the left and right margins of the output have been trimmed as well.

```
error[E0308]: mismatched types
  --> $DIR/long-span.rs:6:15
   |
LL | ... = [0, 0, 0, 0, ..., 0, 0];
   |       ^^^^^^^^^^^^^...^^^^^^^ expected `u8`, found `[{integer}; 1681]`
```

Address part of rust-lang#137680 (missing handling of the long suggestion). Fix rust-lang#125581.

---

Change the way that underline positions are calculated by delaying using the "visual" column position until the last possible moment, instead using the "file"/byte position in the file, and then calculating visual positioning as late as possible. This should make the underlines more resilient to non-1-width unicode chars.

Unfortunately, as part of this change (which fixes some visual bugs) comes with the loss of some eager tab codepoint handling, but the output remains legible despite some minor regression on the "margin trimming" logic.

---

`-Zteach` is perma-unstable, barely used, the highlighting logic buggy and the flag being passed around is tech-debt. We should likely remove `-Zteach` in its entirely.
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. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

long literal expressions should be truncated
7 participants