rust/tests/ui/panic_in_result_fn.rs

87 lines
1.7 KiB
Rust
Raw Normal View History

2020-09-09 16:02:34 -05:00
#![warn(clippy::panic_in_result_fn)]
2020-11-17 10:01:22 -06:00
#![allow(clippy::unnecessary_wraps)]
struct A;
impl A {
fn result_with_panic() -> Result<bool, String> // should emit lint
//~^ ERROR: used `panic!()` or assertion in a function that returns `Result`
{
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 18:55:23 -05:00
fn result_with_todo() -> Result<bool, String> // should emit lint
{
2020-08-27 18:55:23 -05: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 18:55:23 -05:00
fn other_with_todo() // should not emit lint
{
2020-08-27 18:55:23 -05:00
todo!("finish this")
}
2020-08-27 18:55:23 -05:00
fn result_without_banned_functions() -> Result<bool, String> // should not emit lint
{
2020-08-27 18:55:23 -05:00
Ok(true)
}
}
fn function_result_with_panic() -> Result<bool, String> // should emit lint
//~^ ERROR: used `panic!()` or assertion in a function that returns `Result`
{
panic!("error");
}
fn in_closure() -> Result<bool, String> {
let c = || panic!();
c()
}
fn todo() {
println!("something");
}
fn function_result_with_custom_todo() -> Result<bool, String> // should not emit lint
{
todo();
Ok(true)
}
2024-09-11 11:58:05 -05:00
fn issue_13381<const N: usize>() -> Result<(), String> {
const {
if N == 0 {
panic!();
}
}
Ok(())
}
fn main() -> Result<(), String> {
todo!("finish main method");
Ok(())
}