E0504: Question on non option
| Code | Category | Stability |
|---|---|---|
E0504 | Control flow | Permanent |
Explanation
The operand of ? is neither an exact specialization of the trusted std.option.Option producer nor an exact specialization of the trusted std.result.Result producer. Only those two standard-library types have Rue's built-in try behavior; an enum with the same variants is still a distinct, ordinary type.
Likely cause
The operand is a plain value, another type, or a user-defined Some/None or Ok/Err lookalike. Apply ? to a value produced by the standard Option or Result, or handle the operand's cases explicitly.
Examples
Apply try to a plain integer
fn main() -> i32 {
let value = 42?;
value
}
Apply try to a trusted Option
const option = @import("std/option.rue");
fn some_value() -> option.Option(i32) {
let O = option.Option(i32);
O.Some(42)
}
fn propagate() -> option.Option(i32) {
let O = option.Option(i32);
let value = some_value()?;
O.Some(value)
}
fn main() -> i32 {
propagate();
0
}