Skip to content

cargo tree -Z bindeps panics for artifact build-dependency with target = "target" #17125

Description

@wan9chi

Problem

cargo tree -Z bindeps can panic for an artifact build-dependency declared with target = "target" when no explicit --target is passed.

cargo check -Z bindeps succeeds for the same project, but cargo tree -Z bindeps panics instead of printing the dependency tree.

Expected behavior: cargo tree -Z bindeps prints the dependency tree.

Actual behavior: cargo tree -Z bindeps panics.

Reproduction log

Reproduced on current nightly with the repro from the issue, without passing an explicit --target.

$ cargo +nightly -Vv
cargo 1.98.0-nightly (598ab48ec 2026-06-17)
release: 1.98.0-nightly
commit-hash: 598ab48ec328e3e4f5e4e373d8df7264bc8e27cd
commit-date: 2026-06-17
host: aarch64-apple-darwin
libgit2: 1.9.4 (sys:0.21.0 vendored)
libcurl: 8.7.1 (sys:0.4.88+curl-8.20.0 system ssl:(SecureTransport) LibreSSL/3.3.6)
ssl: OpenSSL 3.6.2 7 Apr 2026
os: Mac OS 26.5.1 [64-bit]

cargo check -Z bindeps succeeds:

$ cargo +nightly check -Z bindeps
     Locking 2 packages to latest Rust 1.98.0-nightly compatible versions
   Compiling pm v0.1.0 (/private/tmp/cargo-issue-17125-repro/pm)
   Compiling foo v0.0.0 (/private/tmp/cargo-issue-17125-repro)
   Compiling bar v0.5.0 (/private/tmp/cargo-issue-17125-repro/bar)
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 3.57s

cargo tree -Z bindeps panics:

$ RUST_BACKTRACE=1 cargo +nightly tree -Z bindeps

thread 'main' (43603029) panicked at src/tools/cargo/src/cargo/core/resolver/features.rs:325:13:
did not find features for (PackageId { name: "bar", version: "0.5.0", source: "/private/tmp/cargo-issue-17125-repro/bar" }, HostDep) within activated_features:
[
    (
        PackageId {
            name: "pm",
            version: "0.1.0",
            source: "/private/tmp/cargo-issue-17125-repro/pm",
        },
        HostDep,
    ),
    (
        PackageId {
            name: "foo",
            version: "0.0.0",
            source: "/private/tmp/cargo-issue-17125-repro",
        },
        NormalOrDev,
    ),
    (
        PackageId {
            name: "bar",
            version: "0.5.0",
            source: "/private/tmp/cargo-issue-17125-repro/bar",
        },
        ArtifactDep(
            Tuple(
                "aarch64-apple-darwin",
            ),
        ),
    ),
]
stack backtrace:
   0: __rustc::rust_begin_unwind
   1: core::panicking::panic_fmt
   2: <cargo::core::resolver::features::ResolvedFeatures>::activated_features
   3: cargo::ops::tree::graph::add_pkg
   4: cargo::ops::tree::graph::add_pkg
   5: cargo::ops::tree::build_and_print
   6: cargo::commands::tree::exec
   7: <cargo::cli::Exec>::exec
   8: cargo::main
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

This is related to prior bindeps / cargo tree bugs such as #10593 and #12358, but this case appears distinct because it depends on target = "target".

Steps

Create this project:

# Cargo.toml
[package]
name = "foo"
version = "0.0.0"
edition = "2024"
resolver = "3"

[build-dependencies]
bar = { path = "bar", artifact = "cdylib", target = "target" }
// src/lib.rs
// build.rs
fn main() {}
# bar/Cargo.toml
[package]
name = "bar"
version = "0.5.0"
edition = "2024"
resolver = "3"

[lib]
crate-type = ["cdylib"]

[dependencies]
pm = { path = "../pm" }
// bar/src/lib.rs
# pm/Cargo.toml
[package]
name = "pm"
version = "0.1.0"
edition = "2024"
resolver = "3"

[lib]
proc-macro = true
// pm/src/lib.rs

Then run:

$ cargo +nightly check -Z bindeps
$ cargo +nightly tree -Z bindeps

check succeeds, but tree panics.

A draft PR with a regression test is available at #17124.

Version

cargo 1.96.0 (30a34c682 2026-05-25)
release: 1.96.0
commit-hash: 30a34c6821b57de0aaec83a901aca39f88f6778c
commit-date: 2026-05-25
host: aarch64-apple-darwin
libgit2: 1.9.2 (sys:0.20.4 vendored)
libcurl: 8.7.1 (sys:0.4.87+curl-8.19.0 system ssl:(SecureTransport) LibreSSL/3.3.6)
ssl: OpenSSL 3.5.4 30 Sep 2025
os: Mac OS 26.5.1 [64-bit]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions