diff options
| author | Hirochika Matsumoto <matsujika@gmail.com> | 2020-09-26 16:27:10 +0900 |
|---|---|---|
| committer | Hirochika Matsumoto <matsujika@gmail.com> | 2020-11-18 01:28:37 +0900 |
| commit | 6b55f3fec98fa8fd4ca15edbf1cc1ab86d22f08f (patch) | |
| tree | 6d32acad9de2dfc84c0c2bac787234f46c3dfc9a | |
| parent | cdb72df6f9f9d6946b0614b01e70bc9c46edfe89 (diff) | |
| download | rust-6b55f3fec98fa8fd4ca15edbf1cc1ab86d22f08f.tar.gz rust-6b55f3fec98fa8fd4ca15edbf1cc1ab86d22f08f.zip | |
Add test case
| -rw-r--r-- | tests/ui/unnecessary_wrap.rs | 28 | ||||
| -rw-r--r-- | tests/ui/unnecessary_wrap.stderr | 40 |
2 files changed, 53 insertions, 15 deletions
diff --git a/tests/ui/unnecessary_wrap.rs b/tests/ui/unnecessary_wrap.rs index f78a7604a5a..6037f5807d3 100644 --- a/tests/ui/unnecessary_wrap.rs +++ b/tests/ui/unnecessary_wrap.rs @@ -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 -pub fn func2(a: bool) -> Option<i32> { +pub fn func3(a: bool) -> Option<i32> { if a { Some(1) } else { @@ -27,7 +39,7 @@ pub fn func2(a: bool) -> Option<i32> { } // should not be linted -fn func3(a: bool) -> Option<i32> { +fn func4(a: bool) -> Option<i32> { if a { Some(1) } else { @@ -36,22 +48,22 @@ fn func3(a: bool) -> Option<i32> { } // should be linted -fn func4() -> Option<i32> { +fn func5() -> Option<i32> { Some(1) } // should not be linted -fn func5() -> Option<i32> { +fn func6() -> Option<i32> { None } // should be linted -fn func6() -> Result<i32, ()> { +fn func7() -> Result<i32, ()> { Ok(1) } // should not be linted -fn func7(a: bool) -> Result<i32, ()> { +fn func8(a: bool) -> Result<i32, ()> { if a { Ok(1) } else { @@ -60,12 +72,12 @@ fn func7(a: bool) -> Result<i32, ()> { } // should not be linted -fn func8(a: bool) -> Result<i32, ()> { +fn func9(a: bool) -> Result<i32, ()> { Err(()) } fn main() { // method calls are not linted func1(true, true); - func2(true); + func2(true, true); } diff --git a/tests/ui/unnecessary_wrap.stderr b/tests/ui/unnecessary_wrap.stderr index 7833ee4b213..a3481330e99 100644 --- a/tests/ui/unnecessary_wrap.stderr +++ b/tests/ui/unnecessary_wrap.stderr @@ -26,16 +26,42 @@ LL | } else { ... 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 | | } | |_^ | help: remove `Option` from the return type... | -LL | fn func4() -> i32 { +LL | fn func5() -> i32 { | ^^^ help: ...and change the returning expressions | @@ -43,21 +69,21 @@ LL | 1 | 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 | | } | |_^ | help: remove `Result` from the return type... | -LL | fn func6() -> i32 { +LL | fn func7() -> i32 { | ^^^ help: ...and change the returning expressions | LL | 1 | -error: aborting due to 3 previous errors +error: aborting due to 4 previous errors |
