{"id":"d15c018cd20d7534","repo":"rust-lang/cargo","slug":"artifact-present","errorCode":null,"errorMessage":"artifact present","messagePattern":"artifact present","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/compiler/artifact.rs","lineNumber":107,"sourceCode":"            invalid => unreachable!(\"BUG: artifacts cannot be of type {:?}\", invalid),\n        },\n        TargetKind::Bin => \"BIN\",\n        invalid => unreachable!(\"BUG: artifacts cannot be of type {:?}\", invalid),\n    }\n}\n\n/// Given a dependency with an artifact `artifact_dep` and a set of available `targets`\n/// of its package, find a target for each kind of artifacts that are to be built.\n///\n/// Failure to match any target results in an error mentioning the parent manifests\n/// `parent_package` name.\npub(crate) fn match_artifacts_kind_with_targets<'t, 'd>(\n    artifact_dep: &'d Dependency,\n    targets: &'t [Target],\n    parent_package: &str,\n) -> CargoResult<HashSet<(&'d ArtifactKind, &'t Target)>> {\n    let mut out = HashSet::default();\n    let artifact_requirements = artifact_dep.artifact().expect(\"artifact present\");\n    for artifact_kind in artifact_requirements.kinds() {\n        let mut extend = |kind, filter: &dyn Fn(&&Target) -> bool| {\n            let mut iter = targets.iter().filter(filter).peekable();\n            let found = iter.peek().is_some();\n            out.extend(std::iter::repeat(kind).zip(iter));\n            found\n        };\n        let found = match artifact_kind {\n            ArtifactKind::Cdylib => extend(artifact_kind, &|t| t.is_cdylib()),\n            ArtifactKind::Staticlib => extend(artifact_kind, &|t| t.is_staticlib()),\n            ArtifactKind::AllBinaries => extend(artifact_kind, &|t| t.is_bin()),\n            ArtifactKind::SelectedBinary(bin_name) => extend(artifact_kind, &|t| {\n                t.is_bin() && t.name() == bin_name.as_str()\n            }),\n        };\n        if !found {\n            anyhow::bail!(\n                \"dependency `{}` in package `{}` requires a `{}` artifact to be present.\",","sourceCodeStart":89,"sourceCodeEnd":125,"githubUrl":"https://github.com/rust-lang/cargo/blob/0e07a155371a6ce88ae53a2c00df940280c09a67/src/compiler/artifact.rs#L89-L125","documentation":"`match_artifacts_kind_with_targets` iterates artifact dependency kinds via `artifact_dep.artifact().expect(\"artifact present\")`. The function is only called for dependencies that Cargo has already classified as artifact dependencies, so `.artifact()` must return `Some`. A panic here means the dependency was treated as an artifact dependency in one place but not in another — an internal inconsistency in dependency classification.","triggerScenarios":"A dependency recorded with an artifact kind in the resolver but whose `Dependency::artifact()` returns `None` (e.g. a manifest edited/parsed inconsistently, or a custom resolver path that sets `artifact` only partially). Reachable with malformed `[artifactDependencies]` / `-Zbindeps` manifests on a Cargo version with a classification bug.","commonSituations":"Experimenting with artifact dependencies (`-Zbindeps`) on nightly; upgrading Cargo across a change to the artifact-dependency data model; hand-editing `Cargo.lock` or manifests.","solutions":["Regenerate `Cargo.lock` (`cargo update`) so dependency metadata is consistent with the installed Cargo.","Update to a matching nightly/stable Cargo that supports the artifact-dependency syntax you use.","Remove and re-add the artifact dependency in `Cargo.toml` to ensure it is declared canonically."],"exampleFix":"// before\nlet artifact_requirements = artifact_dep.artifact().expect(\"artifact present\");\n// after\nlet artifact_requirements = artifact_dep.artifact().ok_or_else(|| {\n    anyhow::anyhow!(\n        \"dependency `{}` was classified as an artifact dep but carries no artifact requirements\",\n        artifact_dep.name_in_toml()\n    )\n})?;","handlingStrategy":"validation","validationCode":"// (cargo-internal) before classify, confirm dependency has artifact requirements:\n// if dep.is_artifact() { assert!(dep.artifact().is_some()); }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Regenerate `Cargo.lock` (`cargo update`) after upgrading Cargo when using artifact dependencies.","Use the nightly Cargo version documented for your `-Zbindeps` syntax.","Don't hand-edit dependency tables in `Cargo.lock`."],"tags":["cargo","artifact-dependencies","bindeps","resolver","internal-invariant"],"analyzedSha":"0e07a155371a6ce88ae53a2c00df940280c09a67","analyzedAt":"2026-08-06T01:46:58.334Z","schemaVersion":2}