Sometimes E0308 on a try-expression can be fixed by wrapping with Ok. This is a somewhat common mistake in the form of a ?-expression appearing in tail position of a function that is expected to Result—
fn foo() -> Result<isize, ()> {
Ok(1)
}
fn bar() -> Result<isize, ()> {
foo()? // `Ok(foo()?)` would work
}
fn main() {}
However, not all type mismatches on ? are like this. Here's a negative example—
fn maybe_numbers() -> Result<Vec<i32>, ()> {
Ok(vec![1, 2, 3])
}
fn try_it() -> Result<String, ()> {
let n: i32 = maybe_numbers()?; // `Ok(maybe_numbers()?)` is not the right move here
Ok(format!("{:?}", n))
}
fn main() {}
We want to suggest Ok-wrapping when that's the correct fix. (This issue is being filed because a previous attempt at this suggestion had too many false positives and is likely to be removed.)
See discussion on #52537 for one idea on how to proceed.
Sometimes E0308 on a try-expression can be fixed by wrapping with
Ok. This is a somewhat common mistake in the form of a?-expression appearing in tail position of a function that is expected toResult—However, not all type mismatches on
?are like this. Here's a negative example—We want to suggest
Ok-wrapping when that's the correct fix. (This issue is being filed because a previous attempt at this suggestion had too many false positives and is likely to be removed.)See discussion on #52537 for one idea on how to proceed.