{"record":{"id":"ecff6b503aa6e5bc","repo":"rust-lang/cargo","slug":"package-replacement-is-not-used","errorCode":null,"errorMessage":"package replacement is not used: {}","messagePattern":"package replacement is not used: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"src/ops/resolve.rs","lineNumber":186,"sourceCode":"    let (resolve, resolved_with_overrides) = if ws.require_optional_deps() {\n        // First, resolve the root_package's *listed* dependencies, as well as\n        // downloading and updating all remotes and such.\n        let resolve = resolve_with_registry(ws, &mut registry, dry_run)?;\n        // No need to add patches again, `resolve_with_registry` has done it.\n        let add_patches = false;\n\n        // Second, resolve with precisely what we're doing. Filter out\n        // transitive dependencies if necessary, specify features, handle\n        // overrides, etc.\n        add_overrides(&mut registry, ws)?;\n\n        for (replace_spec, dep) in ws.root_replace() {\n            if !resolve.iter().any(|r| {\n                replace_spec.matches(r) && !dep.matches_id(r, VersionReqMatchMode::Default)\n            }) {\n                ws.gctx()\n                    .shell()\n                    .warn(format!(\"package replacement is not used: {}\", replace_spec))?\n            }\n\n            let mut unused_fields = Vec::new();\n            if dep.features().len() != 0 {\n                unused_fields.push(\"`features`\");\n            }\n            if !dep.uses_default_features() {\n                unused_fields.push(\"`default-features`\")\n            }\n            if !unused_fields.is_empty() {\n                ws.gctx().shell().print_report(\n                    &[Level::WARNING\n                        .secondary_title(format!(\n                            \"unused field in replacement for `{}`: {}\",\n                            dep.package_name(),\n                            unused_fields.join(\", \")\n                        ))\n                        .element(Level::NOTE.message(format!(","sourceCodeStart":168,"sourceCodeEnd":204,"githubUrl":"https://github.com/rust-lang/cargo/blob/98a09e7e7d62850f14e5b6132101fc1edd19a16f/src/ops/resolve.rs#L168-L204","documentation":"During workspace resolution, Cargo checks each `[replace]` entry from the workspace root against the resolved graph: if no resolved package matches the replace spec while failing the dependency's match mode, the replacement never applies. Rather than erroring, resolve_ws_with_opts emits this warning to tell the developer the replace rule is dead configuration.","triggerScenarios":"Calling resolve_ws_with_opts on a workspace whose root manifest declares a [replace] section (e.g. replace \"with\" = { path = \"...\" }) where the spec string matches a resolved package only via the dependency's looser match mode, or matches nothing at all — commonly because the spec's version doesn't match what actually resolved.","commonSituations":"Pinned replace specs whose versions drifted after a lockfile update; replaced crate names spelled differently from the resolved package; legacy [replace] usage that modern dependency resolution no longer engages; migration to [patch] leaving stale entries.","solutions":["Review the named replace spec in the workspace root Cargo.toml and correct the package name/version so it matches a package actually in the dependency graph.","Remove the unused [replace] entry, or migrate to [patch] which is the modern mechanism for overriding sources.","Run `cargo tree -i <spec>` (or inspect Cargo.lock) to confirm what the spec should match."],"exampleFix":"// before: Cargo.toml\n[replace]\n\"serde:1.0.0\" = { path = \"../serde\" }\n\n// after: Cargo.toml (matches resolved serde 1.0.2)\n[replace]\n\"serde:1.0.2\" = { path = \"../serde\" }","handlingStrategy":"validation","validationCode":"# confirm each [replace] spec actually matches a locked package\nfor spec in $(awk '/^\"/ {print $1}' Cargo.toml | tr -d '\"'); do\n  grep -q \"${spec%%:*}\" Cargo.lock || echo \"replace spec '$spec' matches nothing\"\ndone","typeGuard":null,"tryCatchPattern":"// the warning is non-fatal; capture shell output and flag it\nif stderr.contains(\"package replacement is not used:\") {\n    // treat as dead config: alert or fail CI lint step\n}","preventionTips":["Prefer [patch] over [replace]; [replace] is legacy.","After dependency bumps, re-check that replace/patch spec versions still resolve.","Treat cargo warnings from resolution as CI failures to catch dead config early."],"tags":["config","replace","dependency-resolution","cargo"],"backgroundTag":"unsupported-config-value","analyzedSha":"98a09e7e7d62850f14e5b6132101fc1edd19a16f","analyzedAt":"2026-09-22T13:55:30.201Z","contentChangedAt":"2026-09-22T13:55:30.201Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}