Add test cases

This commit is contained in:
Hirochika Matsumoto 2020-09-21 00:11:28 +09:00
parent 0335b8d6a7
commit 0e9d227c04
3 changed files with 27 additions and 7 deletions

View File

@ -42,13 +42,18 @@ fn func4() -> Option<i32> {
Some(1)
}
// should not be linted
fn func5() -> Option<i32> {
None
}
// should be linted
fn func5() -> Result<i32, ()> {
fn func6() -> Result<i32, ()> {
Ok(1)
}
// should not be linted
fn func6(a: bool) -> Result<i32, ()> {
fn func7(a: bool) -> Result<i32, ()> {
if a {
Ok(1)
} else {
@ -56,6 +61,11 @@ fn func6(a: bool) -> Result<i32, ()> {
}
}
// should not be linted
fn func8(a: bool) -> Result<i32, ()> {
Err(())
}
fn main() {
// method calls are not linted
func1(true, true);

View File

@ -42,13 +42,18 @@ fn func4() -> Option<i32> {
Some(1)
}
// should not be linted
fn func5() -> Option<i32> {
None
}
// should be linted
fn func5() -> Result<i32, ()> {
fn func6() -> Result<i32, ()> {
Ok(1)
}
// should not be linted
fn func6(a: bool) -> Result<i32, ()> {
fn func7(a: bool) -> Result<i32, ()> {
if a {
Ok(1)
} else {
@ -56,6 +61,11 @@ fn func6(a: bool) -> Result<i32, ()> {
}
}
// should not be linted
fn func8(a: bool) -> Result<i32, ()> {
Err(())
}
fn main() {
// method calls are not linted
func1(true, true);

View File

@ -36,16 +36,16 @@ LL | 1
|
error: this function returns unnecessarily wrapping data
--> $DIR/unnecessary_wrap.rs:46:1
--> $DIR/unnecessary_wrap.rs:51:1
|
LL | / fn func5() -> Result<i32, ()> {
LL | / fn func6() -> Result<i32, ()> {
LL | | Ok(1)
LL | | }
| |_^
|
help: factor this out to
|
LL | fn func5() -> i32 {
LL | fn func6() -> i32 {
LL | 1
|