{"record":{"id":"d0d80827e7cd70e8","repo":"rust-lang/cargo","slug":"can-t-find-library-name-rename-file-to-src-l","errorCode":null,"errorMessage":"can't find library `{name}`, rename file to `src/lib.rs` or specify lib.path","messagePattern":"can't find library `(.+?)`, rename file to `src/lib\\.rs` or specify lib\\.path","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/workspace/parser/targets.rs","lineNumber":202,"sourceCode":"\n        validate_proc_macro(&lib, TARGET_KIND_HUMAN_LIB, edition, warnings)?;\n        validate_crate_types(&lib, TARGET_KIND_HUMAN_LIB, edition, warnings)?;\n\n        if lib.path.is_none() {\n            if let Some(inferred) = inferred {\n                lib.path = Some(PathValue(inferred));\n            } else {\n                let name = name_or_panic(&lib);\n                let legacy_path = Path::new(\"src\").join(format!(\"{name}.rs\"));\n                if edition == Edition::Edition2015 && package_root.join(&legacy_path).exists() {\n                    warnings.push(format!(\n                        \"path `{}` was erroneously implicitly accepted for library `{name}`,\\n\\\n                     please rename the file to `src/lib.rs` or set lib.path in Cargo.toml\",\n                        legacy_path.display(),\n                    ));\n                    lib.path = Some(PathValue(legacy_path));\n                } else {\n                    anyhow::bail!(\n                        \"can't find library `{name}`, \\\n                     rename file to `src/lib.rs` or specify lib.path\",\n                    )\n                }\n            }\n        }\n\n        if let Some(PathValue(path)) = lib.path.as_ref() {\n            lib.path = Some(PathValue(paths::normalize_path(&path).into()));\n        }\n\n        Ok(Some(lib))\n    }\n}\n\n#[tracing::instrument(skip_all)]\nfn to_lib_target(\n    original_lib: Option<&TomlLibTarget>,","sourceCodeStart":184,"sourceCodeEnd":220,"githubUrl":"https://github.com/rust-lang/cargo/blob/eb98b54bc9f3c74519f43d066cb3fd02ebc88df0/src/workspace/parser/targets.rs#L184-L220","documentation":"When resolving a `[lib]` target, Cargo tries to infer the source file: first `src/lib.rs`, then (edition 2015 only) `src/<name>.rs` with a deprecation warning. If `lib.path` is unset and none of those files exist on disk (`package_root.join(...).exists()` is false), the parser cannot proceed and bails. The library target must point at a real file.","triggerScenarios":"A `[lib]` section (or a package whose name implies a lib) is present, `lib.path` is unset, there is no `src/lib.rs`, and either the edition is 2018+ or `src/<name>.rs` also does not exist. The `else` branch at targets.rs:201-205 fires.","commonSituations":"Renaming `src/lib.rs` to a custom path without updating `lib.path`. Splitting a binary-only crate that still has a leftover `[lib]` table. Cloning a repo where the library source lives under `src/` but with a non-default name on edition 2018+.","solutions":["Create `src/lib.rs` (the conventional default).","Set `[lib] path = \"src/your_name.rs\"` to point at the actual file.","Remove the `[lib]` table entirely if the crate is not a library."],"exampleFix":"# before\n[lib]\n# no path set; src/lib.rs missing\n\n# after\n[lib]\npath = \"src/my_lib.rs\"","handlingStrategy":"validation","validationCode":"use std::path::Path;\nfn lib_path_resolves(pkg_root: &Path, lib_path: Option<&str>, name: &str, ed2015: bool) -> bool {\n    if let Some(p) = lib_path { return pkg_root.join(p).exists(); }\n    if pkg_root.join(\"src/lib.rs\").exists() { return true; }\n    ed2015 && pkg_root.join(\"src\").join(format!(\"{name}.rs\")).exists()\n}\n// call before `cargo build` to fail fast with a clear message","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep library sources at the conventional `src/lib.rs`.","When moving the lib file, update `[lib] path` in the same change.","Remove leftover `[lib]` tables from binary-only crates."],"tags":["cargo","config","library","filesystem","manifest"],"backgroundTag":null,"analyzedSha":"eb98b54bc9f3c74519f43d066cb3fd02ebc88df0","analyzedAt":"2026-08-11T17:42:36.556Z","contentChangedAt":"2026-08-11T17:42:36.556Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}