E0503: Question outside option fn
| Code | Category | Stability |
|---|---|---|
E0503 | Control flow | Permanent |
Explanation
The operand of ? is a trusted standard-library Option, but the enclosing function does not return a trusted standard-library Option. On None, ? immediately returns None from that function, so its declared return type must be std.option.Option(U). The success payload types may differ.
Likely cause
An Option-producing call was followed by ? inside a function returning a plain value, Result, or a user-defined Option-shaped enum. Change the function to return the standard Option, handle Some and None explicitly with match, or remove ?.
Examples
Propagate Option from a plain-value function
fn main() -> i32 {
let value = @parse_i32("42")?;
value
}
Return trusted Option before propagating
const option = @import("std/option.rue");
fn parse() -> option.Option(i32) {
let O = option.Option(i32);
let value = @parse_i32("42")?;
O.Some(value)
}
fn main() -> i32 {
parse();
0
}