{"record":{"id":"063b303e8e8e527c","repo":"rust-lang/rust","slug":"no-attributes-allowed-in-this-position","errorCode":null,"errorMessage":"no attributes allowed in this position","messagePattern":"no attributes allowed in this position","errorType":"validation","errorClass":"syn::Error","httpStatus":null,"severity":"error","filePath":"library/compiler-builtins/crates/libm-macros/src/parse.rs","lineNumber":219,"sourceCode":"\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(());\n    }\n\n    let e = syn::Error::new(\n        attrs.first().unwrap().span(),\n        \"no attributes allowed in this position\",\n    );\n    Err(e)\n}\n\n/// Extract a named field from a map, raising an error if it doesn't exist.\nfn expect_field(v: &mut Vec<Mapping>, name: &str) -> syn::Result<Expr> {\n    let pos = v.iter().position(|v| v.name == name).ok_or_else(|| {\n        syn::Error::new(\n            Span::call_site(),\n            format!(\"missing expected field `{name}`\"),\n        )\n    })?;\n\n    Ok(v.remove(pos).expr)\n}\n","sourceCodeStart":201,"sourceCodeEnd":237,"githubUrl":"https://github.com/rust-lang/rust/blob/7088e4b63a9516ebfbfe2ab2d999cf01a528ac14/library/compiler-builtins/crates/libm-macros/src/parse.rs#L201-L237","documentation":"Attributes (e.g. `#[cfg(...)]`, `#[test]`) are not permitted on the fn_extra match expression itself nor on its individual arms. expect_empty_attrs() is called on both the match and each arm and rejects any attributes present (parse.rs:170, 190, 214-224).","triggerScenarios":"`fn_extra: #[cfg(test)] match MACRO_FN_NAME { ... }` or an arm like `#[attr] foo => ...`.","commonSituations":"Trying to conditionally compile arms; pasting attributes that are legal on normal match arms but not here.","solutions":["Remove the attribute from the match/arm.","Control which functions are included via the top-level attributes, skip, or only fields instead."],"exampleFix":"// before\nfn_extra: #[cfg(test)]\n    match MACRO_FN_NAME {\n        _ => |x| x,\n    },\n// after\nfn_extra: match MACRO_FN_NAME {\n    _ => |x| x,\n},","handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["fn_extra match and its arms must be attribute-free.","Use the top-level attributes field for per-function cfg attributes."],"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"}