Some(0)
}
-fn result_func(x: Result<i32, &str>) -> Result<i32, &str> {
+fn func_returning_result() -> Result<i32, i32> {
+ Ok(1)
+}
+
+fn result_func(x: Result<i32, i32>) -> Result<i32, i32> {
let _ = x?;
x?;
let y = if let Ok(x) = x {
x
} else {
- return Err("some error");
+ return Err(0);
+ };
+
+ // issue #7859
+ // no warning
+ let _ = if let Ok(x) = func_returning_result() {
+ x
+ } else {
+ return Err(0);
};
+ // no warning
+ if func_returning_result().is_err() {
+ return func_returning_result();
+ }
+
Ok(y)
}
+// see issue #8019
+pub enum NotOption {
+ None,
+ First,
+ AfterFirst,
+}
+
+fn obj(_: i32) -> Result<(), NotOption> {
+ Err(NotOption::First)
+}
+
+fn f() -> NotOption {
+ if obj(2).is_err() {
+ return NotOption::None;
+ }
+ NotOption::First
+}
+
fn main() {
some_func(Some(42));
some_func(None);
func();
let _ = result_func(Ok(42));
+ let _ = f();
}