slint-ui/slint · error · syn::Error

Self pointer need to be the first

Error message

Self pointer need to be the first

What it means

Error "Self pointer need to be the first" thrown in slint-ui/slint.

Source

Thrown at helper_crates/vtable/macro/macro.rs:340

                    call_code = Some(quote!(vtable as _,));
                    continue;
                }

                let (is_pin, self_ty) = match is_pin(&param.ty) {
                    Some(t) => (true, t),
                    None => (false, &param.ty),
                };

                // check for self
                if let (true, mutability) = if match_generic_type(self_ty, "VRef", &vtable_name) {
                    (true, None)
                } else if match_generic_type(self_ty, "VRefMut", &vtable_name) {
                    (true, Some(Default::default()))
                } else {
                    (false, None)
                } {
                    if !sig.inputs.is_empty() {
                        return Error::new(param.span(), "Self pointer need to be the first")
                            .to_compile_error()
                            .into();
                    }

                    let const_or_mut = mutability.map_or_else(|| quote!(const), |x| quote!(#x));
                    has_self = true;
                    if !is_pin {
                        sig.inputs.push(FnArg::Receiver(Receiver {
                            attrs: param.attrs.clone(),
                            mutability: None,
                            self_token: Default::default(),
                            kind: ReceiverKind::Reference(Default::default(), None, mutability),
                        }));
                        call_code =
                            Some(quote!(#call_code <#self_ty>::from_raw(self.vtable, self.ptr),));
                        self_call =
                            Some(quote!(&#mutability (*(#arg_name.as_ptr() as *#const_or_mut T)),));
                    } else {

View on GitHub (pinned to 3fd8f2ec03)

Solutions

  1. Place the self pointer as the first field/member as required by the macro.
  2. Reorder the fields so the self pointer comes first.

When it happens

Trigger: Thrown at helper_crates/vtable/macro/macro.rs:340 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of slint-ui/slint@3fd8f2ec03 (2026-08-19). Data as JSON: /api/errors/ae1e540185398313. Report an issue: GitHub.