diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2024-06-24 15:06:23 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-06-24 15:06:23 +0200 |
| commit | a80ee9159b053f27fdf3e974aab44f2dc74b2868 (patch) | |
| tree | 0dceb58491fcc051613fb4e97ae63bb873988f4e /compiler/rustc_errors/src | |
| parent | 8bfde609e285a8068396490c5399e7913682d19c (diff) | |
| parent | 284437d4342b70e03771d5329e5ac02dd719166a (diff) | |
| download | rust-a80ee9159b053f27fdf3e974aab44f2dc74b2868.tar.gz rust-a80ee9159b053f27fdf3e974aab44f2dc74b2868.zip | |
Rollup merge of #126882 - estebank:multiline-order, r=WaffleLapkin
Special case when a code line only has multiline span starts Minimize multline span overlap when there are multiple of them starting on the same line: ``` 3 | X0 Y0 Z0 | _____^ - - | | _______| | | || _________| 4 | ||| X1 Y1 Z1 5 | ||| X2 Y2 Z2 | |||____^__-__- `Z` label | ||_____|__| | |______| `Y` is a good letter too | `X` is a good letter ```
Diffstat (limited to 'compiler/rustc_errors/src')
| -rw-r--r-- | compiler/rustc_errors/src/emitter.rs | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/compiler/rustc_errors/src/emitter.rs b/compiler/rustc_errors/src/emitter.rs index 7405705dd33..45118bcc58a 100644 --- a/compiler/rustc_errors/src/emitter.rs +++ b/compiler/rustc_errors/src/emitter.rs @@ -902,7 +902,7 @@ impl HumanEmitter { // <EMPTY LINE> // let mut annotations_position = vec![]; - let mut line_len = 0; + let mut line_len: usize = 0; let mut p = 0; for (i, annotation) in annotations.iter().enumerate() { for (j, next) in annotations.iter().enumerate() { @@ -973,6 +973,31 @@ impl HumanEmitter { return vec![]; } + if annotations_position + .iter() + .all(|(_, ann)| matches!(ann.annotation_type, AnnotationType::MultilineStart(_))) + && let Some(max_pos) = annotations_position.iter().map(|(pos, _)| *pos).max() + { + // Special case the following, so that we minimize overlapping multiline spans. + // + // 3 │ X0 Y0 Z0 + // │ ┏━━━━━┛ │ │ < We are writing these lines + // │ ┃┌───────┘ │ < by reverting the "depth" of + // │ ┃│┌─────────┘ < their multilne spans. + // 4 │ ┃││ X1 Y1 Z1 + // 5 │ ┃││ X2 Y2 Z2 + // │ ┃│└────╿──│──┘ `Z` label + // │ ┃└─────│──┤ + // │ ┗━━━━━━┥ `Y` is a good letter too + // ╰╴ `X` is a good letter + for (pos, _) in &mut annotations_position { + *pos = max_pos - *pos; + } + // We know then that we don't need an additional line for the span label, saving us + // one line of vertical space. + line_len = line_len.saturating_sub(1); + } + // Write the column separator. // // After this we will have: |
