{"id":"d95c7b33e895653d","repo":"rust-lang/cargo","slug":"in-the-non-empty-branch","errorCode":null,"errorMessage":"in the non-empty branch","messagePattern":"in the non-empty branch","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/resolver/errors.rs","lineNumber":167,"sourceCode":"                    msg.push_str(\"` as well:\\n\");\n                    msg.push_str(&describe_path_in_context(resolver_ctx, p));\n                    msg.push_str(\"\\nnote: only one package in the dependency graph may specify the same links value to ensure that only one copy of a native library is linked in the final binary\");\n                    msg.push_str(\"\\nfor more information, see https://doc.rust-lang.org/cargo/reference/resolver.html#links\");\n                    msg.push_str(\"\\nhelp: try to adjust your dependencies so that only one package uses the `links = \\\"\");\n                    msg.push_str(link);\n                    msg.push_str(\"\\\"` value\");\n                }\n                ConflictReason::MissingFeature(feature) => {\n                    msg.push_str(\"\\n\\npackage `\");\n                    msg.push_str(&*p.name());\n                    msg.push_str(\"` depends on `\");\n                    msg.push_str(&*dep.package_name());\n                    msg.push_str(\"` with feature `\");\n                    msg.push_str(feature);\n                    msg.push_str(\"` but `\");\n                    msg.push_str(&*dep.package_name());\n                    msg.push_str(\"` does not have that feature.\\n\");\n                    let latest = candidates.last().expect(\"in the non-empty branch\");\n                    if let Some(closest) = closest(feature, latest.features().keys(), |k| k) {\n                        msg.push_str(\"help: there is a feature `\");\n                        msg.push_str(closest);\n                        msg.push_str(\"` with a similar name\\n\");\n                    } else if !latest.features().is_empty() {\n                        let mut features: Vec<_> =\n                            latest.features().keys().map(|f| f.as_str()).collect();\n                        features.sort();\n                        msg.push_str(\"help: available features: \");\n                        msg.push_str(&features.join(\", \"));\n                        msg.push_str(\"\\n\");\n                    }\n                    // p == parent so the full path is redundant.\n                }\n                ConflictReason::RequiredDependencyAsFeature(feature) => {\n                    msg.push_str(\"\\n\\npackage `\");\n                    msg.push_str(&*p.name());\n                    msg.push_str(\"` depends on `\");","sourceCodeStart":149,"sourceCodeEnd":185,"githubUrl":"https://github.com/rust-lang/cargo/blob/0e07a155371a6ce88ae53a2c00df940280c09a67/src/resolver/errors.rs#L149-L185","documentation":"Invariant in resolver error formatting: when reporting `ConflictReason::MissingFeature`, the code calls `candidates.last().expect(\"in the non-empty branch\")`. This branch is only entered when there is at least one candidate for the dependency; the expect guards that assumption.","triggerScenarios":"Fires only if the missing-feature error path is reached with an empty `candidates` list — i.e. the resolver is formatting a \"missing feature\" conflict for a dependency that has zero candidate versions, contradicting the branch's non-empty precondition.","commonSituations":"Cargo bug in conflict/error formatting where `candidates` is unexpectedly empty; a dependency whose all versions were filtered out (e.g. by `rust-version`/platform) but still reached the missing-feature reporter. End users see this only as a panic during an already-failing resolution.","solutions":["Report a cargo bug with the resolution failure context (the missing-feature message would have preceded it).","Loosen constraints (rust-version, target, feature) that may be eliminating all candidates and retry.","Update cargo — resolver error-reporting regressions are patched quickly."],"exampleFix":"// before\nlet latest = candidates.last().expect(\"in the non-empty branch\");\n\n// after\nlet latest = candidates.last().ok_or_else(|| anyhow::anyhow!(\n    \"reached missing-feature report with no candidates for `{}`\", dep.package_name()))?;","handlingStrategy":"validation","validationCode":"// If you mirror resolver error formatting, guard the candidates lookup.\nlet latest = match candidates.last() {\n    Some(c) => c,\n    None => return format!(\"missing feature (no candidates available for `{}`)\", dep.package_name()),\n};","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Relax rust-version/platform/feature filters so at least one candidate remains.","Update cargo to pick up resolver error-reporting fixes."],"tags":["cargo","panic","invariant","resolver","error-reporting","features","rust"],"analyzedSha":"0e07a155371a6ce88ae53a2c00df940280c09a67","analyzedAt":"2026-08-06T01:46:58.334Z","schemaVersion":2}