slint-ui/slint · error
invalid argument for callback
Error message
invalid argument for callback {}::{} What it means
Same site as the arity check, but this panic is the unwrap failure on the individual pieces: either a callback argument type or the return type had no mapping in rust_primitive_type, so no Rust type could be produced for the generated invoker accessor. It means the live-preview generator encountered a callback signature (in a global) containing a type it cannot express in generated Rust.
Solutions
- Extend rust_primitive_type to map the callback's argument or return type (e.g. structs, models, enums) to a Rust primitive type
- Simplify the .slint callback signature to use only types the live-preview generator supports
- Check the callback return type first: the unwrap on rust_primitive_type(&callback.return_type) is the usual offender
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at internal/compiler/generator/rust_live_preview.rs:285 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of slint-ui/slint@3a7e700487 (2026-09-16).
Data as JSON: /api/errors/a16edef70b563893.
Report an issue: GitHub.
Appendix: source
Thrown at internal/compiler/generator/rust_live_preview.rs:289
let return_type = rust_primitive_type(&callback.return_type).unwrap();
let args_name =
(0..callback.args.len()).map(|i| format_ident!("arg_{}", i)).collect::<Vec<_>>();
let caller_ident = accessor_names::rust_accessor_ident(name, AccessorKind::Invoker);
property_and_callback_accessors.push(quote!(
#[allow(dead_code)]
pub fn #caller_ident(&self, #(#args_name : #callback_args,)*) -> #return_type {
self.0.borrow().invoke_global(#global_name, #prop_name, &[#(#args_name.into(),)*])
.try_into().unwrap_or_else(|_| panic!("Invalid return type for callback {}::{}", #global_name, #prop_name))
}
));
let on_ident = accessor_names::rust_accessor_ident(name, AccessorKind::Handler);
property_and_callback_accessors.push(quote!(
#[allow(dead_code)]
pub fn #on_ident(&self, f: impl FnMut(#(#callback_args),*) -> #return_type + 'static) {
let f = ::core::cell::RefCell::new(f);
self.0.borrow().set_global_callback(#global_name, #prop_name, sp::Rc::new(move |values| {
let [#(#args_name,)*] = values else { panic!("invalid number of argument for callback {}::{}", #global_name, #prop_name) };
(*f.borrow_mut())(#(#args_name.clone().try_into().unwrap_or_else(|_| panic!("invalid argument for callback {}::{}", #global_name, #prop_name)),)*).into()
}))
}
));
} else if let Type::Function(function) = &p.ty {
let callback_args =
function.args.iter().map(|a| rust_primitive_type(a).unwrap()).collect::<Vec<_>>();
let return_type = rust_primitive_type(&function.return_type).unwrap();
let args_name =
(0..function.args.len()).map(|i| format_ident!("arg_{}", i)).collect::<Vec<_>>();
let caller_ident = accessor_names::rust_accessor_ident(name, AccessorKind::Invoker);
property_and_callback_accessors.push(quote!(
#[allow(dead_code)]
pub fn #caller_ident(&self, #(#args_name : #callback_args,)*) -> #return_type {
self.0.borrow().invoke_global(#global_name, #prop_name, &[#(#args_name.into(),)*])
.try_into().unwrap_or_else(|_| panic!("Invalid return type for function {}::{}", #global_name, #prop_name))
}
));
} else {View on GitHub (pinned to 3a7e700487)