Skip to content

Commit 8c8ff5f

Browse files
committed
Auto merge of #10976 - dswij:issue-10966, r=Alexendoo
Make [`missing_panics_doc`] not lint for `todo!()` closes #10966 changelog: [`missing_panics_doc`] now does not lint for `todo!()`
2 parents bb78d76 + a6346d7 commit 8c8ff5f

File tree

4 files changed

+60
-57
lines changed

4 files changed

+60
-57
lines changed

clippy_lints/src/doc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -909,7 +909,7 @@ impl<'a, 'tcx> Visitor<'tcx> for FindPanicUnwrap<'a, 'tcx> {
909909
if is_panic(self.cx, macro_call.def_id)
910910
|| matches!(
911911
self.cx.tcx.item_name(macro_call.def_id).as_str(),
912-
"assert" | "assert_eq" | "assert_ne" | "todo"
912+
"assert" | "assert_eq" | "assert_ne"
913913
)
914914
{
915915
self.panic_span = Some(macro_call.span);

tests/ui/auxiliary/macro_rules.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,10 @@ macro_rules! issue_10421 {
4343
b = a;
4444
};
4545
}
46+
47+
#[macro_export]
48+
macro_rules! macro_with_panic {
49+
() => {
50+
panic!()
51+
};
52+
}

tests/ui/missing_panics_doc.rs

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
1+
//@aux-build:macro_rules.rs
12
#![warn(clippy::missing_panics_doc)]
23
#![allow(clippy::option_map_unit_fn, clippy::unnecessary_literal_unwrap)]
4+
5+
#[macro_use]
6+
extern crate macro_rules;
7+
8+
use macro_rules::macro_with_panic;
9+
310
fn main() {}
411

512
/// This needs to be documented
@@ -13,11 +20,6 @@ pub fn panic() {
1320
panic!("This function panics")
1421
}
1522

