about summary refs log tree commit diff
path: root/compiler/rustc_errors/src
diff options
context:
space:
mode:
authorEsteban Küber <esteban@kuber.com.ar>2024-12-11 21:17:33 +0000
committerEsteban Küber <esteban@kuber.com.ar>2024-12-12 23:36:27 +0000
commit65a54a7f277b30ebeeacb5b303804fa8ffb5c922 (patch)
tree374a7656c18bb7f9ed9846a5bda585b8b5860530 /compiler/rustc_errors/src
parent21fe748be15271ea5804e0507cd699b675efe038 (diff)
downloadrust-65a54a7f277b30ebeeacb5b303804fa8ffb5c922.tar.gz
rust-65a54a7f277b30ebeeacb5b303804fa8ffb5c922.zip
Tweak multispan rendering
Consider comments and bare delimiters the same as an "empty line" for purposes of hiding rendered code output of long multispans. This results in more aggressive shortening of rendered output without losing too much context, specially in `*.stderr` tests that have "hidden" comments.
Diffstat (limited to 'compiler/rustc_errors/src')
-rw-r--r--compiler/rustc_errors/src/emitter.rs8
1 files changed, 6 insertions, 2 deletions
diff --git a/compiler/rustc_errors/src/emitter.rs b/compiler/rustc_errors/src/emitter.rs
index 1b6c6edcc61..9595790d574 100644
--- a/compiler/rustc_errors/src/emitter.rs
+++ b/compiler/rustc_errors/src/emitter.rs
@@ -3048,11 +3048,15 @@ impl FileWithAnnotatedLines {
                 // working correctly.
                 let middle = min(ann.line_start + 4, ann.line_end);
                 // We'll show up to 4 lines past the beginning of the multispan start.
-                // We will *not* include the tail of lines that are only whitespace.
+                // We will *not* include the tail of lines that are only whitespace, a comment or
+                // a bare delimiter.
                 let until = (ann.line_start..middle)
                     .rev()
                     .filter_map(|line| file.get_line(line - 1).map(|s| (line + 1, s)))
-                    .find(|(_, s)| !s.trim().is_empty())
+                    .find(|(_, s)| {
+                        let s = s.trim();
+                        !["", "{", "}", "(", ")", "[", "]"].contains(&s) && !s.starts_with("//")
+                    })
                     .map(|(line, _)| line)
                     .unwrap_or(ann.line_start);
                 for line in ann.line_start + 1..until {