{"record":{"id":"cf62f65843bd5af9","repo":"rust-lang/rust-analyzer","slug":"no-projects","errorCode":null,"errorMessage":"no projects","messagePattern":"no projects","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/project-model/src/lib.rs","lineNumber":121,"sourceCode":"        }\n        if path.file_name().unwrap_or_default() == \".rust-project.json\" {\n            return Ok(ProjectManifest::ProjectJson(path));\n        }\n        if path.file_name().unwrap_or_default() == \"Cargo.toml\" {\n            return Ok(ProjectManifest::CargoToml(path));\n        }\n        if path.extension().unwrap_or_default() == \"rs\" {\n            return Ok(ProjectManifest::CargoScript(path));\n        }\n        bail!(\n            \"project root must point to a Cargo.toml, rust-project.json or <script>.rs file: {path}\"\n        );\n    }\n\n    pub fn discover_single(path: &AbsPath) -> anyhow::Result<ProjectManifest> {\n        let mut candidates = ProjectManifest::discover(path)?;\n        let res = match candidates.pop() {\n            None => bail!(\"no projects\"),\n            Some(it) => it,\n        };\n\n        if !candidates.is_empty() {\n            bail!(\"more than one project\");\n        }\n        Ok(res)\n    }\n\n    pub fn discover(path: &AbsPath) -> io::Result<Vec<ProjectManifest>> {\n        if let Some(project_json) = find_in_parent_dirs(path, \"rust-project.json\") {\n            return Ok(vec![ProjectManifest::ProjectJson(project_json)]);\n        }\n        if let Some(project_json) = find_in_parent_dirs(path, \".rust-project.json\") {\n            return Ok(vec![ProjectManifest::ProjectJson(project_json)]);\n        }\n        return find_cargo_toml(path)\n            .map(|paths| paths.into_iter().map(ProjectManifest::CargoToml).collect());","sourceCodeStart":103,"sourceCodeEnd":139,"githubUrl":"https://github.com/rust-lang/rust-analyzer/blob/e8f7e90aa3e7b26aa9a000200f606c1078da99ec/crates/project-model/src/lib.rs#L103-L139","documentation":"discover_single expects exactly one project manifest under the given path. It calls discover(), and if the returned candidate list is empty it bails with \"no projects\". It means the given root contains no Cargo.toml, rust-project.json, or script.rs that discovery can find.","triggerScenarios":"Calling `ProjectManifest::discover_single(&abs_path)` on a directory with no Cargo.toml/rust-project.json anywhere it searches, so discover() returns an empty Vec.","commonSituations":"Running rust-analyzer in an empty or non-Rust directory; wrong working directory; project files ignored by discovery (e.g. manifest inside a subdir while pointing at the parent); a checkout missing manifests due to sparse clone.","solutions":["cd into (or point at) the directory containing Cargo.toml or rust-project.json.","Create a Cargo.toml (`cargo init`) if the directory should be a Rust project.","Use ProjectManifest::discover() instead if you want to handle zero/many projects explicitly.","Provide a rust-project.json for non-Cargo builds."],"exampleFix":"// before\nlet manifest = ProjectManifest::discover_single(&empty_dir)?; // bails\n// after\nlet manifest = ProjectManifest::discover_single(&workspace_dir.join(\"crates/foo\"))?;","handlingStrategy":"validation","validationCode":"fn has_manifest(dir: &Path) -> bool {\n    dir.join(\"Cargo.toml\").is_file()\n        || dir.join(\"rust-project.json\").is_file()\n        || dir.ancestors().any(|a| a.join(\"Cargo.toml\").is_file())\n}\n// if !has_manifest(&root) { create one or fix the path first }","typeGuard":null,"tryCatchPattern":"match ProjectManifest::discover_single(&path) {\n    Ok(m) => m,\n    Err(e) if e.to_string() == \"no projects\" => {\n        let candidates = ProjectManifest::discover(&path)?;\n        if candidates.is_empty() { /* init a project or abort */ }\n        unreachable!()\n    }\n    Err(e) => return Err(e.into()),\n}","preventionTips":["Verify Cargo.toml or rust-project.json exists at/below the root before calling.","Run `cargo init` in directories that should be Rust projects.","Prefer discover() and explicit matching over discover_single in tooling.","Check the working directory is the intended project root."],"tags":["rust-analyzer","project-model","discovery","cargo"],"backgroundTag":"no-projects-found","analyzedSha":"e8f7e90aa3e7b26aa9a000200f606c1078da99ec","analyzedAt":"2026-09-03T21:08:06.959Z","contentChangedAt":"2026-09-03T21:08:06.959Z","schemaVersion":2},"datasetVersion":"2026-09-11T07:07:21.782Z"}