{"id":"5e698ba46e9b31b9","repo":"rust-lang/cargo","slug":"single-file-packages-cannot-be-used-as-dependencie","errorCode":null,"errorMessage":"single file packages cannot be used as dependencies","messagePattern":"single file packages cannot be used as dependencies","errorType":"validation","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"src/workspace/source_id.rs","lineNumber":402,"sourceCode":"\n    /// Returns `true` if this source from a Git repository.\n    pub fn is_git(self) -> bool {\n        matches!(self.inner.kind, SourceKind::Git(_))\n    }\n\n    /// Creates an implementation of `Source` corresponding to this ID.\n    pub fn load<'a>(self, gctx: &'a GlobalContext) -> CargoResult<Box<dyn Source + 'a>> {\n        trace!(\"loading SourceId; {}\", self);\n        match self.inner.kind {\n            SourceKind::Git(..) => Ok(Box::new(GitSource::new(self, gctx)?)),\n            SourceKind::Path => {\n                let path = self\n                    .inner\n                    .url\n                    .to_file_path()\n                    .expect(\"path sources cannot be remote\");\n                if crate::workspace::parser::is_embedded(&path) && path.is_file() {\n                    anyhow::bail!(\"single file packages cannot be used as dependencies\")\n                }\n                Ok(Box::new(PathSource::new(&path, self, gctx)))\n            }\n            SourceKind::Registry | SourceKind::SparseRegistry => {\n                Ok(Box::new(RegistrySource::remote(self, gctx)?))\n            }\n            SourceKind::LocalRegistry => {\n                let path = self\n                    .inner\n                    .url\n                    .to_file_path()\n                    .expect(\"path sources cannot be remote\");\n                Ok(Box::new(RegistrySource::local(self, &path, gctx)))\n            }\n            SourceKind::Directory => {\n                let path = self\n                    .inner\n                    .url","sourceCodeStart":384,"sourceCodeEnd":420,"githubUrl":"https://github.com/rust-lang/cargo/blob/0e07a155371a6ce88ae53a2c00df940280c09a67/src/workspace/source_id.rs#L384-L420","documentation":"Raised in `SourceId::load` (src/workspace/source_id.rs:401) for a `SourceKind::Path` dependency whose resolved path is a single file (passes `is_embedded(&path) && path.is_file()`). Cargo's path dependencies must be a directory containing a `Cargo.toml`; a lone `.rs` file is only valid as an embedded/crate-root inside a package, never as an external dependency source.","triggerScenarios":"Declaring a dependency with `path = \"./src/lib.rs\"` or any path that points at a file rather than a directory; `is_embedded` returns true for a path that also satisfies `is_file()`.","commonSituations":"Confusing Cargo's path deps (which take a directory) with the embedded `[lib] path = \"src/lib.rs\"` syntax; pointing at a single-file crate from another workspace; refactoring a sub-crate into a file and forgetting to update dependents.","solutions":["Point the `path` at the directory containing the dependency's `Cargo.toml` (e.g. `path = \"../my-lib\"`).","If you genuinely have a single-file crate, wrap it in a minimal package directory with its own `Cargo.toml`.","Re-check the path is not accidentally resolving to a file via a glob or trailing filename."],"exampleFix":"# before\n[dependencies]\nmy-lib = { path = \"./src/my_lib.rs\" }\n# after\n[dependencies]\nmy-lib = { path = \"./my-lib\" }   # directory containing Cargo.toml","handlingStrategy":"validation","validationCode":"fn is_valid_path_dep(p: &std::path::Path) -> bool {\n    p.is_dir() && p.join(\"Cargo.toml\").exists()\n}\n// assert is_valid_path_dep(std::path::Path::new(dep_path)) before declaring the dependency","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always point path dependencies at a directory containing Cargo.toml.","Never reference a single .rs file as a dependency path.","Validate path deps in a pre-build script."],"tags":["cargo","dependency","path","manifest"],"analyzedSha":"0e07a155371a6ce88ae53a2c00df940280c09a67","analyzedAt":"2026-08-06T01:46:58.334Z","schemaVersion":2}