{"record":{"id":"0d5e4dc144d10f3a","repo":"bevyengine/bevy","slug":"conflicting-type-data-registration","errorCode":null,"errorMessage":"conflicting type data registration","messagePattern":"conflicting type data registration","errorType":"validation","errorClass":"syn::Error","httpStatus":null,"severity":"error","filePath":"crates/bevy_reflect/derive/src/container_attributes.rs","lineNumber":75,"sourceCode":"    /// The trait is registered with a custom function rather than an actual implementation.\n    Custom(Path, Span),\n}\n\nimpl TraitImpl {\n    /// Merges this [`TraitImpl`] with another.\n    ///\n    /// Update `self` with whichever value is not [`TraitImpl::NotImplemented`].\n    /// If `other` is [`TraitImpl::NotImplemented`], then `self` is not modified.\n    /// An error is returned if neither value is [`TraitImpl::NotImplemented`].\n    pub fn merge(&mut self, other: TraitImpl) -> Result<(), syn::Error> {\n        match (&self, other) {\n            (TraitImpl::NotImplemented, value) => {\n                *self = value;\n                Ok(())\n            }\n            (_, TraitImpl::NotImplemented) => Ok(()),\n            (_, TraitImpl::Implemented(span) | TraitImpl::Custom(_, span)) => {\n                Err(syn::Error::new(span, CONFLICTING_TYPE_DATA_MESSAGE))\n            }\n        }\n    }\n}\n\n/// A collection of attributes used for deriving `FromReflect`.\n#[derive(Clone, Default)]\npub(crate) struct FromReflectAttrs {\n    auto_derive: Option<LitBool>,\n}\n\nimpl FromReflectAttrs {\n    /// Returns true if `FromReflect` should be automatically derived as part of the `Reflect` derive.\n    pub fn should_auto_derive(&self) -> bool {\n        self.auto_derive.as_ref().is_none_or(LitBool::value)\n    }\n}\n","sourceCodeStart":57,"sourceCodeEnd":93,"githubUrl":"https://github.com/bevyengine/bevy/blob/396ca727080776bd313bb892423b7d94e03b81b4/crates/bevy_reflect/derive/src/container_attributes.rs#L57-L93","documentation":"The bevy_reflect derive stores each special registration (Clone, Debug, PartialEq, PartialOrd, Hash) as a single optional impl. While parsing `#[reflect(...)]`, the plain form (`#[reflect(Hash)]`, sets `Implemented`) and the custom-function form (`#[reflect(Hash(my_fn))]`, merges `Custom`) share that one slot; `TraitImpl::merge` (crates/bevy_reflect/derive/src/container_attributes.rs:67) returns the compile error \"conflicting type data registration\" when both sides already carry an implementation.","triggerScenarios":"Listing one of the specially-handled traits twice on the same type with implementations on both sides: `#[reflect(Hash, Hash(my_hash_fn))]`, `#[reflect(Debug(custom), Debug)]`, or two custom functions `#[reflect(Debug(a), Debug(b))]` — including across multiple `#[reflect(...)]` attribute lists.","commonSituations":"Copy-pasting reflect attributes and merging the lists by hand; upgrading old code that had `#[reflect(Hash)]` plus a newer custom-function registration added next to it instead of replacing it.","solutions":["Register each trait exactly once per type","If you need a custom function, use only the custom form: replace `#[reflect(Hash)]` with `#[reflect(my_hash_fn)]`-style `#[reflect(Hash(my_hash_fn))]`, not both","Consolidate everything into a single `#[reflect(...)]` list so duplicates are visually obvious"],"exampleFix":"// before: Hash registered twice -> conflicting type data registration\n#[derive(Reflect)]\n#[reflect(Hash, Hash(custom_hash_fn))]\nstruct Foo { ... }\n\n// after: single custom registration\n#[derive(Reflect)]\n#[reflect(Hash(custom_hash_fn))]\nstruct Foo { ... }","handlingStrategy":"validation","validationCode":"null","typeGuard":null,"tryCatchPattern":null,"preventionTips":["One `#[reflect(...)]` list per type; review it as a whole after refactors","Each of Clone/Debug/PartialEq/PartialOrd/Hash appears at most once, in either the plain or the custom-function form","When adding a custom fn registration, delete the plain `#[reflect(Hash)]` entry it replaces"],"tags":["bevy","reflect","derive-macro","proc-macro","compile-error"],"backgroundTag":"derive-macro-attribute-conflict","analyzedSha":"396ca727080776bd313bb892423b7d94e03b81b4","analyzedAt":"2026-08-20T16:12:39.808Z","contentChangedAt":"2026-08-20T16:12:39.808Z","schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}