]> git.proxmox.com Git - rustc.git/blob - src/tools/clippy/tests/ui/panic_in_result_fn.rs
New upstream version 1.58.1+dfsg1
[rustc.git] / src / tools / clippy / tests / ui / panic_in_result_fn.rs
1 #![warn(clippy::panic_in_result_fn)]
2 #![allow(clippy::unnecessary_wraps)]
3 struct A;
4
5 impl A {
6 fn result_with_panic() -> Result<bool, String> // should emit lint
7 {
8 panic!("error");
9 }
10
11 fn result_with_unimplemented() -> Result<bool, String> // should emit lint
12 {
13 unimplemented!();
14 }
15
16 fn result_with_unreachable() -> Result<bool, String> // should emit lint
17 {
18 unreachable!();
19 }
20
21 fn result_with_todo() -> Result<bool, String> // should emit lint
22 {
23 todo!("Finish this");
24 }
25
26 fn other_with_panic() // should not emit lint
27 {
28 panic!("");
29 }
30
31 fn other_with_unreachable() // should not emit lint
32 {
33 unreachable!();
34 }
35
36 fn other_with_unimplemented() // should not emit lint
37 {
38 unimplemented!();
39 }
40
41 fn other_with_todo() // should not emit lint
42 {
43 todo!("finish this")
44 }
45
46 fn result_without_banned_functions() -> Result<bool, String> // should not emit lint
47 {
48 Ok(true)
49 }
50 }
51
52 fn function_result_with_panic() -> Result<bool, String> // should emit lint
53 {
54 panic!("error");
55 }
56
57 fn todo() {
58 println!("something");
59 }
60
61 fn function_result_with_custom_todo() -> Result<bool, String> // should not emit lint
62 {
63 todo();
64 Ok(true)
65 }
66
67 fn main() -> Result<(), String> {
68 todo!("finish main method");
69 Ok(())
70 }