Skip to content

Commit 9f1044e

Browse files
committed
Account for /// when rendering multiline spans
Don't consider `///` and `//!` docstrings to be empty for the purposes of multiline span rendering.
1 parent ad82d9f commit 9f1044e

18 files changed

+144
-43
lines changed

compiler/rustc_errors/src/emitter.rs

+9-8
Original file line numberDiff line numberDiff line change
@@ -3050,24 +3050,25 @@ impl FileWithAnnotatedLines {
30503050
// We'll show up to 4 lines past the beginning of the multispan start.
30513051
// We will *not* include the tail of lines that are only whitespace, a comment or
30523052
// a bare delimiter.
3053+
let filter = |s: &str| {
3054+
let s = s.trim();
3055+
// Consider comments as empty, but don't consider docstrings to be empty.
3056+
!(s.starts_with("//") && !(s.starts_with("///") || s.starts_with("//!")))
3057+
// Consider lines with nothing but whitespace, a single delimiter as empty.
3058+
&& !["", "{", "}", "(", ")", "[", "]"].contains(&s)
3059+
};
30533060
let until = (ann.line_start..middle)
30543061
.rev()
30553062
.filter_map(|line| file.get_line(line - 1).map(|s| (line + 1, s)))
3056-
.find(|(_, s)| {
3057-
let s = s.trim();
3058-
!["", "{", "}", "(", ")", "[", "]"].contains(&s) && !s.starts_with("//")
3059-
})
3063+
.find(|(_, s)| filter(s))
30603064
.map(|(line, _)| line)
30613065
.unwrap_or(ann.line_start);
30623066
for line in ann.line_start + 1..until {
30633067
// Every `|` that joins the beginning of the span (`___^`) to the end (`|__^`).
30643068
add_annotation_to_file(&mut output, Lrc::clone(&file), line, ann.as_line());
30653069
}
30663070
let line_end = ann.line_end - 1;
3067-
let end_is_empty = file.get_line(line_end - 1).map_or(false, |s| {
3068-
let s = s.trim();
3069-
["", "{", "}", "(", ")", "[", "]"].contains(&s) || s.starts_with("//")
3070-
});
3071+
let end_is_empty = file.get_line(line_end - 1).map_or(false, |s| !filter(&s));
30713072
if middle < line_end && !end_is_empty {
30723073
add_annotation_to_file(&mut output, Lrc::clone(&file), line_end, ann.as_line());
30733074
}

src/tools/clippy/tests/ui/doc/unbalanced_ticks.stderr

+3-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ error: backticks are unbalanced
33
|
44
LL | /// This is a doc comment with `unbalanced_tick marks and several words that
55
| _____^
6-
... |
6+
LL | |
7+
LL | | /// should be `encompassed_by` tick marks because they `contain_underscores`.
8+
LL | | /// Because of the initial `unbalanced_tick` pair, the error message is
79
LL | | /// very `confusing_and_misleading`.
810
| |____________________________________^
911
|

src/tools/clippy/tests/ui/empty_line_after/doc_comments.stderr

+3
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@ error: empty lines after doc comment
9696
--> tests/ui/empty_line_after/doc_comments.rs:63:5
9797
|
9898
LL | / /// for OldA
99+
LL | | // struct OldA;
100+
LL | |
101+
LL | | /// Docs
99102
... |
100103
LL | |
101104
| |_^

src/tools/clippy/tests/ui/needless_doc_main.stderr

+10-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ error: needless `fn main` in doctest
33
|
44
LL | /// fn main() {
55
| _____^
6-
... |
6+
LL | |
7+
LL | |
8+
LL | | /// unimplemented!();
79
LL | | /// }
810
| |_____^
911
|
@@ -15,7 +17,8 @@ error: needless `fn main` in doctest
1517
|
1618
LL | /// fn main() -> () {
1719
| _____^
18-
... |
20+
LL | |
21+
LL | | /// unimplemented!();
1922
LL | | /// }
2023
| |_____^
2124

@@ -24,7 +27,8 @@ error: needless `fn main` in doctest
2427
|
2528
LL | /// fn main() {
2629
| _____^
27-
... |
30+
LL | |
31+
LL | | /// unimplemented!();
2832
LL | | /// }
2933
| |_____^
3034

@@ -33,7 +37,9 @@ error: needless `fn main` in doctest
3337
|
3438
LL | /// // the fn is not always the first line
3539
| _____^
36-
... |
40+
LL | |
41+
LL | | /// fn main() {
42+
LL | | /// unimplemented!();
3743
LL | | /// }
3844
| |_____^
3945

src/tools/clippy/tests/ui/suspicious_doc_comments_unfixable.stderr

+7-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@ error: this is an outer doc comment and does not apply to the parent module or c
22
--> tests/ui/suspicious_doc_comments_unfixable.rs:4:1
33
|
44
LL | / ///! a
5-
... |
5+
LL | |
6+
LL | |
7+
LL | | ///! b
8+
LL | | /// c
69
LL | | ///! d
710
| |______^
811
|
@@ -22,7 +25,9 @@ error: this is an outer doc comment and does not apply to the parent module or c
2225
--> tests/ui/suspicious_doc_comments_unfixable.rs:12:1
2326
|
2427
LL | / ///! a
25-
... |
28+
LL | |
29+
LL | | ///! b
30+
LL | | /// c
2631
LL | | ///! d
2732
| |______^
2833
|

src/tools/clippy/tests/ui/too_long_first_doc_paragraph-fix.stderr

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ error: first doc comment paragraph is too long
22
--> tests/ui/too_long_first_doc_paragraph-fix.rs:3:1
33
|
44
LL | / /// A very short summary.
5-
... |
5+
LL | | /// A much longer explanation that goes into a lot more detail about
6+
LL | | /// how the thing works, possibly with doclinks and so one,
7+
LL | | /// and probably spanning a many rows. Blablabla, it needs to be over
68
LL | | /// 200 characters so I needed to write something longeeeeeeer.
79
| |_^
810
|

src/tools/clippy/tests/ui/too_long_first_doc_paragraph.stderr

+5-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ error: first doc comment paragraph is too long
22
--> tests/ui/too_long_first_doc_paragraph.rs:8:5
33
|
44
LL | / //! A very short summary.
5-
... |
5+
LL | | //! A much longer explanation that goes into a lot more detail about
6+
LL | | //! how the thing works, possibly with doclinks and so one,
7+
LL | | //! and probably spanning a many rows. Blablabla, it needs to be over
68
LL | | //! 200 characters so I needed to write something longeeeeeeer.
79
| |____^
810
|
@@ -27,7 +29,8 @@ error: first doc comment paragraph is too long
2729
--> tests/ui/too_long_first_doc_paragraph.rs:36:1
2830
|
2931
LL | / /// Lorem
30-
... |
32+
LL | | /// ipsum dolor sit amet, consectetur adipiscing elit. Nunc turpis nunc, lacinia
33+
LL | | /// a dolor in, pellentesque aliquet enim. Cras nec maximus sem. Mauris arcu libero,
3134
LL | | /// gravida non lacinia at, rhoncus eu lacus.
3235
| |_^
3336

tests/rustdoc-ui/custom_code_classes_in_docs-warning3.stderr

+6
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@ error: unclosed quote string `"`
22
--> $DIR/custom_code_classes_in_docs-warning3.rs:8:1
33
|
44
LL | / /// ```{class="}
5+
LL | | /// main;
6+
LL | | /// ```
57
... |
8+
LL | | /// main;
69
LL | | /// ```
710
| |_______^
811
|
@@ -17,7 +20,10 @@ error: unclosed quote string `"`
1720
--> $DIR/custom_code_classes_in_docs-warning3.rs:8:1
1821
|
1922
LL | / /// ```{class="}
23+
LL | | /// main;
24+
LL | | /// ```
2025
... |
26+
LL | | /// main;
2127
LL | | /// ```
2228
| |_______^
2329
|

tests/rustdoc-ui/doctest/check-attr-test.stderr

+36-12
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ error: unknown attribute `compile-fail`
22
--> $DIR/check-attr-test.rs:5:1
33
|
44
5 | / /// foo
5-
... |
5+
6 | | ///
6+
7 | | /// ```compile-fail,compilefail,comPile_fail
7+
8 | | /// boo
68
9 | | /// ```
79
| |_______^
810
|
@@ -18,7 +20,9 @@ error: unknown attribute `compilefail`
1820
--> $DIR/check-attr-test.rs:5:1
1921
|
2022
5 | / /// foo
21-
... |
23+
6 | | ///
24+
7 | | /// ```compile-fail,compilefail,comPile_fail
25+
8 | | /// boo
2226
9 | | /// ```
2327
| |_______^
2428
|
@@ -29,7 +33,9 @@ error: unknown attribute `comPile_fail`
2933
--> $DIR/check-attr-test.rs:5:1
3034
|
3135
5 | / /// foo
32-
... |
36+
6 | | ///
37+
7 | | /// ```compile-fail,compilefail,comPile_fail
38+
8 | | /// boo
3339
9 | | /// ```
3440
| |_______^
3541
|
@@ -40,7 +46,9 @@ error: unknown attribute `should-panic`
4046
--> $DIR/check-attr-test.rs:12:1
4147
|
4248
12 | / /// bar
43-
... |
49+
13 | | ///
50+
14 | | /// ```should-panic,shouldpanic,shOuld_panic
51+
15 | | /// boo
4452
16 | | /// ```
4553
| |_______^
4654
|
@@ -51,7 +59,9 @@ error: unknown attribute `shouldpanic`
5159
--> $DIR/check-attr-test.rs:12:1
5260
|
5361
12 | / /// bar
54-
... |
62+
13 | | ///
63+
14 | | /// ```should-panic,shouldpanic,shOuld_panic
64+
15 | | /// boo
5565
16 | | /// ```
5666
| |_______^
5767
|
@@ -62,7 +72,9 @@ error: unknown attribute `shOuld_panic`
6272
--> $DIR/check-attr-test.rs:12:1
6373
|
6474
12 | / /// bar
65-
... |
75+
13 | | ///
76+
14 | | /// ```should-panic,shouldpanic,shOuld_panic
77+
15 | | /// boo
6678
16 | | /// ```
6779
| |_______^
6880
|
@@ -73,7 +85,9 @@ error: unknown attribute `no-run`
7385
--> $DIR/check-attr-test.rs:19:1
7486
|
7587
19 | / /// foobar
76-
... |
88+
20 | | ///
89+
21 | | /// ```no-run,norun,nO_run
90+
22 | | /// boo
7791
23 | | /// ```
7892
| |_______^
7993
|
@@ -84,7 +98,9 @@ error: unknown attribute `norun`
8498
--> $DIR/check-attr-test.rs:19:1
8599
|
86100
19 | / /// foobar
87-
... |
101+
20 | | ///
102+
21 | | /// ```no-run,norun,nO_run
103+
22 | | /// boo
88104
23 | | /// ```
89105
| |_______^
90106
|
@@ -95,7 +111,9 @@ error: unknown attribute `nO_run`
95111
--> $DIR/check-attr-test.rs:19:1
96112
|
97113
19 | / /// foobar
98-
... |
114+
20 | | ///
115+
21 | | /// ```no-run,norun,nO_run
116+
22 | | /// boo
99117
23 | | /// ```
100118
| |_______^
101119
|
@@ -106,7 +124,9 @@ error: unknown attribute `test-harness`
106124
--> $DIR/check-attr-test.rs:26:1
107125
|
108126
26 | / /// b
109-
... |
127+
27 | | ///
128+
28 | | /// ```test-harness,testharness,tesT_harness
129+
29 | | /// boo
110130
30 | | /// ```
111131
| |_______^
112132
|
@@ -117,7 +137,9 @@ error: unknown attribute `testharness`
117137
--> $DIR/check-attr-test.rs:26:1
118138
|
119139
26 | / /// b
120-
... |
140+
27 | | ///
141+
28 | | /// ```test-harness,testharness,tesT_harness
142+
29 | | /// boo
121143
30 | | /// ```
122144
| |_______^
123145
|
@@ -128,7 +150,9 @@ error: unknown attribute `tesT_harness`
128150
--> $DIR/check-attr-test.rs:26:1
129151
|
130152
26 | / /// b
131-
... |
153+
27 | | ///
154+
28 | | /// ```test-harness,testharness,tesT_harness
155+
29 | | /// boo
132156
30 | | /// ```
133157
| |_______^
134158
|

tests/rustdoc-ui/doctest/private-item-doc-test.stderr

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ error: documentation test in private item
22
--> $DIR/private-item-doc-test.rs:4:5
33
|
44
LL | / /// private doc test
5-
... |
5+
LL | | ///
6+
LL | | /// ```
7+
LL | | /// assert!(false);
68
LL | | /// ```
79
| |___________^
810
|

tests/rustdoc-ui/doctest/private-public-item-doc-test.stderr

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ error: documentation test in private item
22
--> $DIR/private-public-item-doc-test.rs:4:5
33
|
44
LL | / /// private doc test
5-
... |
5+
LL | | ///
6+
LL | | /// ```
7+
LL | | /// assert!(false);
68
LL | | /// ```
79
| |___________^
810
|

tests/rustdoc-ui/doctest/standalone-warning-2024.stderr

+10-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@ error: unknown attribute `standalone`
22
--> $DIR/standalone-warning-2024.rs:11:1
33
|
44
11 | / //! ```standalone
5-
... |
5+
12 | | //! bla
6+
13 | | //! ```
7+
14 | | //!
8+
15 | | //! ```standalone-crate
9+
16 | | //! bla
610
17 | | //! ```
711
| |_______^
812
|
@@ -19,7 +23,11 @@ error: unknown attribute `standalone-crate`
1923
--> $DIR/standalone-warning-2024.rs:11:1
2024
|
2125
11 | / //! ```standalone
22-
... |
26+
12 | | //! bla
27+
13 | | //! ```
28+
14 | | //!
29+
15 | | //! ```standalone-crate
30+
16 | | //! bla
2331
17 | | //! ```
2432
| |_______^
2533
|

tests/rustdoc-ui/invalid-syntax.stderr

+5-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ warning: could not parse code block as Rust code
2121
|
2222
LL | /// ```
2323
| _____^
24-
... |
24+
LL | | /// |
25+
LL | | /// LL | use foobar::Baz;
26+
LL | | /// | ^^^^^^ did you mean `baz::foobar`?
2527
LL | | /// ```
2628
| |_______^
2729
|
@@ -112,7 +114,8 @@ warning: Rust code block is empty
112114
|
113115
LL | /// ```
114116
| _____^
115-
... |
117+
LL | | ///
118+
LL | | ///
116119
LL | | /// ```
117120
| |_______^
118121
|

0 commit comments

Comments
 (0)