E0505: Question outside result fn
| Code | Category | Stability |
|---|---|---|
E0505 | Control flow | Permanent |
Explanation
The operand of ? is a trusted standard-library Result, but the enclosing function does not return a trusted standard-library Result. On Err(e), ? immediately returns an Err(e) constructed with the enclosing function's Result type, so that return type must be std.result.Result(U, E).
Likely cause
A Result-producing call was followed by ? inside a function returning a plain value, Option, or a user-defined Result-shaped enum. Change the function to return the standard Result, handle Ok and Err explicitly with match, or remove ?.
Examples
Propagate Result from a plain-value function
const result = @import("std/result.rue");
fn fallible() -> result.Result(i32, i32) {
let R = result.Result(i32, i32);
R.Ok(42)
}
fn main() -> i32 {
fallible()?
}
Return trusted Result before propagating
const result = @import("std/result.rue");
fn fallible() -> result.Result(i32, i32) {
let R = result.Result(i32, i32);
R.Ok(42)
}
fn run() -> result.Result(i32, i32) {
let R = result.Result(i32, i32);
let value = fallible()?;
R.Ok(value)
}
fn main() -> i32 {
run();
0
}