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

E0216: Ineligible callback

CodeCategoryStability
E0216SemanticPermanent

Explanation

A fn parameter (preview feature fn_params) binds a named function: an ordinary monomorphic free function, a module-qualified function, a compile-time alias to one, or a receiverless associated function of a concrete type. Any other expression, and a function of a kind that has no plain callable address, is rejected: a method with a receiver, a generic function, an extern "C" or unchecked function, a -> type constructor, an accessor, and a builtin.

Likely cause

The argument is an expression rather than a function name, or it names a generic, foreign, unchecked, or receiver-taking function. Write a named wrapper function with the expected signature that calls the intended function, and pass the wrapper.

Examples

Pass an integer where a callback is expected by name

Requires --preview fn_params.

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

Name a monomorphic wrapper

Requires --preview fn_params.

fn identity(comptime T: type, value: T) -> T { value }
fn identity_i32(value: i32) -> i32 { identity(i32, value) }
fn apply(cb: fn(i32) -> i32, value: i32) -> i32 { cb(value) }
fn main() -> i32 { apply(identity_i32, 1) }

References