{"record":{"id":"622e417fef83732d","repo":"bevyengine/bevy","slug":"substates-require-a-source","errorCode":null,"errorMessage":"SubStates require a source","messagePattern":"SubStates require a source","errorType":"exception","errorClass":"syn::Error","httpStatus":null,"severity":"error","filePath":"crates/bevy_state/macros/src/states.rs","lineNumber":79,"sourceCode":"                    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();\n\n    let mut base_trait_path = bevy_state_path();\n    base_trait_path.segments.push(format_ident!(\"state\").into());\n\n    let mut trait_path = base_trait_path.clone();\n    trait_path.segments.push(format_ident!(\"SubStates\").into());\n","sourceCodeStart":61,"sourceCodeEnd":97,"githubUrl":"https://github.com/bevyengine/bevy/blob/396ca727080776bd313bb892423b7d94e03b81b4/crates/bevy_state/macros/src/states.rs#L61-L97","documentation":"Compile-time error from derive(SubStates) (states.rs:77-80): after dedup checks, result.pop() finds nothing, meaning the derive had no parseable `#[source(...)]` attribute at all. SubStates must declare which parent state and value they are derived from; a plain derive cannot generate that.","triggerScenarios":"`#[derive(SubStates)]` on an enum with no `#[source]` attribute; the source attribute misspelled (e.g. `#[sources]`) so it is ignored.","commonSituations":"Converting a States enum to SubStates and deleting the attribute; upgrading from a Bevy version with different source syntax; attribute-name typos.","solutions":["Add `#[source(ParentStateType = ParentState::Variant)]` to the derived enum","Double-check the attribute spelling — anything other than `source` is silently ignored"],"exampleFix":"// before\n#[derive(SubStates, Debug, Hash, PartialEq, Eq, Clone)]\nenum MenuState { MainMenu, Paused }\n\n// after\n#[derive(SubStates, Debug, Hash, PartialEq, Eq, Clone)]\n#[source(AppState = AppState::InGame)]\nenum MenuState { MainMenu, Paused }","handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always pair `#[derive(SubStates)]` with a `#[source(...)]` attribute","Watch for misspelled `#[sources]` — the derive ignores unknown attributes and then reports this"],"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-14T00:17:10.932Z"}