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

E0709: Cannot infer cast target

CodeCategoryStability
E0709IntrinsicPermanent

Explanation

A context-directed numeric conversion has no target type to convert to. The stable @intCast and @bitCast intrinsics infer an integer result type from the surrounding annotation, parameter, or return position. When the floats preview is enabled, @int_to_float, @float_to_int, and @float_cast use the same contextual rule for their float or integer result; those floating-point intrinsics are unavailable without that preview gate.

Likely cause

The conversion result is discarded, stored in an unannotated binding, or passed only to a type-polymorphic operation such as @dbg, so no surrounding use requires the concrete integer or floating-point result type expected by that intrinsic.

Examples

Leave an integer cast target unconstrained

fn main() -> i32 {
    let source: u64 = 5;
    @dbg(@intCast(source));
    0
}

Annotate the cast result

fn main() -> i32 {
    let source: u64 = 5;
    let converted: i32 = @intCast(source);
    converted
}

References