mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-23 23:34:48 +00:00
Update test for question_mark
to cover Result
This commit is contained in:
parent
687f3925da
commit
3fc99b6a33
@ -104,6 +104,21 @@ fn func() -> Option<i32> {
|
||||
Some(0)
|
||||
}
|
||||
|
||||
fn result_func(x: Result<i32, &str>) -> Result<i32, &str> {
|
||||
let _ = x?;
|
||||
|
||||
x?;
|
||||
|
||||
// No warning
|
||||
let y = if let Ok(x) = x {
|
||||
x
|
||||
} else {
|
||||
return Err("some error");
|
||||
};
|
||||
|
||||
Ok(y)
|
||||
}
|
||||
|
||||
fn main() {
|
||||
some_func(Some(42));
|
||||
some_func(None);
|
||||
@ -123,4 +138,6 @@ fn main() {
|
||||
returns_something_similar_to_option(so);
|
||||
|
||||
func();
|
||||
|
||||
let _ = result_func(Ok(42));
|
||||
}
|
||||
|
@ -134,6 +134,23 @@ fn func() -> Option<i32> {
|
||||
Some(0)
|
||||
}
|
||||
|
||||
fn result_func(x: Result<i32, &str>) -> Result<i32, &str> {
|
||||
let _ = if let Ok(x) = x { x } else { return x };
|
||||
|
||||
if x.is_err() {
|
||||
return x;
|
||||
}
|
||||
|
||||
// No warning
|
||||
let y = if let Ok(x) = x {
|
||||
x
|
||||
} else {
|
||||
return Err("some error");
|
||||
};
|
||||
|
||||
Ok(y)
|
||||
}
|
||||
|
||||
fn main() {
|
||||
some_func(Some(42));
|
||||
some_func(None);
|
||||
@ -153,4 +170,6 @@ fn main() {
|
||||
returns_something_similar_to_option(so);
|
||||
|
||||
func();
|
||||
|
||||
let _ = result_func(Ok(42));
|
||||
}
|
||||
|
@ -100,5 +100,19 @@ LL | | return None;
|
||||
LL | | }
|
||||
| |_____^ help: replace it with: `f()?;`
|
||||
|
||||
error: aborting due to 11 previous errors
|
||||
error: this if-let-else may be rewritten with the `?` operator
|
||||
--> $DIR/question_mark.rs:138:13
|
||||
|
|
||||
LL | let _ = if let Ok(x) = x { x } else { return x };
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `x?`
|
||||
|
||||
error: this block may be rewritten with the `?` operator
|
||||
--> $DIR/question_mark.rs:140:5
|
||||
|
|
||||
LL | / if x.is_err() {
|
||||
LL | | return x;
|
||||
LL | | }
|
||||
| |_____^ help: replace it with: `x?;`
|
||||
|
||||
error: aborting due to 13 previous errors
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user