rust/tests/ui/panic_in_result_fn.rs

72 lines
1.3 KiB
Rust
Raw Normal View History

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)]
struct A;
impl A {
fn result_with_panic() -> Result<bool, String> // should emit lint
{
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:55:23 +00:00
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!();
}
2020-08-27 23:55:23 +00:00
fn other_with_todo() // should not emit lint
{
2020-08-27 23:55:23 +00:00
todo!("finish this")
}
2020-08-27 23:55:23 +00:00
fn result_without_banned_functions() -> Result<bool, String> // should not emit lint
{
2020-08-27 23:55:23 +00:00
Ok(true)
}
}
fn function_result_with_panic() -> Result<bool, String> // should emit lint
{
panic!("error");
}
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(())
}