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