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

E0214: Fn type outside parameter

CodeCategoryStability
E0214SemanticPermanent

Explanation

A function type fn(A, borrow B) -> R (preview feature fn_params) names a second-class callback: a parameter that a named function is passed to and that the body calls or forwards. The callback exists only for the duration of the call, so a fn type may be written only as the type of a by-value runtime parameter, including a parameter inside another fn type's parameter list. It cannot be a return type, a let or const annotation, a struct field or enum payload, an array element, a pointer pointee, a slice element, a type argument, or the type of a borrow, inout, or comptime parameter.

Likely cause

A function tried to store, return, or nest a callback. Take the callback as a by-value parameter and call or forward it inside the body; to keep behavior across calls, pass it again at each call, or name a function directly.

Examples

Return a callback

Requires --preview fn_params.

fn pick(cb: fn(i32) -> i32) -> fn(i32) -> i32 { cb }
fn main() -> i32 { 0 }

Take the callback as a parameter

Requires --preview fn_params.

fn apply(cb: fn(i32) -> i32, value: i32) -> i32 { 0 }
fn main() -> i32 { 0 }

References