{"id":"c0b72f5da11c706d","repo":"rust-lang/cargo","slug":"lock-file-version-current-version-requires","errorCode":null,"errorMessage":"lock file version `{current_version:?}` requires `-Znext-lockfile-bump`","messagePattern":"lock file version `(.+?)` requires `-Znext-lockfile-bump`","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"src/ops/lockfile.rs","lineNumber":86,"sourceCode":"        );\n    }\n\n    // While we're updating the lock file anyway go ahead and update its\n    // encoding to whatever the latest default is. That way we can slowly roll\n    // out lock file updates as they're otherwise already updated, and changes\n    // which don't touch dependencies won't seemingly spuriously update the lock\n    // file.\n    let default_version = ResolveVersion::with_rust_version(ws.lowest_rust_version());\n    let current_version = resolve.version();\n    let next_lockfile_bump = ws.gctx().cli_unstable().next_lockfile_bump;\n    tracing::debug!(\"lockfile - current: {current_version:?}, default: {default_version:?}\");\n\n    if current_version < default_version {\n        resolve.set_version(default_version);\n        out = serialize_resolve(resolve, orig.as_deref());\n    } else if current_version > ResolveVersion::max_stable() && !next_lockfile_bump {\n        // The next version hasn't yet stabilized.\n        anyhow::bail!(\"lock file version `{current_version:?}` requires `-Znext-lockfile-bump`\")\n    }\n\n    if !lock_root.as_path_unlocked().exists() {\n        lock_root.create_dir()?;\n    }\n\n    // Ok, if that didn't work just write it out\n    lock_root\n        .open_rw_exclusive_create(LOCKFILE_NAME, ws.gctx(), \"Cargo.lock file\")\n        .and_then(|mut f| {\n            f.file().set_len(0)?;\n            f.write_all(out.as_bytes())?;\n            Ok(())\n        })\n        .with_context(|| {\n            format!(\n                \"failed to write {}\",\n                lock_root.as_path_unlocked().join(LOCKFILE_NAME).display()","sourceCodeStart":68,"sourceCodeEnd":104,"githubUrl":"https://github.com/rust-lang/cargo/blob/0e07a155371a6ce88ae53a2c00df940280c09a67/src/ops/lockfile.rs#L68-L104","documentation":"Cargo.lock carries a version tag. If the on-disk version is newer than the maximum stable version the running cargo understands, write_pkg_lockfile refuses to proceed unless `-Znext-lockfile-bump` is enabled (lockfile.rs:86). This usually means the lockfile was produced by a newer/nightly cargo.","triggerScenarios":"Opening/building a project whose Cargo.lock was written by a newer cargo (or nightly with next-lockfile-bump) using an older stable cargo.","commonSituations":"Downgrading the rust toolchain; teammates on different rustup versions; lockfile committed from a nightly CI.","solutions":["Upgrade your toolchain to match the cargo that wrote the lockfile (e.g. `rustup update`).","If you intentionally use the newer format, run with `-Znext-lockfile-bump` (nightly only).","Downgrade the lockfile by deleting it and regenerating with your current stable cargo (may change resolved versions)."],"exampleFix":"# before\n$ cargo build\nerror: lock file version `V4` requires `-Znext-lockfile-bump`\n\n# after - upgrade toolchain to one that understands the version\n$ rustup update stable\n$ cargo build\n# or, on nightly with the new format:\n$ cargo +nightly build -Znext-lockfile-bump","handlingStrategy":"validation","validationCode":"# Check the lockfile version against your cargo's supported version:\nif grep -q '^version' Cargo.lock 2>/dev/null; then\n  # If build fails on version, upgrade toolchain first:\n  rustup update stable || true\nfi\ncargo build || cargo +nightly build -Znext-lockfile-bump","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep teammates on the same rust/cargo version.","Don't commit a nightly-generated lockfile to a project built on stable.","Run `rustup update` when seeing unfamiliar lockfile version errors."],"tags":["lockfile","version","nightly","toolchain"],"analyzedSha":"0e07a155371a6ce88ae53a2c00df940280c09a67","analyzedAt":"2026-08-06T01:46:58.334Z","schemaVersion":2}