rust/tests/ui/unnecessary_wraps.rs

124 lines
1.8 KiB
Rust
Raw Normal View History

2020-11-17 17:01:22 +01:00
#![warn(clippy::unnecessary_wraps)]
#![allow(clippy::no_effect)]
#![allow(clippy::needless_return)]
#![allow(clippy::if_same_then_else)]
2020-09-20 11:22:01 +02: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);
}
}
2020-09-26 09:27:10 +02:00
// should be linted
fn func2(a: bool, b: bool) -> Option<i32> {
if a && b {
return Some(10);
}
if a {
Some(20)
} else {
Some(30)
}
}
// public fns should not be linted
2020-09-26 09:27:10 +02:00
pub fn func3(a: bool) -> Option<i32> {
if a {
Some(1)
} else {
Some(1)
}
}
// should not be linted
2020-09-26 09:27:10 +02:00
fn func4(a: bool) -> Option<i32> {
if a {
Some(1)
} else {
None
}
}
// should be linted
2020-09-26 09:27:10 +02:00
fn func5() -> Option<i32> {
Some(1)
}
2020-09-20 17:11:28 +02:00
// should not be linted
2020-09-26 09:27:10 +02:00
fn func6() -> Option<i32> {
2020-09-20 17:11:28 +02:00
None
}
2020-09-20 11:22:01 +02:00
// should be linted
2020-09-26 09:27:10 +02:00
fn func7() -> Result<i32, ()> {
2020-09-20 11:22:01 +02:00
Ok(1)
}
// should not be linted
2020-09-26 09:27:10 +02:00
fn func8(a: bool) -> Result<i32, ()> {
2020-09-20 11:22:01 +02:00
if a {
Ok(1)
} else {
Err(())
}
}
2020-09-20 17:11:28 +02:00
// should not be linted
2020-09-26 09:27:10 +02:00
fn func9(a: bool) -> Result<i32, ()> {
2020-09-20 17:11:28 +02:00
Err(())
}
2020-10-18 10:17:45 +02:00
// should not be linted
fn func10() -> Option<()> {
unimplemented!()
}
2020-10-18 09:53:18 +02:00
struct A;
impl A {
// should not be linted
2020-10-18 10:17:45 +02:00
pub fn func11() -> Option<i32> {
2020-10-18 09:53:18 +02:00
Some(1)
}
// should be linted
2020-10-18 10:17:45 +02:00
fn func12() -> Option<i32> {
2020-10-18 09:53:18 +02:00
Some(1)
}
}
2020-11-14 11:25:54 +01:00
trait B {
// trait impls are not linted
fn func13() -> Option<i32> {
Some(1)
}
}
2020-11-14 11:39:41 +01:00
impl B for A {
2020-11-14 11:25:54 +01:00
// trait impls are not linted
fn func13() -> Option<i32> {
Some(0)
}
}
fn issue_6384(s: &str) -> Option<&str> {
Some(match s {
"a" => "A",
_ => return None,
})
}
fn main() {
// method calls are not linted
func1(true, true);
2020-09-26 09:27:10 +02:00
func2(true, true);
}