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

E0215: Callback signature mismatch

CodeCategoryStability
E0215SemanticPermanent

Explanation

The argument to a fn parameter (preview feature fn_params) must be a named function whose signature is exactly the parameter's: the same number of parameters, the same mode and type at every position, and the same result type. No conversion relates two fn types: an integer parameter is not widened, a borrow parameter does not stand in for a by-value one, and a result is not adapted.

Likely cause

The callback's declaration differs from the fn type in one parameter mode, one parameter type, the arity, or the result. Change the declaration to match, or write a wrapper function with exactly the expected signature and pass that.

Examples

Pass a function with a wider parameter

Requires --preview fn_params.

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

Pass a function with exactly the signature

Requires --preview fn_params.

fn apply(cb: fn(i32) -> i32, value: i32) -> i32 { cb(value) }
fn double(value: i32) -> i32 { value * 2 }
fn main() -> i32 { apply(double, 1) }

References