rust-clippy/tests/ui/unnecessary_wrap.rs

72 lines
1.1 KiB
Rust
Raw Normal View History

#![warn(clippy::unnecessary_wrap)]
#![allow(clippy::no_effect)]
#![allow(clippy::needless_return)]
#![allow(clippy::if_same_then_else)]
2020-09-20 09:22:01 +00:00
#![allow(dead_code)]
// should be linted
fn func1(a: bool, b: bool) -> Option<i32> {
if a && b {
return Some(42);
}
if a {
Some(-1);
Some(2)
} else {
return Some(1337);
}
}
// public fns should not be linted
pub fn func2(a: bool) -> Option<i32> {
if a {
Some(1)
} else {
Some(1)
}
}
// should not be linted
fn func3(a: bool) -> Option<i32> {
if a {
Some(1)
} else {
None
}
}
// should be linted
fn func4() -> Option<i32> {
Some(1)
}
2020-09-20 15:11:28 +00:00
// should not be linted
fn func5() -> Option<i32> {
None
}
2020-09-20 09:22:01 +00:00
// should be linted
2020-09-20 15:11:28 +00:00
fn func6() -> Result<i32, ()> {
2020-09-20 09:22:01 +00:00
Ok(1)
}
// should not be linted
2020-09-20 15:11:28 +00:00
fn func7(a: bool) -> Result<i32, ()> {
2020-09-20 09:22:01 +00:00
if a {
Ok(1)
} else {
Err(())
}
}
2020-09-20 15:11:28 +00:00
// should not be linted
fn func8(a: bool) -> Result<i32, ()> {
Err(())
}
fn main() {
// method calls are not linted
func1(true, true);
func2(true);
}