{"id":"1b45143565310eb7","repo":"rust-lang/cargo","slug":"cannot-specify-both-recursive-and-precise-simultan","errorCode":null,"errorMessage":"cannot specify both recursive and precise simultaneously","messagePattern":"cannot specify both recursive and precise simultaneously","errorType":"validation","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"src/ops/cargo_update.rs","lineNumber":62,"sourceCode":"    let previous_resolve = None;\n    let mut resolve = ops::resolve_with_previous(\n        &mut registry,\n        ws,\n        &CliFeatures::new_all(true),\n        HasDevUnits::Yes,\n        previous_resolve,\n        None,\n        &[],\n        true,\n    )?;\n    ops::write_pkg_lockfile(ws, &mut resolve)?;\n    print_lockfile_changes(ws, previous_resolve, &resolve, &mut registry)?;\n    Ok(())\n}\n\npub fn update_lockfile(ws: &Workspace<'_>, opts: &UpdateOptions<'_>) -> CargoResult<()> {\n    if opts.recursive && opts.precise.is_some() {\n        anyhow::bail!(\"cannot specify both recursive and precise simultaneously\")\n    }\n\n    if ws.members().count() == 0 {\n        anyhow::bail!(\"you can't generate a lockfile for an empty workspace.\")\n    }\n\n    // Updates often require a lot of modifications to the registry, so ensure\n    // that we're synchronized against other Cargos.\n    let _lock = ws\n        .gctx()\n        .acquire_package_cache_lock(CacheLockMode::DownloadExclusive)?;\n\n    let previous_resolve = match ops::load_pkg_lockfile(ws)? {\n        Some(resolve) => resolve,\n        None => {\n            match opts.precise {\n                None => return generate_lockfile(ws),\n","sourceCodeStart":44,"sourceCodeEnd":80,"githubUrl":"https://github.com/rust-lang/cargo/blob/0e07a155371a6ce88ae53a2c00df940280c09a67/src/ops/cargo_update.rs#L44-L80","documentation":"In update_lockfile, `--recursive` (walk transitive deps) and `--precise <version>` (pin one version) have conflicting semantics, so cargo_update.rs:62 rejects using both at once.","triggerScenarios":"Passing both `--recursive` and `--precise <ver>` to `cargo update`.","commonSituations":"Misreading the update docs; combining flags copied from examples; scripting a one-off that accidentally sets both.","solutions":["Drop one of the flags: use `--precise <ver>` alone to pin, or `--recursive` alone to walk deps.","If you want to pin several deps, call `cargo update --precise` once per package rather than combining with --recursive."],"exampleFix":"# before\n$ cargo update --recursive -p serde --precise 1.0.150\nerror: cannot specify both recursive and precise simultaneously\n\n# after - choose one\n$ cargo update -p serde --precise 1.0.150\n#   or\n$ cargo update --recursive -p serde","handlingStrategy":"validation","validationCode":"# Reject combining --recursive with --precise on cargo update:\nfor a in \"$@\"; do\n  case \"$a\" in --recursive) rec=1;; --precise) prec=1;; esac\ndone\nif [ \"$rec\" = 1 ] && [ \"$prec\" = 1 ]; then\n  echo \"--recursive and --precise are mutually exclusive\" >&2; exit 1\nfi\ncargo update \"$@\"","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use --precise to pin a single version, --recursive to walk deps — never both.","Pin multiple deps with separate `cargo update --precise` calls.","Review `cargo update --help` for flag interactions."],"tags":["update","lockfile","cli","flags"],"analyzedSha":"0e07a155371a6ce88ae53a2c00df940280c09a67","analyzedAt":"2026-08-06T01:46:58.334Z","schemaVersion":2}