2020-09-09 21:02:34 +00:00
|
|
|
#![warn(clippy::panic_in_result_fn)]
|
2020-11-17 16:01:22 +00:00
|
|
|
#![allow(clippy::unnecessary_wraps)]
|
2020-08-27 23:18:05 +00:00
|
|
|
struct A;
|
|
|
|
|
|
|
|
impl A {
|
|
|
|
fn result_with_panic() -> Result<bool, String> // should emit lint
|
2023-07-28 19:35:48 +00:00
|
|
|
//~^ ERROR: used `panic!()` or assertion in a function that returns `Result`
|
2020-08-27 23:18:05 +00:00
|
|
|
{
|
|
|
|
panic!("error");
|
|
|
|
}
|
|
|
|
|
|
|
|
fn result_with_unimplemented() -> Result<bool, String> // should emit lint
|
|
|
|
{
|
|
|
|
unimplemented!();
|
|
|
|
}
|
|
|
|
|
|
|
|
fn result_with_unreachable() -> Result<bool, String> // should emit lint
|
|
|
|
{
|
|
|
|
unreachable!();
|
|
|
|
}
|
|
|
|
|
2020-08-27 23:55:23 +00:00
|
|
|
fn result_with_todo() -> Result<bool, String> // should emit lint
|
2020-08-27 23:18:05 +00:00
|
|
|
{
|
2020-08-27 23:55:23 +00:00
|
|
|
todo!("Finish this");
|
2020-08-27 23:18:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn other_with_panic() // should not emit lint
|
|
|
|
{
|
|
|
|
panic!("");
|
|
|
|
}
|
|
|
|
|
|
|
|
fn other_with_unreachable() // should not emit lint
|
|
|
|
{
|
|
|
|
unreachable!();
|
|
|
|
}
|
|
|
|
|
|
|
|
fn other_with_unimplemented() // should not emit lint
|
|
|
|
{
|
|
|
|
unimplemented!();
|
|
|
|
}
|
|
|
|
|
2020-08-27 23:55:23 +00:00
|
|
|
fn other_with_todo() // should not emit lint
|
2020-08-27 23:18:05 +00:00
|
|
|
{
|
2020-08-27 23:55:23 +00:00
|
|
|
todo!("finish this")
|
2020-08-27 23:18:05 +00:00
|
|
|
}
|
|
|
|
|
2020-08-27 23:55:23 +00:00
|
|
|
fn result_without_banned_functions() -> Result<bool, String> // should not emit lint
|
2020-08-27 23:18:05 +00:00
|
|
|
{
|
2020-08-27 23:55:23 +00:00
|
|
|
Ok(true)
|
2020-08-27 23:18:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-29 23:17:53 +00:00
|
|
|
fn function_result_with_panic() -> Result<bool, String> // should emit lint
|
2023-07-28 19:35:48 +00:00
|
|
|
//~^ ERROR: used `panic!()` or assertion in a function that returns `Result`
|
2020-08-29 23:17:53 +00:00
|
|
|
{
|
|
|
|
panic!("error");
|
|
|
|
}
|
|
|
|
|
2024-05-19 15:08:36 +00:00
|
|
|
fn in_closure() -> Result<bool, String> {
|
|
|
|
let c = || panic!();
|
|
|
|
c()
|
|
|
|
}
|
|
|
|
|
2020-08-29 23:17:53 +00:00
|
|
|
fn todo() {
|
|
|
|
println!("something");
|
|
|
|
}
|
|
|
|
|
|
|
|
fn function_result_with_custom_todo() -> Result<bool, String> // should not emit lint
|
|
|
|
{
|
|
|
|
todo();
|
|
|
|
Ok(true)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() -> Result<(), String> {
|
|
|
|
todo!("finish main method");
|
|
|
|
Ok(())
|
|
|
|
}
|