{"record":{"id":"c6be512ff8b5d5e5","repo":"rust-lang/rust","slug":"trait-name-is-mandatory-so-it-is-present","errorCode":null,"errorMessage":"Trait name is mandatory, so it is present","messagePattern":"Trait name is mandatory, so it is present","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"compiler/rustc_attr_parsing/src/attributes/proc_macro_attrs.rs","lineNumber":38,"sourceCode":"    const ALLOWED_TARGETS: AllowedTargets<'_> = PROC_MACRO_ALLOWED_TARGETS;\n    const STABILITY: AttributeStability = AttributeStability::Stable;\n    const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::ProcMacroAttribute;\n}\n\npub(crate) struct ProcMacroDeriveParser;\nimpl SingleAttributeParser for ProcMacroDeriveParser {\n    const PATH: &[Symbol] = &[sym::proc_macro_derive];\n    const ALLOWED_TARGETS: AllowedTargets<'_> = PROC_MACRO_ALLOWED_TARGETS;\n    const TEMPLATE: AttributeTemplate = template!(\n        List: &[\"TraitName\", \"TraitName, attributes(name1, name2, ...)\"],\n        \"https://doc.rust-lang.org/reference/procedural-macros.html#derive-macros\"\n    );\n    const STABILITY: AttributeStability = AttributeStability::Stable;\n\n    fn convert(cx: &mut AcceptContext<'_, '_>, args: &ArgParser) -> Option<AttributeKind> {\n        let (trait_name, helper_attrs) = parse_derive_like(cx, args, true)?;\n        Some(AttributeKind::ProcMacroDerive {\n            trait_name: trait_name.expect(\"Trait name is mandatory, so it is present\"),\n            helper_attrs,\n        })\n    }\n}\n\npub(crate) struct RustcBuiltinMacroParser;\nimpl SingleAttributeParser for RustcBuiltinMacroParser {\n    const PATH: &[Symbol] = &[sym::rustc_builtin_macro];\n    const ALLOWED_TARGETS: AllowedTargets<'_> =\n        AllowedTargets::AllowList(&[Allow(Target::MacroDef)]);\n    const TEMPLATE: AttributeTemplate =\n        template!(List: &[\"TraitName\", \"TraitName, attributes(name1, name2, ...)\"]);\n    const STABILITY: AttributeStability = unstable!(rustc_attrs);\n\n    fn convert(cx: &mut AcceptContext<'_, '_>, args: &ArgParser) -> Option<AttributeKind> {\n        let (builtin_name, helper_attrs) = parse_derive_like(cx, args, false)?;\n        Some(AttributeKind::RustcBuiltinMacro { builtin_name, helper_attrs })\n    }","sourceCodeStart":20,"sourceCodeEnd":56,"githubUrl":"https://github.com/rust-lang/rust/blob/7088e4b63a9516ebfbfe2ab2d999cf01a528ac14/compiler/rustc_attr_parsing/src/attributes/proc_macro_attrs.rs#L20-L56","documentation":"proc_macro_attrs.rs:38: ProcMacroDeriveParser::convert calls parse_derive_like(cx, args, true) (third arg true => name mandatory) then does trait_name.expect(\"Trait name is mandatory, so it is present\"). The contract: when the mandatory flag is true, parse_derive_like returns Some(trait_name), so the Option is always Some.","triggerScenarios":"Parsing #[proc_macro_derive(...)] where parse_derive_like returns (None, _) despite the mandatory flag, an internal contract violation in the derive-attribute parser.","commonSituations":"A regression in the proc_macro_derive attribute parser; not reachable by well-formed #[proc_macro_derive(TraitName)] on a normal toolchain.","solutions":["File a rustc ICE with the minimized #[proc_macro_derive(...)] repro.","Ensure the derive declaration has a trait name: #[proc_macro_derive(MyTrait)].","Bisect across nightlies.","Try stable to check whether it is a recent regression."],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always write #[proc_macro_derive(TraitName)] with an explicit trait name.","Treat a panic here as a compiler bug; file an ICE with the minimized declaration.","Bisect across nightlies with cargo bisect-rustc.","Try stable to confirm whether it is a regression."],"tags":["rust","proc-macro","derive","compiler-internal"],"backgroundTag":null,"analyzedSha":"7088e4b63a9516ebfbfe2ab2d999cf01a528ac14","analyzedAt":"2026-08-10T14:17:03.603Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}