Skip to content

Commit 047f3e1

Browse files
committed
Auto merge of #6700 - daxpedda:panics-doc-unreachable, r=llogiq
Fix missing_panics_doc warning on `unreachable!`. Fixes #6699. Are there any other test-cases I should cover? changelog: [`missing_panics_doc`](https://rust-lang.github.io/rust-clippy/master/index.html#missing_panics_doc): No longer lints on [`unreachable!`](https://doc.rust-lang.org/std/macro.unreachable.html)
2 parents 605e9ba + 37f9782 commit 047f3e1

File tree

3 files changed

+50
-3
lines changed

3 files changed

+50
-3
lines changed

clippy_lints/src/doc.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::utils::{
2-
implements_trait, is_entrypoint_fn, is_type_diagnostic_item, match_panic_def_id, method_chain_args, return_ty,
3-
span_lint, span_lint_and_note,
2+
implements_trait, is_entrypoint_fn, is_expn_of, is_type_diagnostic_item, match_panic_def_id, method_chain_args,
3+
return_ty, span_lint, span_lint_and_note,
44
};
55
use if_chain::if_chain;
66
use itertools::Itertools;
@@ -699,6 +699,7 @@ impl<'a, 'tcx> Visitor<'tcx> for FindPanicUnwrap<'a, 'tcx> {
699699
if let ExprKind::Path(QPath::Resolved(_, ref path)) = func_expr.kind;
700700
if let Some(path_def_id) = path.res.opt_def_id();
701701
if match_panic_def_id(self.cx, path_def_id);
702+
if is_expn_of(expr.span, "unreachable").is_none();
702703
then {
703704
self.panic_span = Some(expr.span);
704705
}

tests/ui/doc_panics.rs

+27
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,15 @@ pub fn inner_body(opt: Option<u32>) {
2828
});
2929
}
3030

31+
/// This needs to be documented
32+
pub fn unreachable_and_panic() {
33+
if true {
34+
unreachable!()
35+
} else {
36+
panic!()
37+
}
38+
}
39+
3140
/// This is documented
3241
///
3342
/// # Panics
@@ -69,6 +78,19 @@ pub fn todo_documented() {
6978
todo!()
7079
}
7180

81+
/// This is documented
82+
///
83+
/// # Panics
84+
///
85+
/// We still need to do this part
86+
pub fn unreachable_amd_panic_documented() {
87+
if true {
88+
unreachable!()
89+
} else {
90+
panic!()
91+
}
92+
}
93+
7294
/// This is okay because it is private
7395
fn unwrap_private() {
7496
let result = Err("Hi");
@@ -93,3 +115,8 @@ fn inner_body_private(opt: Option<u32>) {
93115
}
94116
});
95117
}
118+
119+
/// This is okay because unreachable
120+
pub fn unreachable() {
121+
unreachable!("This function panics")
122+
}

tests/ui/doc_panics.stderr

+20-1
Original file line numberDiff line numberDiff line change
@@ -63,5 +63,24 @@ LL | panic!()
6363
| ^^^^^^^^
6464
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
6565

66-
error: aborting due to 4 previous errors
66+
error: docs for function which may panic missing `# Panics` section
67+
--> $DIR/doc_panics.rs:32:1
68+
|
69+
LL | / pub fn unreachable_and_panic() {
70+
LL | | if true {
71+
LL | | unreachable!()
72+
LL | | } else {
73+
LL | | panic!()
74+
LL | | }
75+
LL | | }
76+
| |_^
77+
|
78+
note: first possible panic found here
79+
--> $DIR/doc_panics.rs:36:9
80+
|
81+
LL | panic!()
82+
| ^^^^^^^^
83+
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
84+
85+
error: aborting due to 5 previous errors
6786

0 commit comments

Comments
 (0)