{"record":{"id":"a69cf6b31d10a98f","repo":"slint-ui/slint","slug":"vtable-cannot-be-mutable","errorCode":null,"errorMessage":"VTable cannot be mutable","messagePattern":"VTable cannot be mutable","errorType":"exception","errorClass":"proc_macro::Error","httpStatus":null,"severity":"error","filePath":"helper_crates/vtable/macro/macro.rs","lineNumber":313,"sourceCode":"                sig_extern.inputs.push(typed_arg.clone());\n\n                // check for the vtable\n                let ptr_target = match &param.ty {\n                    Type::Ptr(TypePtr { mutability, elem, .. }) => {\n                        Some((matches!(mutability, PointerMutability::Mut(_)), elem))\n                    }\n                    Type::Reference(TypeReference { mutability, elem, .. }) => {\n                        Some((mutability.is_some(), elem))\n                    }\n                    _ => None,\n                };\n                if let Some((is_mut, elem)) = ptr_target\n                    && let Type::Path(p) = &**elem\n                    && let Some(pointer_to) = p.path.get_ident()\n                    && pointer_to == &vtable_name\n                {\n                    if is_mut {\n                        return Error::new(p.span(), \"VTable cannot be mutable\")\n                            .to_compile_error()\n                            .into();\n                    }\n                    if call_code.is_some() || !sig.inputs.is_empty() {\n                        return Error::new(p.span(), \"VTable pointer need to be the first\")\n                            .to_compile_error()\n                            .into();\n                    }\n                    call_code = Some(quote!(vtable as _,));\n                    continue;\n                }\n\n                let (is_pin, self_ty) = match is_pin(&param.ty) {\n                    Some(t) => (true, t),\n                    None => (false, &param.ty),\n                };\n\n                // check for self","sourceCodeStart":295,"sourceCodeEnd":331,"githubUrl":"https://github.com/slint-ui/slint/blob/bb937076de3f7919766c1f25e2e969367cf77e9a/helper_crates/vtable/macro/macro.rs#L295-L331","documentation":"In a #[vtable] trait method, the first parameter may be a *const pointer to the vtable itself (the dispatch entry). The macro forbids declaring that vtable pointer as *mut, because vtables are shared immutable dispatch tables; mutating one would be undefined behavior.","triggerScenarios":"Declaring a vtable method whose first argument is `*mut MyVTable` (or &mut) instead of `*const MyVTable`.","commonSituations":"Writing 'mutable-looking' method signatures by habit when defining raw-pointer vtable methods; confusing the self-pointer parameter (VRefMut) with the vtable pointer parameter.","solutions":["Change the vtable pointer parameter to *const MyVTable.","If you intended mutability of the instance, use VRefMut<Self> as the first parameter instead of a vtable pointer."],"exampleFix":"// before\nfn dispatch(vt: *mut MyVTable);\n// after\nfn dispatch(vt: *const MyVTable);","handlingStrategy":"validation","validationCode":"// signature check: vtable ptr must be *const\nfn dispatch(vt: *const MyVTable);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always use *const for vtable pointer parameters.","Use VRefMut<Self> (not a mutable vtable pointer) when you need mutable access to the instance."],"tags":["proc-macro","const-correctness","compile-time","rust"],"backgroundTag":"type-mismatch","analyzedSha":"bb937076de3f7919766c1f25e2e969367cf77e9a","analyzedAt":"2026-09-16T01:37:20.251Z","contentChangedAt":"2026-09-16T01:37:20.251Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}