mirror of
https://github.com/rust-lang/rust.git
synced 2025-04-28 11:07:42 +00:00
Add test case
This commit is contained in:
parent
cdb72df6f9
commit
6b55f3fec9
@ -17,8 +17,20 @@ fn func1(a: bool, b: bool) -> Option<i32> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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
|
// public fns should not be linted
|
||||||
pub fn func2(a: bool) -> Option<i32> {
|
pub fn func3(a: bool) -> Option<i32> {
|
||||||
if a {
|
if a {
|
||||||
Some(1)
|
Some(1)
|
||||||
} else {
|
} else {
|
||||||
@ -27,7 +39,7 @@ pub fn func2(a: bool) -> Option<i32> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// should not be linted
|
// should not be linted
|
||||||
fn func3(a: bool) -> Option<i32> {
|
fn func4(a: bool) -> Option<i32> {
|
||||||
if a {
|
if a {
|
||||||
Some(1)
|
Some(1)
|
||||||
} else {
|
} else {
|
||||||
@ -36,22 +48,22 @@ fn func3(a: bool) -> Option<i32> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// should be linted
|
// should be linted
|
||||||
fn func4() -> Option<i32> {
|
fn func5() -> Option<i32> {
|
||||||
Some(1)
|
Some(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
// should not be linted
|
// should not be linted
|
||||||
fn func5() -> Option<i32> {
|
fn func6() -> Option<i32> {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
// should be linted
|
// should be linted
|
||||||
fn func6() -> Result<i32, ()> {
|
fn func7() -> Result<i32, ()> {
|
||||||
Ok(1)
|
Ok(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
// should not be linted
|
// should not be linted
|
||||||
fn func7(a: bool) -> Result<i32, ()> {
|
fn func8(a: bool) -> Result<i32, ()> {
|
||||||
if a {
|
if a {
|
||||||
Ok(1)
|
Ok(1)
|
||||||
} else {
|
} else {
|
||||||
@ -60,12 +72,12 @@ fn func7(a: bool) -> Result<i32, ()> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// should not be linted
|
// should not be linted
|
||||||
fn func8(a: bool) -> Result<i32, ()> {
|
fn func9(a: bool) -> Result<i32, ()> {
|
||||||
Err(())
|
Err(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
// method calls are not linted
|
// method calls are not linted
|
||||||
func1(true, true);
|
func1(true, true);
|
||||||
func2(true);
|
func2(true, true);
|
||||||
}
|
}
|
||||||
|
@ -26,16 +26,42 @@ LL | } else {
|
|||||||
...
|
...
|
||||||
|
|
||||||
error: this function returns unnecessarily wrapping data
|
error: this function returns unnecessarily wrapping data
|
||||||
--> $DIR/unnecessary_wrap.rs:39:1
|
--> $DIR/unnecessary_wrap.rs:21:1
|
||||||
|
|
|
|
||||||
LL | / fn func4() -> Option<i32> {
|
LL | / fn func2(a: bool, b: bool) -> Option<i32> {
|
||||||
|
LL | | if a && b {
|
||||||
|
LL | | return Some(10);
|
||||||
|
LL | | }
|
||||||
|
... |
|
||||||
|
LL | | }
|
||||||
|
LL | | }
|
||||||
|
| |_^
|
||||||
|
|
|
||||||
|
help: remove `Option` from the return type...
|
||||||
|
|
|
||||||
|
LL | fn func2(a: bool, b: bool) -> i32 {
|
||||||
|
| ^^^
|
||||||
|
help: ...and change the returning expressions
|
||||||
|
|
|
||||||
|
LL | return 10;
|
||||||
|
LL | }
|
||||||
|
LL | if a {
|
||||||
|
LL | 20
|
||||||
|
LL | } else {
|
||||||
|
LL | 30
|
||||||
|
|
|
||||||
|
|
||||||
|
error: this function returns unnecessarily wrapping data
|
||||||
|
--> $DIR/unnecessary_wrap.rs:51:1
|
||||||
|
|
|
||||||
|
LL | / fn func5() -> Option<i32> {
|
||||||
LL | | Some(1)
|
LL | | Some(1)
|
||||||
LL | | }
|
LL | | }
|
||||||
| |_^
|
| |_^
|
||||||
|
|
|
|
||||||
help: remove `Option` from the return type...
|
help: remove `Option` from the return type...
|
||||||
|
|
|
|
||||||
LL | fn func4() -> i32 {
|
LL | fn func5() -> i32 {
|
||||||
| ^^^
|
| ^^^
|
||||||
help: ...and change the returning expressions
|
help: ...and change the returning expressions
|
||||||
|
|
|
|
||||||
@ -43,21 +69,21 @@ LL | 1
|
|||||||
|
|
|
|
||||||
|
|
||||||
error: this function returns unnecessarily wrapping data
|
error: this function returns unnecessarily wrapping data
|
||||||
--> $DIR/unnecessary_wrap.rs:49:1
|
--> $DIR/unnecessary_wrap.rs:61:1
|
||||||
|
|
|
|
||||||
LL | / fn func6() -> Result<i32, ()> {
|
LL | / fn func7() -> Result<i32, ()> {
|
||||||
LL | | Ok(1)
|
LL | | Ok(1)
|
||||||
LL | | }
|
LL | | }
|
||||||
| |_^
|
| |_^
|
||||||
|
|
|
|
||||||
help: remove `Result` from the return type...
|
help: remove `Result` from the return type...
|
||||||
|
|
|
|
||||||
LL | fn func6() -> i32 {
|
LL | fn func7() -> i32 {
|
||||||
| ^^^
|
| ^^^
|
||||||
help: ...and change the returning expressions
|
help: ...and change the returning expressions
|
||||||
|
|
|
|
||||||
LL | 1
|
LL | 1
|
||||||
|
|
|
|
||||||
|
|
||||||
error: aborting due to 3 previous errors
|
error: aborting due to 4 previous errors
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user