{"record":{"id":"ad00f7d065ce8ea4","repo":"rust-lang/rust","slug":"no-guards-allowed-in-this-position","errorCode":null,"errorMessage":"no guards allowed in this position","messagePattern":"no guards allowed in this position","errorType":"validation","errorClass":"syn::Error","httpStatus":null,"severity":"error","filePath":"library/compiler-builtins/crates/libm-macros/src/parse.rs","lineNumber":198,"sourceCode":"    for arm in arms {\n        let Arm {\n            attrs,\n            pat,\n            guard,\n            fat_arrow_token: _,\n            body,\n            comma: _,\n        } = arm;\n\n        expect_empty_attrs(&attrs)?;\n\n        let keys = match pat {\n            syn::Pat::Wild(w) => vec![Ident::new(\"_\", w.span())],\n            _ => Parser::parse2(parse_ident_pat, pat.into_token_stream())?,\n        };\n\n        if let Some(guard) = guard {\n            let e = syn::Error::new(guard.0.span(), \"no guards allowed in this position\");\n            return Err(e);\n        }\n\n        for key in keys {\n            let inserted = res.insert(key.clone(), *body.clone());\n            if inserted.is_some() {\n                let e = syn::Error::new(key.span(), format!(\"key `{key}` specified twice\"));\n                return Err(e);\n            }\n        }\n    }\n\n    Ok(res)\n}\n\nfn expect_empty_attrs(attrs: &[Attribute]) -> syn::Result<()> {\n    if attrs.is_empty() {\n        return Ok(());","sourceCodeStart":180,"sourceCodeEnd":216,"githubUrl":"https://github.com/rust-lang/rust/blob/7088e4b63a9516ebfbfe2ab2d999cf01a528ac14/library/compiler-builtins/crates/libm-macros/src/parse.rs#L180-L216","documentation":"Match arms in fn_extra dispatch purely on function-name patterns and cannot carry `if` guards (parse.rs:197-200). A guard like `foo if cond => ...` is rejected because the macro needs deterministic name-keyed dispatch.","triggerScenarios":"Writing `fn_extra: match MACRO_FN_NAME { foo if some_cond => ... }`.","commonSituations":"Trying to add conditional logic per function; assuming full Rust match semantics apply.","solutions":["Remove the `if` guard from the arm.","Move the conditional logic into the arm body expression (e.g. an if/else inside the body)."],"exampleFix":"// before\nfn_extra: match MACRO_FN_NAME {\n    sin if cfg!(foo) => |x| x.sin(),\n    _ => |x| x,\n},\n// after\nfn_extra: match MACRO_FN_NAME {\n    sin => |x| if cfg!(foo) { x.sin() } else { x },\n    _ => |x| x,\n},","handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["fn_extra arms are name patterns only, no guards.","Push any runtime condition into the arm body expression."],"tags":["rust","proc-macro","libm","compile-time","validation"],"backgroundTag":null,"analyzedSha":"7088e4b63a9516ebfbfe2ab2d999cf01a528ac14","analyzedAt":"2026-08-10T14:17:03.603Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}