{"id":"40750f304921ad98","repo":"rust-lang/cargo","slug":"invalid-inclusion-of-reserved-file-name-in-pack","errorCode":null,"errorMessage":"invalid inclusion of reserved file name {} in package source","messagePattern":"invalid inclusion of reserved file name (.+?) in package source","errorType":"validation","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"src/ops/cargo_package/mod.rs","lineNumber":515,"sourceCode":"#[tracing::instrument(skip_all)]\nfn build_ar_list(\n    ws: &Workspace<'_>,\n    pkg: &Package,\n    src_files: Vec<PathEntry>,\n    vcs_info: Option<vcs::VcsInfo>,\n    include_lockfile: bool,\n) -> CargoResult<Vec<ArchiveFile>> {\n    let mut result = HashMap::default();\n    let root = pkg.root();\n    for src_file in &src_files {\n        let rel_path = src_file.strip_prefix(&root)?;\n        check_filename(rel_path, &mut ws.gctx().shell())?;\n        let rel_str = rel_path.to_str().ok_or_else(|| {\n            anyhow::format_err!(\"non-utf8 path in source directory: {}\", rel_path.display())\n        })?;\n        match rel_str {\n            \"Cargo.lock\" => continue,\n            VCS_INFO_FILE | ORIGINAL_MANIFEST_FILE => anyhow::bail!(\n                \"invalid inclusion of reserved file name {} in package source\",\n                rel_str\n            ),\n            _ => {\n                result\n                    .entry(UncasedAscii::new(rel_str))\n                    .or_insert_with(Vec::new)\n                    .push(ArchiveFile {\n                        rel_path: rel_path.to_owned(),\n                        rel_str: rel_str.to_owned(),\n                        contents: FileContents::OnDisk(src_file.to_path_buf()),\n                    });\n            }\n        }\n    }\n\n    // Ensure we normalize for case insensitive filesystems (like on Windows) by removing the\n    // existing entry, regardless of case, and adding in with the correct case","sourceCodeStart":497,"sourceCodeEnd":533,"githubUrl":"https://github.com/rust-lang/cargo/blob/0e07a155371a6ce88ae53a2c00df940280c09a67/src/ops/cargo_package/mod.rs#L497-L533","documentation":"During `cargo package`/`cargo publish`, build_ar_list walks every source file to be archived. The filenames .cargo_vcs_info.json and Cargo.toml.orig are reserved - Cargo itself generates them inside the .crate archive - so any such file appearing in the package source list is treated as an illegal inclusion and rejected. This prevents user files from shadowing Cargo's generated metadata.","triggerScenarios":"Shipping a file literally named `.cargo_vcs_info.json` or `Cargo.toml.orig` inside the package source tree (e.g. copied in by a build script, vendored manually, or committed by mistake). The match arm at cargo_package/mod.rs:515 catches them.","commonSituations":"A previous `cargo package` output was unzipped into the source tree and not cleaned; a macro/build script copies archive metadata back into src/; CI artifacts committed by accident; users trying to 'pre-seed' VCS info.","solutions":["Delete the offending file from your source tree: `rm .cargo_vcs_info.json Cargo.toml.orig`","Add it to .gitignore and ensure no build step writes it into the package","If you extracted a previous .crate into your repo, remove all generated artifacts"],"exampleFix":"# before: src/.cargo_vcs_info.json exists -> cargo package fails\n# after\nrm src/.cargo_vcs_info.json Cargo.toml.orig 2>/dev/null\ncargo package","handlingStrategy":"validation","validationCode":"use std::path::Path;\nconst RESERVED: &[&str] = &[\".cargo_vcs_info.json\", \"Cargo.toml.orig\"];\nfn ensure_no_reserved_files(root: &Path) -> Result<(), String> {\n    for entry in walkdir::WalkDir::new(root) {\n        let entry = entry.map_err(|e| e.to_string())?;\n        if entry.file_type().is_file() {\n            if let Some(name) = entry.file_name().to_str() {\n                if RESERVED.contains(&name) {\n                    return Err(format!(\"reserved file in tree: {}\", entry.path().display()));\n                }\n            }\n        }\n    }\n    Ok(())\n}","typeGuard":"import { walkSync } from 'fs';\nimport { basename } from 'path';\nconst RESERVED = new Set(['.cargo_vcs_info.json', 'Cargo.toml.orig']);\nfunction treeHasNoReserved(root: string): boolean {\n  for (const f of walkSync(root)) { if (RESERVED.has(basename(f.path))) return false; }\n  return true;\n}","tryCatchPattern":null,"preventionTips":["Never commit .cargo_vcs_info.json or Cargo.toml.orig; add them to .gitignore","Run `cargo package --list` before `cargo package` to inspect the file list","Avoid unzipping prior .crate archives into your source tree"],"tags":["cargo-package","reserved-filename","packaging","metadata"],"analyzedSha":"0e07a155371a6ce88ae53a2c00df940280c09a67","analyzedAt":"2026-08-06T01:46:58.334Z","schemaVersion":2}