{"record":{"id":"c62c1ace021c3397","repo":"rust-lang/cargo","slug":"invalid-feature-in-required-features-of-targe-c62c1a","errorCode":null,"errorMessage":"invalid feature `{}` in required-features of target `{}`: optional dependency with `?` is not allowed in required-features","messagePattern":"invalid feature `(.+?)` in required-features of target `(.+?)`: optional dependency with `\\?` is not allowed in required-features","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/ops/cargo_compile/unit_generator.rs","lineNumber":661,"sourceCode":"                FeatureValue::Feature(f) => {\n                    if !summary.features().contains_key(f) {\n                        shell.warn(format!(\n                            \"invalid feature `{}` in required-features of target `{}`: \\\n                      `{}` is not present in [features] section\",\n                            fv, target_name, fv\n                        ))?;\n                    }\n                }\n                FeatureValue::Dep { .. } => {\n                    anyhow::bail!(\n                        \"invalid feature `{}` in required-features of target `{}`: \\\n                  `dep:` prefixed feature values are not allowed in required-features\",\n                        fv,\n                        target_name\n                    );\n                }\n                FeatureValue::DepFeature { weak: true, .. } => {\n                    anyhow::bail!(\n                        \"invalid feature `{}` in required-features of target `{}`: \\\n                  optional dependency with `?` is not allowed in required-features\",\n                        fv,\n                        target_name\n                    );\n                }\n                // Handling of dependent_crate/dependent_crate_feature syntax\n                FeatureValue::DepFeature {\n                    dep_name,\n                    dep_feature,\n                    weak: false,\n                } => {\n                    match resolve.deps(summary.package_id()).find(|(_dep_id, deps)| {\n                        deps.iter().any(|dep| dep.name_in_toml() == *dep_name)\n                    }) {\n                        Some((dep_id, _deps)) => {\n                            let dep_summary = resolve.summary(dep_id);\n                            if !dep_summary.features().contains_key(dep_feature)","sourceCodeStart":643,"sourceCodeEnd":679,"githubUrl":"https://github.com/rust-lang/cargo/blob/eb98b54bc9f3c74519f43d066cb3fd02ebc88df0/src/ops/cargo_compile/unit_generator.rs#L643-L679","documentation":"Sibling of error 78, same validator: fires when a FeatureValue in required-features parses as FeatureValue::DepFeature with weak == true, i.e. an optional dependency referenced with the trailing `?` (weak feature) form like `\"opt-dep?\"`. Weak optional deps cannot drive target inclusion because their activation depends on another feature, so cargo rejects them in required-features.","triggerScenarios":"Writing `required-features = [\"some-optional-dep?\"]` in a target. The `?` suffix marks the dependency as weakly optional, which is not permitted for gating target builds.","commonSituations":"Adopting the weak-deps (`dep:`/`?`) RFC and incorrectly reusing the syntax in required-features; refactoring [features] without updating target required-features consistently.","solutions":["Remove the `?` so the dependency is a normal optional dependency: `required-features = [\"some-optional-dep\"]`.","Or gate the target on the feature that activates the weak dep: `required-features = [\"the-feature\"]`.","Re-run `cargo check` to confirm the manifest validates after the edit."],"exampleFix":"# before\n[[bin]]\nname = \"tool\"\nrequired-features = [\"opt-dep?\"]\n# after\n[[bin]]\nname = \"tool\"\nrequired-features = [\"opt-dep\"]","handlingStrategy":"validation","validationCode":"// Lint required-features entries for weak-dep `?` suffix.\nfn valid_required_feature(f: &str) -> bool { !f.ends_with('?') }","typeGuard":"// Reject weak optional-dep syntax in required-features.\nfn is_valid_required_feature(f: &str) -> bool {\n    !f.starts_with(\"dep:\") && !f.ends_with('?')\n}","tryCatchPattern":null,"preventionTips":["Drop the trailing `?` on optional deps listed in required-features.","Gate targets on the feature that activates the weak dep, not the dep directly.","Validate manifests with `cargo check` after adopting weak-deps syntax."],"tags":["cargo-compile","features","required-features","weak-deps","manifest","validation"],"backgroundTag":null,"analyzedSha":"eb98b54bc9f3c74519f43d066cb3fd02ebc88df0","analyzedAt":"2026-08-11T17:42:36.556Z","contentChangedAt":"2026-08-11T17:42:36.556Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}