Skip to content

Commit 0e06b3c

Browse files
committed
Auto merge of #6996 - Y-Nak:missing_panics_doc, r=Manishearth
Allow missing panics doc if the panics occur only when debug-assertions is specified fixes #6970 changelog: `missing_panics_doc`: Allow missing panics doc if the panics occur only when `debug-assertions` is specified.
2 parents c07103b + 31afdfc commit 0e06b3c

File tree

3 files changed

+24
-10
lines changed

3 files changed

+24
-10
lines changed

clippy_lints/src/doc.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -715,6 +715,7 @@ impl<'a, 'tcx> Visitor<'tcx> for FindPanicUnwrap<'a, 'tcx> {
715715
if let Some(path_def_id) = path.res.opt_def_id();
716716
if match_panic_def_id(self.cx, path_def_id);
717717
if is_expn_of(expr.span, "unreachable").is_none();
718+
if !is_expn_of_debug_assertions(expr.span);
718719
then {
719720
self.panic_span = Some(expr.span);
720721
}
@@ -738,3 +739,8 @@ impl<'a, 'tcx> Visitor<'tcx> for FindPanicUnwrap<'a, 'tcx> {
738739
NestedVisitorMap::OnlyBodies(self.cx.tcx.hir())
739740
}
740741
}
742+
743+
fn is_expn_of_debug_assertions(span: Span) -> bool {
744+
const MACRO_NAMES: &[&str] = &["debug_assert", "debug_assert_eq", "debug_assert_ne"];
745+
MACRO_NAMES.iter().any(|name| is_expn_of(span, name).is_some())
746+
}

tests/ui/doc_panics.rs renamed to tests/ui/missing_panics_doc.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,3 +112,11 @@ fn inner_body_private(opt: Option<u32>) {
112112
pub fn unreachable() {
113113
unreachable!("This function panics")
114114
}
115+
116+
/// #6970.
117+
/// This is okay because it is expansion of `debug_assert` family.
118+
pub fn debug_assertions() {
119+
debug_assert!(false);
120+
debug_assert_eq!(1, 2);
121+
debug_assert_ne!(1, 2);
122+
}

tests/ui/doc_panics.stderr renamed to tests/ui/missing_panics_doc.stderr

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: docs for function which may panic missing `# Panics` section
2-
--> $DIR/doc_panics.rs:7:1
2+
--> $DIR/missing_panics_doc.rs:7:1
33
|
44
LL | / pub fn unwrap() {
55
LL | | let result = Err("Hi");
@@ -9,43 +9,43 @@ LL | | }
99
|
1010
= note: `-D clippy::missing-panics-doc` implied by `-D warnings`
1111
note: first possible panic found here
12-
--> $DIR/doc_panics.rs:9:5
12+
--> $DIR/missing_panics_doc.rs:9:5
1313
|
1414
LL | result.unwrap()
1515
| ^^^^^^^^^^^^^^^
1616

1717
error: docs for function which may panic missing `# Panics` section
18-
--> $DIR/doc_panics.rs:13:1
18+
--> $DIR/missing_panics_doc.rs:13:1
1919
|
2020
LL | / pub fn panic() {
2121
LL | | panic!("This function panics")
2222
LL | | }
2323
| |_^
2424
|
2525
note: first possible panic found here
26-
--> $DIR/doc_panics.rs:14:5
26+
--> $DIR/missing_panics_doc.rs:14:5
2727
|
2828
LL | panic!("This function panics")
2929
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3030
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
3131

3232
error: docs for function which may panic missing `# Panics` section
33-
--> $DIR/doc_panics.rs:18:1
33+
--> $DIR/missing_panics_doc.rs:18:1
3434
|
3535
LL | / pub fn todo() {
3636
LL | | todo!()
3737
LL | | }
3838
| |_^
3939
|
4040
note: first possible panic found here
41-
--> $DIR/doc_panics.rs:19:5
41+
--> $DIR/missing_panics_doc.rs:19:5
4242
|
4343
LL | todo!()
4444
| ^^^^^^^
4545
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
4646

4747
error: docs for function which may panic missing `# Panics` section
48-
--> $DIR/doc_panics.rs:23:1
48+
--> $DIR/missing_panics_doc.rs:23:1
4949
|
5050
LL | / pub fn inner_body(opt: Option<u32>) {
5151
LL | | opt.map(|x| {
@@ -57,22 +57,22 @@ LL | | }
5757
| |_^
5858
|
5959
note: first possible panic found here
60-
--> $DIR/doc_panics.rs:26:13
60+
--> $DIR/missing_panics_doc.rs:26:13
6161
|
6262
LL | panic!()
6363
| ^^^^^^^^
6464
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
6565

6666
error: docs for function which may panic missing `# Panics` section
67-
--> $DIR/doc_panics.rs:32:1
67+
--> $DIR/missing_panics_doc.rs:32:1
6868
|
6969
LL | / pub fn unreachable_and_panic() {
7070
LL | | if true { unreachable!() } else { panic!() }
7171
LL | | }
7272
| |_^
7373
|
7474
note: first possible panic found here
75-
--> $DIR/doc_panics.rs:33:39
75+
--> $DIR/missing_panics_doc.rs:33:39
7676
|
7777
LL | if true { unreachable!() } else { panic!() }
7878
| ^^^^^^^^

0 commit comments

Comments
 (0)