{"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":"validation","errorClass":"anyhow::Error","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/0e07a155371a6ce88ae53a2c00df940280c09a67/src/workspace/parser/targets.rs#L184-L220","documentation":"Error \"can't find library `{name}`, rename file to `src/lib.rs` or specify lib.path\" thrown in rust-lang/cargo.","triggerScenarios":"Thrown at src/workspace/parser/targets.rs:202 when the library encounters an invalid state.","commonSituations":"Occurs when Cargo cannot find a library target: `src/lib.rs` is missing and no `[lib] path` is set. Create `src/lib.rs` or add a `[lib]` section with `path = \"...\"` pointing at the library source file.","solutions":["Create `src/lib.rs` in the package, or set `[lib] path = \"...\"` in Cargo.toml pointing at the actual library file.","Rename the existing library source file to `src/lib.rs`."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"analyzedSha":"0e07a155371a6ce88ae53a2c00df940280c09a67","analyzedAt":"2026-08-06T01:46:58.334Z","schemaVersion":2}