{"record":{"id":"b79a1e9bf07619c6","repo":"rust-lang/rust-analyzer","slug":"project-root-must-point-to-a-cargo-toml-rust-proj","errorCode":null,"errorMessage":"project root must point to a Cargo.toml, rust-project.json or <script>.rs file: {path}","messagePattern":"project root must point to a Cargo\\.toml, rust-project\\.json or <script>\\.rs file: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/project-model/src/lib.rs","lineNumber":113,"sourceCode":"}\n\nimpl ProjectManifest {\n    pub fn from_manifest_file(path: AbsPathBuf) -> anyhow::Result<ProjectManifest> {\n        let path = ManifestPath::try_from(path)\n            .map_err(|path| format_err!(\"bad manifest path: {path}\"))?;\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() == \".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>> {","sourceCodeStart":95,"sourceCodeEnd":131,"githubUrl":"https://github.com/rust-lang/rust-analyzer/blob/e8f7e90aa3e7b26aa9a000200f606c1078da99ec/crates/project-model/src/lib.rs#L95-L131","documentation":"ProjectManifest::from_manifest_file only accepts a Cargo.toml, a rust-project.json, or a `<script>.rs` file as the project root. Any other path (directory, missing manifest, wrong file) fails this bail. It tells you the path you handed to project discovery isn't a recognizable project manifest.","triggerScenarios":"Calling `ProjectManifest::from_manifest_file(&path)` with: a directory path, a path whose file_name is not `Cargo.toml`, a file whose extension is not `rs` and is not rust-project.json, or a nonexistent file.","commonSituations":"Passing the workspace root directory instead of the manifest; pointing rust-analyzer at a non-Cargo (e.g. bazel) project without a rust-project.json; typo'd manifest path; running rust-analyzer outside a Rust project.","solutions":["Point the path at the actual `Cargo.toml` of the crate/workspace.","For non-Cargo setups, generate a `rust-project.json` and pass that file.","For a single-file Rust script, pass the `<script>.rs` path.","Verify the path exists and is a file, not a directory, before calling."],"exampleFix":"// before\nlet manifest = ProjectManifest::from_manifest_file(&root_dir.join(\"project\"))?;\n// after\nlet manifest = ProjectManifest::from_manifest_file(&root_dir.join(\"project/Cargo.toml\"))?;","handlingStrategy":"validation","validationCode":"fn looks_like_manifest(p: &Path) -> bool {\n    p.file_name().map_or(false, |f| f == \"Cargo.toml\" || f == \"rust-project.json\")\n        || p.extension().map_or(false, |e| e == \"rs\")\n}\n// assert!(path.is_file() && looks_like_manifest(&path));","typeGuard":null,"tryCatchPattern":"match ProjectManifest::from_manifest_file(&path) {\n    Ok(m) => m,\n    Err(e) if e.to_string().contains(\"project root must point\") => {\n        // walk up to find Cargo.toml or prompt user for the manifest path\n    }\n    Err(e) => return Err(e.into()),\n}","preventionTips":["Always pass a file path to the manifest, never a directory.","Accept Cargo.toml / rust-project.json / script.rs only.","Search parent directories for Cargo.toml before erroring.","Validate path.is_file() before discovery."],"tags":["rust-analyzer","project-model","configuration","cargo"],"backgroundTag":"invalid-project-root","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"}