diff options
| author | Esteban Küber <esteban@kuber.com.ar> | 2024-12-13 18:18:19 +0000 |
|---|---|---|
| committer | Esteban Küber <esteban@kuber.com.ar> | 2024-12-13 18:48:33 +0000 |
| commit | 9f1044ef76de2ae88ac5c38a27b2bd49f5507d94 (patch) | |
| tree | 48e12299f5c722e7a993e91069772592201b8c15 /compiler/rustc_errors/src/emitter.rs | |
| parent | ad82d9f6986c9801b1d6a60a7f86c71dc16c112f (diff) | |
| download | rust-9f1044ef76de2ae88ac5c38a27b2bd49f5507d94.tar.gz rust-9f1044ef76de2ae88ac5c38a27b2bd49f5507d94.zip | |
Account for `///` when rendering multiline spans
Don't consider `///` and `//!` docstrings to be empty for the purposes of multiline span rendering.
Diffstat (limited to 'compiler/rustc_errors/src/emitter.rs')
| -rw-r--r-- | compiler/rustc_errors/src/emitter.rs | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/compiler/rustc_errors/src/emitter.rs b/compiler/rustc_errors/src/emitter.rs index 04b18b92a0c..ac2f91cdeb3 100644 --- a/compiler/rustc_errors/src/emitter.rs +++ b/compiler/rustc_errors/src/emitter.rs @@ -3050,13 +3050,17 @@ impl FileWithAnnotatedLines { // 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, 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)| { - let s = s.trim(); - !["", "{", "}", "(", ")", "[", "]"].contains(&s) && !s.starts_with("//") - }) + .find(|(_, s)| filter(s)) .map(|(line, _)| line) .unwrap_or(ann.line_start); for line in ann.line_start + 1..until { @@ -3064,10 +3068,7 @@ impl FileWithAnnotatedLines { add_annotation_to_file(&mut output, Lrc::clone(&file), line, ann.as_line()); } let line_end = ann.line_end - 1; - let end_is_empty = file.get_line(line_end - 1).map_or(false, |s| { - let s = s.trim(); - ["", "{", "}", "(", ")", "[", "]"].contains(&s) || s.starts_with("//") - }); + 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()); } |
