about summary refs log tree commit diff
path: root/compiler/rustc_errors/src
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2024-12-14 03:55:47 +0000
committerbors <bors@rust-lang.org>2024-12-14 03:55:47 +0000
commita1740a9c3568e856f6aa12d83e008d38c9749d4b (patch)
tree9830a58a9a9a6f2b70c34a550e91e6fc80fe75e7 /compiler/rustc_errors/src
parent4a204bebdfd5cbc3e7edabf41cda3c3ff8b74917 (diff)
parent75e778991ec9d07bba422645c2a148829bf9d0f3 (diff)
downloadrust-a1740a9c3568e856f6aa12d83e008d38c9749d4b.tar.gz
rust-a1740a9c3568e856f6aa12d83e008d38c9749d4b.zip
Auto merge of #134292 - matthiaskrgr:rollup-3kbjocl, r=matthiaskrgr
Rollup of 8 pull requests

Successful merges:

 - #134181 (Tweak multispan rendering to reduce output length)
 - #134209 (validate `--skip` and `--exclude` paths)
 - #134231 (rustdoc-search: fix mismatched path when parent re-exported twice)
 - #134236 (crashes: more tests v2)
 - #134240 (Only dist `llvm-objcopy` if llvm tools are enabled)
 - #134244 (rustc_borrowck: Stop suggesting the invalid syntax `&mut raw const`)
 - #134251 (A bunch of cleanups (part 2))
 - #134256 (Use a more precise span in placeholder_type_error_diag)

r? `@ghost`
`@rustbot` modify labels: rollup
Diffstat (limited to 'compiler/rustc_errors/src')
-rw-r--r--compiler/rustc_errors/src/emitter.rs15
1 files changed, 12 insertions, 3 deletions
diff --git a/compiler/rustc_errors/src/emitter.rs b/compiler/rustc_errors/src/emitter.rs
index 1b6c6edcc61..ac2f91cdeb3 100644
--- a/compiler/rustc_errors/src/emitter.rs
+++ b/compiler/rustc_errors/src/emitter.rs
@@ -3048,11 +3048,19 @@ 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 filter = |s: &str| {
+                    let s = s.trim();
+                    // Consider comments as empty, but don't consider docstrings to be empty.
+                    !(s.starts_with("//") && !(s.starts_with("///") || s.starts_with("//!")))
+                        // Consider lines with nothing but whitespace, a single delimiter as empty.
+                        && !["", "{", "}", "(", ")", "[", "]"].contains(&s)
+                };
                 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)| filter(s))
                     .map(|(line, _)| line)
                     .unwrap_or(ann.line_start);
                 for line in ann.line_start + 1..until {
@@ -3060,7 +3068,8 @@ impl FileWithAnnotatedLines {
                     add_annotation_to_file(&mut output, Lrc::clone(&file), line, ann.as_line());
                 }
                 let line_end = ann.line_end - 1;
-                if middle < line_end {
+                let end_is_empty = file.get_line(line_end - 1).map_or(false, |s| !filter(&s));
+                if middle < line_end && !end_is_empty {
                     add_annotation_to_file(&mut output, Lrc::clone(&file), line_end, ann.as_line());
                 }
             } else {