{"record":{"id":"c443395d5d070a59","repo":"bevyengine/bevy","slug":"only-one-source-is-allowed-for-substates","errorCode":null,"errorMessage":"Only one source is allowed for SubStates","messagePattern":"Only one source is allowed for SubStates","errorType":"exception","errorClass":"syn::Error","httpStatus":null,"severity":"error","filePath":"crates/bevy_state/macros/src/states.rs","lineNumber":72,"sourceCode":"                    source_value,\n                });\n                Ok(())\n            });\n            match source {\n                Some(value) => Ok(value),\n                None => match value {\n                    Ok(_) => Err(syn::Error::new(\n                        ast.span(),\n                        \"Couldn't parse SubStates source\",\n                    )),\n                    Err(e) => Err(e),\n                },\n            }\n        })\n        .collect::<Result<Vec<_>>>()?;\n\n    if result.len() > 1 {\n        return Err(syn::Error::new(\n            ast.span(),\n            \"Only one source is allowed for SubStates\",\n        ));\n    }\n\n    let Some(result) = result.pop() else {\n        return Err(syn::Error::new(ast.span(), \"SubStates require a source\"));\n    };\n\n    Ok(result)\n}\n\npub fn derive_substates(input: TokenStream) -> TokenStream {\n    let ast = parse_macro_input!(input as DeriveInput);\n    let sources = parse_sources_attr(&ast).expect(\"Failed to parse substate sources\");\n\n    let generics = ast.generics;\n    let (impl_generics, ty_generics, where_clause) = generics.split_for_impl();","sourceCodeStart":54,"sourceCodeEnd":90,"githubUrl":"https://github.com/bevyengine/bevy/blob/396ca727080776bd313bb892423b7d94e03b81b4/crates/bevy_state/macros/src/states.rs#L54-L90","documentation":"Compile-time error from derive(SubStates) (states.rs:70-75): parse_sources_attr collects one Source per parsed `#[source(...)]` attribute/meta and rejects result.len() > 1. A SubStates type has exactly one upstream state, so multiple `#[source(...)]` attributes — or multiple `Type = value` pairs inside one — are rejected.","triggerScenarios":"Stacking `#[source(A = a)] #[source(B = b)]` on one enum; writing `#[source(A = a, B = b)]` with two pairs in a single attribute.","commonSituations":"Trying to make a substate depend on two parent states (not supported — use a States pair/combinator instead); copy-pasting source attributes during refactoring.","solutions":["Keep exactly one `#[source(ParentState = Value)]` attribute with one pair","If two upstream states are needed, model the combination as a parent States enum (e.g. a tuple state) and source from that"],"exampleFix":"// before — two sources\n#[derive(SubStates, ...)]\n#[source(GameState = GameState::Playing)]\n#[source(UiState = UiState::Open)]\nenum MenuState { Root, Settings }\n\n// after — one combined parent state drives the substate\n#[derive(SubStates, ...)]\n#[source(GameState = GameState::Playing)]\nenum MenuState { Root, Settings }","handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["One substate, one source attribute, one `Type = value` pair","Model multi-parent dependencies as a combined parent States enum instead of multiple sources"],"tags":["bevy","states","proc-macro","derive","compile-error"],"backgroundTag":"derive-macro-attribute-invalid","analyzedSha":"396ca727080776bd313bb892423b7d94e03b81b4","analyzedAt":"2026-08-20T16:12:39.808Z","contentChangedAt":"2026-08-20T16:12:39.808Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}