diff options
| author | Stuart Cook <Zalathar@users.noreply.github.com> | 2025-07-31 18:52:10 +1000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-07-31 18:52:10 +1000 |
| commit | 880113eff908e5d08ea5552f7bfd3ae86c601484 (patch) | |
| tree | 21fe77b968af8f65b36ef5522230c401cae36405 /compiler/rustc_errors/src | |
| parent | 32e7a4b92b109c24e9822c862a7c74436b50e564 (diff) | |
| parent | 761c4e308ca17c1d6d893c7d512f579728b1552f (diff) | |
| download | rust-880113eff908e5d08ea5552f7bfd3ae86c601484.tar.gz rust-880113eff908e5d08ea5552f7bfd3ae86c601484.zip | |
Rollup merge of #144657 - Muscraft:fix-unicode-close-window, r=fee1-dead
fix: Only "close the window" when its the last annotated file
While comparing the Unicode theme output of `rustc` and `annotate-snippets`, I found that `rustc` would ["close the window"](https://github.com/rust-lang/rust/blob/686bc1c5f9c06762b18082434c04d514acf6707e/compiler/rustc_errors/src/emitter.rs#L1025-L1027) (draw a `╰╴`), even though there were other annotated files that followed the current one. This PR makes it so the emitter will only "close the window" on the last annotated file.
Before:
```
error[E0624]: method `method` is private
╭▸ $DIR/close_window.rs:9:7
│
LL │ s.method();
╰╴ ━━━━━━ private method
│
⸬ $DIR/auxiliary/close_window.rs:3:5
│
LL │ fn method(&self) {}
╰╴ ──────────────── private method defined here
```
After:
```
error[E0624]: method `method` is private
╭▸ $DIR/close_window.rs:9:7
│
LL │ s.method();
│ ━━━━━━ private method
│
⸬ $DIR/auxiliary/close_window.rs:3:5
│
LL │ fn method(&self) {}
╰╴ ──────────────── private method defined here
```
Diffstat (limited to 'compiler/rustc_errors/src')
| -rw-r--r-- | compiler/rustc_errors/src/emitter.rs | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/compiler/rustc_errors/src/emitter.rs b/compiler/rustc_errors/src/emitter.rs index 46a4a186824..3fe525df94f 100644 --- a/compiler/rustc_errors/src/emitter.rs +++ b/compiler/rustc_errors/src/emitter.rs @@ -1597,8 +1597,9 @@ impl HumanEmitter { annotated_files.swap(0, pos); } + let annotated_files_len = annotated_files.len(); // Print out the annotate source lines that correspond with the error - for annotated_file in annotated_files { + for (file_idx, annotated_file) in annotated_files.into_iter().enumerate() { // we can't annotate anything if the source is unavailable. if !should_show_source_code( &self.ignored_directories_in_source_blocks, @@ -1855,7 +1856,9 @@ impl HumanEmitter { width_offset, code_offset, margin, - !is_cont && line_idx + 1 == annotated_file.lines.len(), + !is_cont + && file_idx + 1 == annotated_files_len + && line_idx + 1 == annotated_file.lines.len(), ); let mut to_add = FxHashMap::default(); |
