Skip to content

Commit a58067b

Browse files
committed
Also inspect doc code blocks
1 parent baf3680 commit a58067b

File tree

5 files changed

+53
-3
lines changed

5 files changed

+53
-3
lines changed

clippy_lints/src/doc.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -649,7 +649,9 @@ fn check_doc<'a, Events: Iterator<Item = (pulldown_cmark::Event<'a>, Range<usize
649649
headers.safety |= in_heading && trimmed_text == "Implementation safety";
650650
headers.safety |= in_heading && trimmed_text == "Implementation Safety";
651651
headers.errors |= in_heading && trimmed_text == "Errors";
652+
headers.errors |= trimmed_text.contains("# Errors\n"); // For /** Doc comments */
652653
headers.panics |= in_heading && trimmed_text == "Panics";
654+
headers.panics |= trimmed_text.contains("# Panics\n");
653655
if in_code {
654656
if is_rust && !no_test {
655657
let edition = edition.unwrap_or_else(|| cx.tcx.sess.edition());

tests/ui/doc_errors.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,21 @@ impl Struct1 {
6363
unimplemented!();
6464
}
6565

66+
/**
67+
# Errors
68+
Hi
69+
*/
70+
pub fn pub_method_with_block_errors_header() -> Result<(), ()> {
71+
unimplemented!();
72+
}
73+
74+
/**
75+
This is not sufficiently documented.
76+
*/
77+
pub fn pub_method_missing_block_errors_header() -> Result<(), ()> {
78+
unimplemented!();
79+
}
80+
6681
/// # Errors
6782
/// A description of the errors goes here.
6883
pub async fn async_pub_method_with_errors_header() -> Result<(), ()> {

tests/ui/doc_errors.stderr

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,16 @@ LL | pub async fn async_pub_method_missing_errors_header() -> Result<(), ()>
3737
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3838

3939
error: docs for function returning `Result` missing `# Errors` section
40-
--> $DIR/doc_errors.rs:85:5
40+
--> $DIR/doc_errors.rs:77:5
41+
|
42+
LL | pub fn pub_method_missing_block_errors_header() -> Result<(), ()> {
43+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
44+
45+
error: docs for function returning `Result` missing `# Errors` section
46+
--> $DIR/doc_errors.rs:100:5
4147
|
4248
LL | fn trait_method_missing_errors_header() -> Result<(), ()>;
4349
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4450

45-
error: aborting due to 7 previous errors
51+
error: aborting due to 8 previous errors
4652

tests/ui/missing_panics_doc.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,21 @@ pub fn assert_ne_documented() {
114114
assert_ne!(x, 0);
115115
}
116116

117+
/**
118+
# Panics
119+
A reason
120+
*/
121+
pub fn panic_documented_in_block() {
122+
panic!();
123+
}
124+
125+
/**
126+
<Cool documentation here>
127+
*/
128+
pub fn panic_undocumented_in_block() {
129+
panic!();
130+
}
131+
117132
/// This is okay because it is private
118133
fn unwrap_private() {
119134
let result = Err("Hi");

tests/ui/missing_panics_doc.stderr

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,18 @@ note: first possible panic found here
8383
LL | assert_ne!(x, 0);
8484
| ^^^^^^^^^^^^^^^^
8585

86+
error: docs for function which may panic missing `# Panics` section
87+
--> $DIR/missing_panics_doc.rs:128:1
88+
|
89+
LL | pub fn panic_undocumented_in_block() {
90+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
91+
|
92+
note: first possible panic found here
93+
--> $DIR/missing_panics_doc.rs:129:5
94+
|
95+
LL | panic!();
96+
| ^^^^^^^^
97+
8698
error: docs for function which may panic missing `# Panics` section
8799
--> $DIR/missing_panics_doc.rs:158:5
88100
|
@@ -114,7 +126,7 @@ LL | pub fn result_unwrap<T>(v: &[T]) -> &T {
114126
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
115127
|
116128
note: first possible panic found here
117-
--> $DIR/missing_panics_doc.rs:170:9
129+
--> $DIR/missing_panics_doc.rs:180:9
118130
|
119131
LL | res.unwrap()
120132
| ^^^^^^^^^^^^

0 commit comments

Comments
 (0)