Skip to content

Commit d4196d0

Browse files
committed
Add rust-lang#7859 FP test case for question_mark
1 parent 075996e commit d4196d0

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

tests/ui/question_mark.rs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
#![allow(unreachable_code)]
33
#![allow(clippy::unnecessary_wraps)]
44

5+
use std::env;
6+
use std::path::PathBuf;
7+
58
fn some_func(a: Option<u32>) -> Option<u32> {
69
if a.is_none() {
710
return None;
@@ -134,7 +137,11 @@ fn func() -> Option<i32> {
134137
Some(0)
135138
}
136139

137-
fn result_func(x: Result<i32, &str>) -> Result<i32, &str> {
140+
fn func_returning_result() -> Result<i32, String> {
141+
Ok(1)
142+
}
143+
144+
fn result_func(x: Result<i32, String>) -> Result<i32, String> {
138145
let _ = if let Ok(x) = x { x } else { return x };
139146

140147
if x.is_err() {
@@ -145,9 +152,21 @@ fn result_func(x: Result<i32, &str>) -> Result<i32, &str> {
145152
let y = if let Ok(x) = x {
146153
x
147154
} else {
148-
return Err("some error");
155+
return Err("some error".to_string());
149156
};
150157

158+
// issue #7859
159+
// no warning
160+
let _ = if let Ok(x) = func_returning_result() {
161+
x
162+
} else {
163+
return Err("some error".to_string());
164+
};
165+
166+
if func_returning_result().is_err() {
167+
return func_returning_result();
168+
}
169+
151170
Ok(y)
152171
}
153172

0 commit comments

Comments
 (0)