2020-09-24 12:49:22 +00:00
|
|
|
#![warn(clippy::panic_in_result_fn)]
|
2020-11-23 12:51:04 +00:00
|
|
|
#![allow(clippy::unnecessary_wraps)]
|
2020-09-24 12:49:22 +00:00
|
|
|
struct A;
|
|
|
|
|
|
|
|
impl A {
|
|
|
|
fn result_with_panic() -> Result<bool, String> // should emit lint
|
2023-08-24 19:32:12 +00:00
|
|
|
//~^ ERROR: used `panic!()` or assertion in a function that returns `Result`
|
2020-09-24 12:49:22 +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!();
|
|
|
|
}
|
|
|
|
|
|
|
|
fn result_with_todo() -> Result<bool, String> // should emit lint
|
|
|
|
{
|
|
|
|
todo!("Finish this");
|
|
|
|
}
|
|
|
|
|
|
|
|
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!();
|
|
|
|
}
|
|
|
|
|
|
|
|
fn other_with_todo() // should not emit lint
|
|
|
|
{
|
|
|
|
todo!("finish this")
|
|
|
|
}
|
|
|
|
|
|
|
|
fn result_without_banned_functions() -> Result<bool, String> // should not emit lint
|
|
|
|
{
|
|
|
|
Ok(true)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn function_result_with_panic() -> Result<bool, String> // should emit lint
|
2023-08-24 19:32:12 +00:00
|
|
|
//~^ ERROR: used `panic!()` or assertion in a function that returns `Result`
|
2020-09-24 12:49:22 +00:00
|
|
|
{
|
|
|
|
panic!("error");
|
|
|
|
}
|
|
|
|
|
2024-06-13 10:30:48 +00:00
|
|
|
fn in_closure() -> Result<bool, String> {
|
|
|
|
let c = || panic!();
|
|
|
|
c()
|
|
|
|
}
|
|
|
|
|
2020-09-24 12:49:22 +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(())
|
|
|
|
}
|