{"record":{"id":"9e8389801bc60756","repo":"slint-ui/slint","slug":"the-type-of-an-field-offset-member-in-the-vtabl","errorCode":null,"errorMessage":"The type of an #[field_offset] member in the vtable must be 'usize'","messagePattern":"The type of an #\\[field_offset\\] member in the vtable must be 'usize'","errorType":"exception","errorClass":"proc_macro::Error","httpStatus":null,"severity":"error","filePath":"helper_crates/vtable/macro/macro.rs","lineNumber":588,"sourceCode":"                    items: Vec::new(),\n                    ..generated_trait.clone()\n                });\n\n            let const_type = if let Some(o) = field\n                .attrs\n                .iter()\n                .position(|a| a.path().get_ident().map(|a| a == \"field_offset\").unwrap_or(false))\n            {\n                let a = field.attrs.remove(o);\n                let member_type = match a.parse_args::<Type>() {\n                    Err(e) => return e.to_compile_error().into(),\n                    Ok(ty) => ty,\n                };\n\n                match &field.ty {\n                    Type::Path(p) if p.path.get_ident().map(|i| i == \"usize\").unwrap_or(false) => {}\n                    ty => {\n                        return Error::new(\n                            ty.span(),\n                            \"The type of an #[field_offset] member in the vtable must be 'usize'\",\n                        )\n                        .to_compile_error()\n                        .into();\n                    }\n                }\n\n                // add `: Sized` to the trait in case it does not have it\n                if generated_trait_assoc_const.supertraits.is_empty() {\n                    generated_trait_assoc_const.colon_token = Some(Default::default());\n                    generated_trait_assoc_const.supertraits.push(parse_quote!(Sized));\n                }\n\n                let offset_type: Type = parse_quote!(vtable::FieldOffset<Self, #member_type>);\n\n                vtable_ctor.push(quote!(#ident: T::#ident.get_byte_offset(),));\n","sourceCodeStart":570,"sourceCodeEnd":606,"githubUrl":"https://github.com/slint-ui/slint/blob/bb937076de3f7919766c1f25e2e969367cf77e9a/helper_crates/vtable/macro/macro.rs#L570-L606","documentation":"Members of a #[vtable] struct annotated with #[field_offset(...)] represent byte offsets of fields in the concrete struct, so the macro requires them to be of type usize. Any other type on a #[field_offset] member is rejected at compile time.","triggerScenarios":"Declaring e.g. `#[field_offset(foo)] x: u32` or `*const u8` inside a #[vtable] struct instead of `usize`.","commonSituations":"Guessing the offset-member type when hand-writing a vtable; copying an ordinary struct field declaration for the offset member.","solutions":["Change the #[field_offset] member's type to usize.","Remove the #[field_offset] attribute if the member is not meant to be an offset."],"exampleFix":"// before\n#[vtable]\nstruct FooVTable {\n    #[field_offset(data)]\n    data_offset: u32,\n}\n// after\n#[vtable]\nstruct FooVTable {\n    #[field_offset(data)]\n    data_offset: usize,\n}","handlingStrategy":"validation","validationCode":"let _: usize = data_offset; // every #[field_offset] member is usize","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Type all #[field_offset] members as usize.","Only attach #[field_offset] to members that represent struct field offsets."],"tags":["proc-macro","type-mismatch","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"}