{"record":{"id":"4619dcca2eca2cb2","repo":"bevyengine/bevy","slug":"couldn-t-parse-substates-source","errorCode":null,"errorMessage":"Couldn't parse SubStates source","messagePattern":"Couldn't parse SubStates source","errorType":"exception","errorClass":"syn::Error","httpStatus":null,"severity":"error","filePath":"crates/bevy_state/macros/src/states.rs","lineNumber":61,"sourceCode":"    let mut result = ast\n        .attrs\n        .iter()\n        .filter(|a| a.path().is_ident(\"source\"))\n        .map(|meta| {\n            let mut source = None;\n            let value = meta.parse_nested_meta(|nested| {\n                let source_type = nested.path.clone();\n                let source_value = Pat::parse_multi(nested.value()?)?;\n                source = Some(Source {\n                    source_type,\n                    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\"));","sourceCodeStart":43,"sourceCodeEnd":79,"githubUrl":"https://github.com/bevyengine/bevy/blob/396ca727080776bd313bb892423b7d94e03b81b4/crates/bevy_state/macros/src/states.rs#L43-L79","documentation":"Compile-time error from the derive(SubStates) proc macro (bevy_state/macros/src/states.rs:44-65). Source attributes are parsed with parse_nested_meta expecting `#[source(SourceStateType = pattern)]`; if attribute parsing succeeded but no valid source pair was captured (source stayed None while the meta parse returned Ok), the macro reports 'Couldn't parse SubStates source' on the whole derive.","triggerScenarios":"Writing `#[derive(SubStates)] #[source]` with no payload; `#[source(foo)]` where foo is not a `Type = value` pair; putting the source in an attribute the macro does not inspect.","commonSituations":"First use of SubStates following examples that omit the exact attribute shape; refactoring States into SubStates and leaving a bare marker attribute; typos in the attribute name so it is ignored.","solutions":["Use the exact form `#[source(AppState = AppState::InGame)]` above the enum","Remember the shape is `SourceStateType = Pattern`, not a bare path or string","Check the SubStates documentation example for the current Bevy version"],"exampleFix":"// before\n#[derive(SubStates, Debug, Hash, PartialEq, Eq, Clone)]\n#[source]\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":["Copy the exact `#[source(ParentState = ParentState::Variant)]` shape from the Bevy SubStates example","Treat any silent derive failure as an attribute-shape problem first — cargo expand shows what the macro parsed"],"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"}