{"record":{"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":null,"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/eb98b54bc9f3c74519f43d066cb3fd02ebc88df0/src/ops/lockfile.rs#L68-L104","documentation":"Thrown when the lockfile's version is greater than `ResolveVersion::max_stable()` (i.e. it uses an unstable, future lockfile format) and the `-Znext-lockfile-bump` unstable feature flag is not enabled. This prevents older Cargo versions or unflagged builds from silently consuming an experimental lockfile format.","triggerScenarios":"Opening or building a project whose `Cargo.lock` has a `version` field ahead of the current stable maximum (e.g. version 4 when only 3 is stable), without `-Znext-lockfile-bump` in `CARGO_UNSTABLE_NEXT_LOCKFILE_BUMP` or the `-Z` flag.","commonSituations":"Checking out a repository where a newer or nightly Cargo wrote a next-version lockfile; downgrading Cargo after a nightly wrote the lockfile; collaborating across Cargo versions where one uses experimental lockfile features.","solutions":["Enable the feature: `cargo build -Znext-lockfile-bump` (requires nightly Cargo).","Downgrade the lockfile by deleting it and running `cargo generate-lockfile` with a stable Cargo.","Pin all collaborators to the same Cargo version to avoid format mismatches."],"exampleFix":"# Option 1: enable the unstable flag (nightly required)\ncargo +nightly build -Znext-lockfile-bump\n\n# Option 2: regenerate with stable Cargo\nrm Cargo.lock\ncargo generate-lockfile","handlingStrategy":"validation","validationCode":"// Check Cargo.lock version before building\nuse std::path::Path;\nfn check_lockfile_version_compat(lockfile: &Path) -> Result<(), String> {\n    let content = std::fs::read_to_string(lockfile).map_err(|e| e.to_string())?;\n    if let Some(line) = content.lines().find(|l| l.starts_with(\"version = \")) {\n        let v: u32 = line.trim_start_matches(\"version = \").trim().parse().unwrap_or(1);\n        if v > 3 { // max_stable as of writing\n            return Err(format!(\"lockfile version {} requires -Znext-lockfile-bump; delete Cargo.lock and regenerate or enable the flag\", v));\n        }\n    }\n    Ok(())\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pin all team members and CI to the same Cargo (stable) version.","Do not mix nightly and stable Cargo on the same lockfile.","Delete and regenerate Cargo.lock if you see version mismatches after a downgrade."],"tags":["lockfile","version-mismatch","unstable","next-lockfile-bump","nightly"],"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"}