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