16-
/// This needs to be documented
17-
pub fn todo() {
18-
todo!()
19-
}
20-
2123
/// This needs to be documented
2224
pub fn inner_body(opt: Option<u32>) {
2325
opt.map(|x| {
@@ -76,15 +78,6 @@ pub fn inner_body_documented(opt: Option<u32>) {
7678
});
7779
}
7880

79-
/// This is documented
80-
///
81-
/// # Panics
82-
///
83-
/// We still need to do this part
84-
pub fn todo_documented() {
85-
todo!()
86-
}
87-
8881
/// This is documented
8982
///
9083
/// # Panics
@@ -114,6 +107,11 @@ pub fn assert_ne_documented() {
114107
assert_ne!(x, 0);
115108
}
116109

110+
/// `todo!()` is fine
111+
pub fn todo() {
112+
todo!()
113+
}
114+
117115
/// This is okay because it is private
118116
fn unwrap_private() {
119117
let result = Err("Hi");
@@ -125,11 +123,6 @@ fn panic_private() {
125123
panic!("This function panics")
126124
}
127125

128-
/// This is okay because it is private
129-
fn todo_private() {
130-
todo!()
131-
}
132-
133126
/// This is okay because it is private
134127
fn inner_body_private(opt: Option<u32>) {
135128
opt.map(|x| {
@@ -183,3 +176,18 @@ pub mod issue10240 {
183176
*v.last().expect("passed an empty thing")
184177
}
185178
}
179+
180+
fn from_external_macro_should_not_lint() {
181+
macro_with_panic!()
182+
}
183+
184+
macro_rules! some_macro_that_panics {
185+
() => {
186+
panic!()
187+
};
188+
}
189+
190+
fn from_declared_macro_should_lint_at_macrosite() {
191+
// Not here.
192+
some_macro_that_panics!()
193+
}

tests/ui/missing_panics_doc.stderr

Lines changed: 25 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,159 +1,147 @@
11
error: docs for function which may panic missing `# Panics` section
2-
--> $DIR/missing_panics_doc.rs:6:1
2+
--> $DIR/missing_panics_doc.rs:13:1
33
|
44
LL | pub fn unwrap() {
55
| ^^^^^^^^^^^^^^^
66
|
77
note: first possible panic found here
8-
--> $DIR/missing_panics_doc.rs:8:5
8+
--> $DIR/missing_panics_doc.rs:15:5
99
|
1010
LL | result.unwrap()
1111
| ^^^^^^^^^^^^^^^
1212
= note: `-D clippy::missing-panics-doc` implied by `-D warnings`
1313

1414
error: docs for function which may panic missing `# Panics` section
15-
--> $DIR/missing_panics_doc.rs:12:1
15+
--> $DIR/missing_panics_doc.rs:19:1
1616
|
1717
LL | pub fn panic() {
1818
| ^^^^^^^^^^^^^^
1919
|
2020
note: first possible panic found here
21-
--> $DIR/missing_panics_doc.rs:13:5
21+
--> $DIR/missing_panics_doc.rs:20:5
2222
|
2323
LL | panic!("This function panics")
2424
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2525

2626
error: docs for function which may panic missing `# Panics` section
27-
--> $DIR/missing_panics_doc.rs:17:1
28-
|
29-
LL | pub fn todo() {
30-
| ^^^^^^^^^^^^^
31-
|
32-
note: first possible panic found here
33-
--> $DIR/missing_panics_doc.rs:18:5
34-
|
35-
LL | todo!()
36-
| ^^^^^^^
37-
38-
error: docs for function which may panic missing `# Panics` section
39-
--> $DIR/missing_panics_doc.rs:22:1
27+
--> $DIR/missing_panics_doc.rs:24:1
4028
|
4129
LL | pub fn inner_body(opt: Option<u32>) {
4230
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4331
|
4432
note: first possible panic found here
45-
--> $DIR/missing_panics_doc.rs:25:13
33+
--> $DIR/missing_panics_doc.rs:27:13
4634
|
4735
LL | panic!()
4836
| ^^^^^^^^
4937

5038
error: docs for function which may panic missing `# Panics` section
51-
--> $DIR/missing_panics_doc.rs:31:1
39+
--> $DIR/missing_panics_doc.rs:33:1
5240
|
5341
LL | pub fn unreachable_and_panic() {
5442
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5543
|
5644
note: first possible panic found here
57-
--> $DIR/missing_panics_doc.rs:32:39
45+
--> $DIR/missing_panics_doc.rs:34:39
5846
|
5947
LL | if true { unreachable!() } else { panic!() }
6048
| ^^^^^^^^
6149

6250
error: docs for function which may panic missing `# Panics` section
63-
--> $DIR/missing_panics_doc.rs:36:1
51+
--> $DIR/missing_panics_doc.rs:38:1
6452
|
6553
LL | pub fn assert_eq() {
6654
| ^^^^^^^^^^^^^^^^^^
6755
|
6856
note: first possible panic found here
69-
--> $DIR/missing_panics_doc.rs:38:5
57+
--> $DIR/missing_panics_doc.rs:40:5
7058
|
7159
LL | assert_eq!(x, 0);
7260
| ^^^^^^^^^^^^^^^^
7361

7462
error: docs for function which may panic missing `# Panics` section
75-
--> $DIR/missing_panics_doc.rs:42:1
63+
--> $DIR/missing_panics_doc.rs:44:1
7664
|
7765
LL | pub fn assert_ne() {
7866
| ^^^^^^^^^^^^^^^^^^
7967
|
8068
note: first possible panic found here
81-
--> $DIR/missing_panics_doc.rs:44:5
69+
--> $DIR/missing_panics_doc.rs:46:5
8270
|
8371
LL | assert_ne!(x, 0);
8472
| ^^^^^^^^^^^^^^^^
8573

8674
error: docs for function which may panic missing `# Panics` section
87-
--> $DIR/missing_panics_doc.rs:158:5
75+
--> $DIR/missing_panics_doc.rs:151:5
8876
|
8977
LL | pub fn option_unwrap<T>(v: &[T]) -> &T {
9078
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9179
|
9280
note: first possible panic found here
93-
--> $DIR/missing_panics_doc.rs:160:9
81+
--> $DIR/missing_panics_doc.rs:153:9
9482
|
9583
LL | o.unwrap()
9684
| ^^^^^^^^^^
9785

9886
error: docs for function which may panic missing `# Panics` section
99-
--> $DIR/missing_panics_doc.rs:163:5
87+
--> $DIR/missing_panics_doc.rs:156:5
10088
|
10189
LL | pub fn option_expect<T>(v: &[T]) -> &T {
10290
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
10391
|
10492
note: first possible panic found here
105-
--> $DIR/missing_panics_doc.rs:165:9
93+
--> $DIR/missing_panics_doc.rs:158:9
10694
|
10795
LL | o.expect("passed an empty thing")
10896
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
10997

11098
error: docs for function which may panic missing `# Panics` section
111-
--> $DIR/missing_panics_doc.rs:168:5
99+
--> $DIR/missing_panics_doc.rs:161:5
112100
|
113101
LL | pub fn result_unwrap<T>(v: &[T]) -> &T {
114102
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
115103
|
116104
note: first possible panic found here
117-
--> $DIR/missing_panics_doc.rs:170:9
105+
--> $DIR/missing_panics_doc.rs:163:9
118106
|
119107
LL | res.unwrap()
120108
| ^^^^^^^^^^^^
121109

122110
error: docs for function which may panic missing `# Panics` section
123-
--> $DIR/missing_panics_doc.rs:173:5
111+
--> $DIR/missing_panics_doc.rs:166:5
124112
|
125113
LL | pub fn result_expect<T>(v: &[T]) -> &T {
126114
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
127115
|
128116
note: first possible panic found here
129-
--> $DIR/missing_panics_doc.rs:175:9
117+
--> $DIR/missing_panics_doc.rs:168:9
130118
|
131119
LL | res.expect("passed an empty thing")
132120
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
133121

134122
error: docs for function which may panic missing `# Panics` section
135-
--> $DIR/missing_panics_doc.rs:178:5
123+
--> $DIR/missing_panics_doc.rs:171:5
136124
|
137125
LL | pub fn last_unwrap(v: &[u32]) -> u32 {
138126
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
139127
|
140128
note: first possible panic found here
141-
--> $DIR/missing_panics_doc.rs:179:10
129+
--> $DIR/missing_panics_doc.rs:172:10
142130
|
143131
LL | *v.last().unwrap()
144132
| ^^^^^^^^^^^^^^^^^
145133

146134
error: docs for function which may panic missing `# Panics` section
147-
--> $DIR/missing_panics_doc.rs:182:5
135+
--> $DIR/missing_panics_doc.rs:175:5
148136
|
149137
LL | pub fn last_expect(v: &[u32]) -> u32 {
150138
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
151139
|
152140
note: first possible panic found here
153-
--> $DIR/missing_panics_doc.rs:183:10
141+
--> $DIR/missing_panics_doc.rs:176:10
154142
|
155143
LL | *v.last().expect("passed an empty thing")
156144
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
157145

158-
error: aborting due to 13 previous errors
146+
error: aborting due to 12 previous errors
159147

0 commit comments

Comments
 (0)