Skip to content

Commit 37f9782

Browse files
committed
Add test for checking a combination of unreachable and panic.
1 parent 6c73f98 commit 37f9782

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

tests/ui/doc_panics.rs

Lines changed: 22 additions & 0 deletions
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");

tests/ui/doc_panics.stderr

Lines changed: 20 additions & 1 deletion
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)