{"record":{"id":"196078496435450e","repo":"yewstack/yew","slug":"missing-type-context","errorCode":null,"errorMessage":"missing `type Context`","messagePattern":"missing `type Context`","errorType":"validation","errorClass":"syn::Error","httpStatus":null,"severity":"error","filePath":"packages/yew-link-macro/src/lib.rs","lineNumber":84,"sourceCode":"        match item {\n            ImplItem::Type(t) if t.ident == \"Input\" => input_ty = Some(&t.ty),\n            ImplItem::Type(t) if t.ident == \"Context\" => context_ty = Some(&t.ty),\n            ImplItem::Type(t) if t.ident == \"Error\" => error_ty = Some(&t.ty),\n            ImplItem::Fn(f) if f.sig.ident == \"resolve\" => resolve_fn = Some(f),\n            other => {\n                return Err(syn::Error::new_spanned(\n                    other,\n                    \"#[linked_state] expects only `type Input`, `type Context`, `type Error` \\\n                     (optional), and `async fn resolve`\",\n                ));\n            }\n        }\n    }\n\n    let input_ty =\n        input_ty.ok_or_else(|| syn::Error::new(Span::call_site(), \"missing `type Input`\"))?;\n    let context_ty =\n        context_ty.ok_or_else(|| syn::Error::new(Span::call_site(), \"missing `type Context`\"))?;\n    let resolve_fn = resolve_fn\n        .ok_or_else(|| syn::Error::new(Span::call_site(), \"missing `async fn resolve`\"))?;\n\n    if resolve_fn.sig.asyncness.is_none() {\n        return Err(syn::Error::new_spanned(\n            resolve_fn.sig.fn_token,\n            \"`resolve` must be an async fn\",\n        ));\n    }\n\n    let params: Vec<_> = resolve_fn.sig.inputs.iter().collect();\n    if params.len() != 2 {\n        return Err(syn::Error::new_spanned(\n            &resolve_fn.sig.inputs,\n            \"`resolve` must take exactly two parameters: context and input references\",\n        ));\n    }\n","sourceCodeStart":66,"sourceCodeEnd":102,"githubUrl":"https://github.com/yewstack/yew/blob/0e4a05472fac4e5fce1befe60fa4a1e43a36b6a3/packages/yew-link-macro/src/lib.rs#L66-L102","documentation":"`#[linked_state]` requires the annotated `impl LinkedState for T` block to declare `type Context`, `type Input`, optional `type Error`, and `async fn resolve` (lib.rs:65-79). When the item walk finishes without finding an associated type named `Context`, the macro emits this error at the call site (lib.rs:83-84). `Context` becomes the `LinkedStateResolve::Context` dependency (e.g. a DB pool) injected into `resolve` on the server, so the codegen cannot proceed without it.","triggerScenarios":"An impl block under `#[linked_state]` that has `type Input` and `async fn resolve` but no `type Context = DbPool;` line. A differently named type would be rejected earlier by the 'expects only …' check, so this fires only when `Context` is absent.","commonSituations":"Writing a resolver that takes no external dependency and assuming `Context` is optional (only `Error` is), or trimming boilerplate from a doc example when copying it in.","solutions":["Add `type Context = YourDep;` naming the type `resolve`'s first parameter receives","If resolve truly needs no context, declare a unit-ish placeholder type (e.g. `type Context = ();`) and accept `_: &()`","Follow the documented skeleton exactly — Context, Input, optional Error, then the async fn"],"exampleFix":"// before\n#[linked_state]\nimpl LinkedState for Post {\n    type Input = u32;\n\n    async fn resolve(ctx: &DbPool, id: &u32) -> Self {\n        ctx.get_post(*id).await\n    }\n}\n\n// after\n#[linked_state]\nimpl LinkedState for Post {\n    type Context = DbPool;\n    type Input = u32;\n\n    async fn resolve(ctx: &DbPool, id: &u32) -> Self {\n        ctx.get_post(*id).await\n    }\n}","handlingStrategy":"validation","validationCode":"// Pre-flight: the impl block must contain `type Context` before adding the attribute\n// fn has_context_item(imp: &syn::ItemImpl) -> bool {\n//     imp.items.iter().any(|i| matches!(i, syn::ImplItem::Type(t) if t.ident == \"Context\"))\n// }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Fill in all three boilerplate items (Context, Input, resolve) in one edit; only `type Error` is optional","If resolve needs no dependency, declare `type Context = ();` rather than omitting the item","Keep the macro's doc example open when writing a new linked-state impl and diff your items against it"],"tags":["rust","yew","linked-state","proc-macro","associated-type"],"backgroundTag":"proc-macro-missing-required-item","analyzedSha":"0e4a05472fac4e5fce1befe60fa4a1e43a36b6a3","analyzedAt":"2026-08-22T21:16:31.212Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}