{"id":"6c28d4d47078a371","repo":"rust-lang/cargo","slug":"required-true","errorCode":null,"errorMessage":"required(true)","messagePattern":"required\\(true\\)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/bin/cargo/commands/remove.rs","lineNumber":100,"sourceCode":"        }\n        1 => packages[0],\n        _ => {\n            let names = packages.iter().map(|p| p.name()).collect::<Vec<_>>();\n            return Err(CliError::new(\n                anyhow::format_err!(\n                    \"no package selected to modify\nhelp: specify a package with `-p <PKGID>`\n      available packages: {}\",\n                    names.join(\", \")\n                ),\n                101,\n            ));\n        }\n    };\n\n    let dependencies = args\n        .get_many::<String>(\"dependencies\")\n        .expect(\"required(true)\")\n        .cloned()\n        .collect::<Vec<_>>();\n\n    let section = parse_section(args);\n\n    let options = RemoveOptions {\n        gctx,\n        spec,\n        dependencies,\n        section,\n        dry_run,\n    };\n    remove(&options)?;\n\n    if !dry_run {\n        // Clean up the workspace\n        gc_workspace(&workspace)?;\n","sourceCodeStart":82,"sourceCodeEnd":118,"githubUrl":"https://github.com/rust-lang/cargo/blob/0e07a155371a6ce88ae53a2c00df940280c09a67/src/bin/cargo/commands/remove.rs#L82-L118","documentation":"Cargo's `cargo remove` command reads its positional `dependencies` argument via clap's `get_many(\"dependencies\").expect(\"required(true)\")`. The argument is declared with `.required(true)` in the clap definition, so clap guarantees at least one value is present when parsing succeeds. This expect is an internal invariant: if it fires, the clap argument definition and the parser are out of sync — a Cargo programming bug, not a user error.","triggerScenarios":"Calling `cargo remove <dep>` after the clap `AppArgs` definition for `dependencies` was edited so it is no longer marked `.required(true)`, or a regression in clap's argument propagation that yields no values for a required arg. The panic happens at argument-consumption time, before any manifest work begins.","commonSituations":"Maintainers hacking on `src/bin/cargo/commands/remove.rs` who tweak the clap definition; upgrading clap across a major version that changes how `required(true)` interacts with `get_many`; running an unrepaired dev build of Cargo after a refactor of the `remove` subcommand.","solutions":["If using a stock Cargo release, file a bug at https://github.com/rust-lang/cargo/issues with the `cargo remove` invocation and Cargo version — this path should be unreachable.","If hacking on Cargo, verify the `dependencies` arg in the `clap::Args` struct still has `required = true` and that no `ArgGroup`/default handling strips it before `get_many` runs.","Pin to a known-good Cargo / clap combination (`rustup override set <stable>`) until the regression is fixed."],"exampleFix":"// before\nlet dependencies = args\n    .get_many::<String>(\"dependencies\")\n    .expect(\"required(true)\");\n// after (defensive, only if the invariant genuinely cannot be upheld)\nlet dependencies = args\n    .get_many::<String>(\"dependencies\")\n    .ok_or_else(|| anyhow::anyhow!(\"internal error: `dependencies` arg not present\"))?\n    .cloned()\n    .collect::<Vec<_>>();","handlingStrategy":"validation","validationCode":"// Nothing a *caller* of `cargo remove` can validate; this is an internal\n// invariant. If you embed Cargo as a library and build the clap AppArgs\n// yourself, assert the arg definition before invoking:\n// (pseudo) ensure args.find(\"dependencies\").map(|a| a.is_required_set()) == Some(true)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Treat this panic as a Cargo bug; capture the exact `cargo remove` invocation and Cargo version.","If maintaining a fork, keep the clap `dependencies` arg declared with `required = true`.","Pin to a released Cargo where `cargo remove` works for your inputs."],"tags":["cargo","clap","argument-parsing","internal-invariant"],"analyzedSha":"0e07a155371a6ce88ae53a2c00df940280c09a67","analyzedAt":"2026-08-06T01:46:58.334Z","schemaVersion":2}