{"record":{"id":"b02791bd1a7b480d","repo":"yewstack/yew","slug":"missing-async-fn-resolve","errorCode":null,"errorMessage":"missing `async fn resolve`","messagePattern":"missing `async fn resolve`","errorType":"validation","errorClass":"syn::Error","httpStatus":null,"severity":"error","filePath":"packages/yew-link-macro/src/lib.rs","lineNumber":86,"sourceCode":"            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\n    let ctx_name = param_ident(params[0])?;\n    let input_name = param_ident(params[1])?;","sourceCodeStart":68,"sourceCodeEnd":104,"githubUrl":"https://github.com/yewstack/yew/blob/0e4a05472fac4e5fce1befe60fa4a1e43a36b6a3/packages/yew-link-macro/src/lib.rs#L68-L104","documentation":"`#[linked_state]` scans the impl block for a method named `resolve` (lib.rs:70); if none exists, this error is raised at the macro call site (lib.rs:85-86). `resolve` is the server-side async function whose body is moved into the generated `LinkedStateResolve::resolve`, so without it there is nothing to expand. Note this is the 'entirely absent' case — a `resolve` that exists but lacks `async` produces the separate error '`resolve` must be an async fn' at lib.rs:88-93.","triggerScenarios":"An impl block annotated with `#[linked_state]` that declares the associated types but contains no `async fn resolve(...)` method — for example only `type Context` and `type Input`.","commonSituations":"Declaring the trait shape first and intending to add the resolver later, renaming `resolve` to something like `fetch` or `load` during development, or copying a partial example that omitted the method body.","solutions":["Add `async fn resolve(ctx: &Self::Context, input: &Self::Input) -> Self` to the impl block","If you declared a custom `type Error`, make resolve return `Result<Self, Self::Error>`; otherwise return `Self` directly and the macro wraps it in `Ok(...)`","Keep the method named exactly `resolve` with exactly two reference parameters"],"exampleFix":"// before\n#[linked_state]\nimpl LinkedState for Post {\n    type Context = DbPool;\n    type Input = u32;\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 a method named `resolve`\n// fn has_resolve_fn(imp: &syn::ItemImpl) -> bool {\n//     imp.items.iter().any(|i| matches!(i, syn::ImplItem::Fn(f) if f.sig.ident == \"resolve\"))\n// }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Write `async fn resolve(ctx: &Ctx, input: &Input) -> Self` with exactly two reference parameters and the `async` keyword","Do not rename `resolve` — the macro only recognizes that exact identifier","If you declared `type Error`, make the resolve body return `Result<Self, Self::Error>`; otherwise return `Self` and let the macro wrap it in `Ok`"],"tags":["rust","yew","linked-state","proc-macro","async","missing-method"],"backgroundTag":"proc-macro-missing-required-item","analyzedSha":"0e4a05472fac4e5fce1befe60fa4a1e43a36b6a3","analyzedAt":"2026-08-22T21:16:31.212Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}