Ruta graveolens  ·  notes from a language experiment  ·  cultivated since 2025

E0503: Question outside option fn

CodeCategoryStability
E0503Control flowPermanent

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
}

References