{"id":"adb69f3dc4052fbc","repo":"rust-lang/cargo","slug":"local-path","errorCode":null,"errorMessage":"local path","messagePattern":"local path","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/ops/cargo_vendor.rs","lineNumber":252,"sourceCode":"        )?;\n\n        let _ = fs::remove_dir_all(&dst);\n\n        let mut file_cksums = BTreeMap::new();\n\n        // Need this mapping anyway because we will directly consult registry sources,\n        // otherwise builtin source replacement (sparse registry) won't be respected.\n        let sid = source_replacement_cache.get(id.source_id())?;\n\n        if sid.is_registry() {\n            // To keep the unpacked source from registry in a pristine state,\n            // we'll do a direct extraction into the vendor directory.\n            let registry = match sid.kind() {\n                SourceKind::Registry | SourceKind::SparseRegistry => {\n                    RegistrySource::remote(sid, gctx)?\n                }\n                SourceKind::LocalRegistry => {\n                    let path = sid.url().to_file_path().expect(\"local path\");\n                    RegistrySource::local(sid, &path, gctx)\n                }\n                _ => unreachable!(\"not registry source: {sid}\"),\n            };\n\n            let walkdir = |root| {\n                WalkDir::new(root)\n                    .into_iter()\n                    // It is safe to skip errors,\n                    // since we'll hit them during copying/reading later anyway.\n                    .filter_map(|e| e.ok())\n                    // There should be no symlink in tarballs on crates.io,\n                    // but might be wrong for local registries.\n                    // Hence here be conservative and include symlinks.\n                    .filter(|e| e.file_type().is_file() || e.file_type().is_symlink())\n            };\n            let mut compute_file_cksums = |root| {\n                for e in walkdir(root) {","sourceCodeStart":234,"sourceCodeEnd":270,"githubUrl":"https://github.com/rust-lang/cargo/blob/0e07a155371a6ce88ae53a2c00df940280c09a67/src/ops/cargo_vendor.rs#L234-L270","documentation":"In `cargo vendor`, for a `SourceKind::LocalRegistry` the code converts the source URL to a filesystem path via `sid.url().to_file_path().expect(\"local path\")`. `Url::to_file_path` returns `Err` when the URL scheme is not `file://` or the host component is non-empty (e.g. a `file://host/...` URL).","triggerScenarios":"Vendoring a dependency that resolves to a local-registry source whose `url` is configured as something other than a bare `file://` path — e.g. a `file://localhost/...` URL with a host, or accidentally a `sparse+file://`, `https://`, or relative path string.","commonSituations":"A `[source]` replacement mapping a registry to a local registry path that was written with a host component or wrong scheme; migrating a local-registry config between Windows (`file:///C:/...`) and Unix; typos in `replace-with`/`local-registry` config.","solutions":["Inspect your `.cargo/config.toml` `[source]` / `[registry]` entries and confirm the local-registry URL is a plain `file:///absolute/path` (no host).","Re-point the source to a directory path directly (`registry = \"file:///path/to/registry\"`) and re-run `cargo vendor`.","On Windows, ensure drive letters are encoded as `file:///C:/...` not `file://C:/...`.","If the URL looks correct, report a cargo bug with the exact `[source]` block."],"exampleFix":"// before\nlet path = sid.url().to_file_path().expect(\"local path\");\n\n// after\nlet path = sid.url().to_file_path()\n    .map_err(|_| anyhow::format_err!(\n        \"local registry source `{}` is not a valid file:// path\", sid.url()))?;","handlingStrategy":"validation","validationCode":"// Validate local-registry source URLs are bare file:// paths before vendoring.\nif !url.as_str().starts_with(\"file:///\") || url.host_str().is_some() {\n    return Err(anyhow!(\"local registry URL must be file:///abs/path with no host: {}\", url));\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Declare local registries as `file:///absolute/path` (three slashes, no host).","On Windows, encode drives as `file:///C:/...`.","Review `.cargo/config.toml` `[source]` blocks after cross-platform moves."],"tags":["cargo","panic","invariant","cargo-vendor","local-registry","url","filesystem","rust"],"analyzedSha":"0e07a155371a6ce88ae53a2c00df940280c09a67","analyzedAt":"2026-08-06T01:46:58.334Z","schemaVersion":2}