diff options
| author | dswij <dswijj@gmail.com> | 2021-10-22 13:36:13 +0800 |
|---|---|---|
| committer | Dharma Saputra Wijaya <dswijj@gmail.com> | 2021-10-26 21:21:46 +0800 |
| commit | d4196d029314c494d84aed97043b2eb84ecdea5b (patch) | |
| tree | 07eec22675dd9268eb9dc45080c90701037b7b72 | |
| parent | 075996efd788613af0e19c0a241a81b1584b4cd1 (diff) | |
| download | rust-d4196d029314c494d84aed97043b2eb84ecdea5b.tar.gz rust-d4196d029314c494d84aed97043b2eb84ecdea5b.zip | |
Add #7859 FP test case for `question_mark`
| -rw-r--r-- | tests/ui/question_mark.rs | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/tests/ui/question_mark.rs b/tests/ui/question_mark.rs index ca3722371f5..fc68a42e46f 100644 --- a/tests/ui/question_mark.rs +++ b/tests/ui/question_mark.rs @@ -2,6 +2,9 @@ #![allow(unreachable_code)] #![allow(clippy::unnecessary_wraps)] +use std::env; +use std::path::PathBuf; + fn some_func(a: Option<u32>) -> Option<u32> { if a.is_none() { return None; @@ -134,7 +137,11 @@ fn func() -> Option<i32> { Some(0) } -fn result_func(x: Result<i32, &str>) -> Result<i32, &str> { +fn func_returning_result() -> Result<i32, String> { + Ok(1) +} + +fn result_func(x: Result<i32, String>) -> Result<i32, String> { let _ = if let Ok(x) = x { x } else { return x }; if x.is_err() { @@ -145,9 +152,21 @@ fn result_func(x: Result<i32, &str>) -> Result<i32, &str> { let y = if let Ok(x) = x { x } else { - return Err("some error"); + return Err("some error".to_string()); }; + // issue #7859 + // no warning + let _ = if let Ok(x) = func_returning_result() { + x + } else { + return Err("some error".to_string()); + }; + + if func_returning_result().is_err() { + return func_returning_result(); + } + Ok(y) } |
