Skip to content

Feature enabled, but dependent crate not added #15490

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
A4-Tacks opened this issue May 5, 2025 · 5 comments
Open

Feature enabled, but dependent crate not added #15490

A4-Tacks opened this issue May 5, 2025 · 5 comments
Labels
A-dev-dependencies Area: [dev-dependencies] A-features Area: features — conditional compilation C-bug Category: bug S-needs-mentor Status: Issue or feature is accepted, but needs a team member to commit to helping and reviewing.

Comments

@A4-Tacks
Copy link

A4-Tacks commented May 5, 2025

Problem

Feature enabled, but dependent crate not added

Using build-dependencies, dev-dependencies, and dependencies in the dependency graph

Steps

  1. Run this bash script

    #!/usr/bin/bash
    set -ex
    
    until rm -rf rustc-test; do :; done
    
    cargo new rustc-test && cd "$_"
    echo > src/lib.rs
    echo '[workspace]' >> Cargo.toml
    
    
    cargo new --lib subcrate && pushd "$_"
    cargo add quote --build --optional
    echo 'default = ["quote"]' >> Cargo.toml
    echo > src/lib.rs
    echo '#[cfg(feature = "quote")] extern crate quote as _;' >> build.rs
    echo 'fn main() {}' >> build.rs
    
    cargo test --tests
    cargo test --tests --no-default-features
    popd
    
    
    cargo new --lib mid && pushd "$_"
    cargo add --path ../subcrate --dev --no-default-features
    echo '[features]' >> Cargo.toml
    echo 'default = ["subcrate/quote"]' >> Cargo.toml
    echo > src/lib.rs
    
    cargo test --tests
    cargo test --tests --no-default-features
    popd
    
    
    cargo add --path subcrate --no-default-features
    cargo add --path mid
    echo > src/lib.rs
    echo '[features]' >> Cargo.toml
    echo 'default = ["subcrate/quote"]' >> Cargo.toml
    
    cargo test --tests
    cargo test --tests --no-default-features
    
    cargo test --workspace --tests
    cargo test --workspace --no-default-features --tests # failed

    Output:

    $ bash rustc-test.sh
    + rm -rf rustc-test
    + cargo new rustc-test
        Creating binary (application) `rustc-test` package
    note: see more `Cargo.toml` keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
    + cd rustc-test
    + echo
    + echo '[workspace]'
    + cargo new --lib subcrate
        Creating library `subcrate` package
          Adding `subcrate` as member of workspace at `/home/lrne/Project/Rust/rustc-test`
    note: see more `Cargo.toml` keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
    + pushd subcrate
    ~/Project/Rust/rustc-test/subcrate ~/Project/Rust/rustc-test
    + cargo add quote --build --optional
        Updating `rsproxy-sparse` index
          Adding quote v1.0.40 to optional build-dependencies
                 Features:
                 + proc-macro
          Adding feature `quote`
        Updating `rsproxy-sparse` index
         Locking 3 packages to latest Rust 1.86.0 compatible versions
    + echo 'default = ["quote"]'
    + echo
    + echo '#[cfg(feature = "quote")] extern crate quote as _;'
    + echo 'fn main() {}'
    + cargo test --tests
       Compiling proc-macro2 v1.0.95
       Compiling unicode-ident v1.0.18
       Compiling quote v1.0.40
       Compiling subcrate v0.1.0 (/home/lrne/Project/Rust/rustc-test/subcrate)
        Finished `test` profile [unoptimized + debuginfo] target(s) in 3.00s
         Running unittests src/lib.rs (/home/lrne/Project/Rust/rustc-test/target/debug/deps/subcrate-94541aa21b80c44f)
    
    running 0 tests
    
    test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
    
    + cargo test --tests --no-default-features
       Compiling subcrate v0.1.0 (/home/lrne/Project/Rust/rustc-test/subcrate)
        Finished `test` profile [unoptimized + debuginfo] target(s) in 1.29s
         Running unittests src/lib.rs (/home/lrne/Project/Rust/rustc-test/target/debug/deps/subcrate-c4eee531dfecc19b)
    
    running 0 tests
    
    test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
    
    + popd
    ~/Project/Rust/rustc-test
    + cargo new --lib mid
        Creating library `mid` package
          Adding `mid` as member of workspace at `/home/lrne/Project/Rust/rustc-test`
    note: see more `Cargo.toml` keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
    + pushd mid
    ~/Project/Rust/rustc-test/mid ~/Project/Rust/rustc-test
    + cargo add --path ../subcrate --dev --no-default-features
          Adding subcrate (local) to dev-dependencies
                 Features as of v0.1.0:
                 - quote
    + echo '[features]'
    + echo 'default = ["subcrate/quote"]'
    + echo
    + cargo test --tests
       Compiling subcrate v0.1.0 (/home/lrne/Project/Rust/rustc-test/subcrate)
       Compiling mid v0.1.0 (/home/lrne/Project/Rust/rustc-test/mid)
        Finished `test` profile [unoptimized + debuginfo] target(s) in 1.40s
         Running unittests src/lib.rs (/home/lrne/Project/Rust/rustc-test/target/debug/deps/mid-8962487b66cf9953)
    
    running 0 tests
    
    test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
    
    + cargo test --tests --no-default-features
       Compiling subcrate v0.1.0 (/home/lrne/Project/Rust/rustc-test/subcrate)
       Compiling mid v0.1.0 (/home/lrne/Project/Rust/rustc-test/mid)
        Finished `test` profile [unoptimized + debuginfo] target(s) in 0.92s
         Running unittests src/lib.rs (/home/lrne/Project/Rust/rustc-test/target/debug/deps/mid-cb9e5d41193179a9)
    
    running 0 tests
    
    test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
    
    + popd
    ~/Project/Rust/rustc-test
    + cargo add --path subcrate --no-default-features
          Adding subcrate (local) to dependencies
                 Features:
                 - quote
    + cargo add --path mid
          Adding mid (local) to dependencies
    + echo
    + echo '[features]'
    + echo 'default = ["subcrate/quote"]'
    + cargo test --tests
       Compiling mid v0.1.0 (/home/lrne/Project/Rust/rustc-test/mid)
       Compiling rustc-test v0.1.0 (/home/lrne/Project/Rust/rustc-test)
        Finished `test` profile [unoptimized + debuginfo] target(s) in 1.07s
         Running unittests src/lib.rs (target/debug/deps/rustc_test-a9728c865edf09fc)
    
    running 0 tests
    
    test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
    
         Running unittests src/main.rs (target/debug/deps/rustc_test-aaa5eafe71c52ad2)
    
    running 0 tests
    
    test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
    
    + cargo test --tests --no-default-features
       Compiling rustc-test v0.1.0 (/home/lrne/Project/Rust/rustc-test)
        Finished `test` profile [unoptimized + debuginfo] target(s) in 0.97s
         Running unittests src/lib.rs (target/debug/deps/rustc_test-4c7adacd8a58681b)
    
    running 0 tests
    
    test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
    
         Running unittests src/main.rs (target/debug/deps/rustc_test-60344cd12e2de624)
    
    running 0 tests
    
    test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
    
    + cargo test --workspace --tests
       Compiling subcrate v0.1.0 (/home/lrne/Project/Rust/rustc-test/subcrate)
       Compiling rustc-test v0.1.0 (/home/lrne/Project/Rust/rustc-test)
       Compiling mid v0.1.0 (/home/lrne/Project/Rust/rustc-test/mid)
        Finished `test` profile [unoptimized + debuginfo] target(s) in 1.36s
         Running unittests src/lib.rs (target/debug/deps/mid-96e1286cb7a7970e)
    
    running 0 tests
    
    test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
    
         Running unittests src/lib.rs (target/debug/deps/rustc_test-a1becec4804655f8)
    
    running 0 tests
    
    test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
    
         Running unittests src/main.rs (target/debug/deps/rustc_test-1a1fa43b8d3282e2)
    
    running 0 tests
    
    test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
    
         Running unittests src/lib.rs (target/debug/deps/subcrate-94541aa21b80c44f)
    
    running 0 tests
    
    test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
    
    + cargo test --workspace --no-default-features --tests
       Compiling subcrate v0.1.0 (/home/lrne/Project/Rust/rustc-test/subcrate)
    error[E0463]: can't find crate for `quote`
     --> subcrate/build.rs:1:27
      |
    1 | #[cfg(feature = "quote")] extern crate quote as _;
      |                           ^^^^^^^^^^^^^^^^^^^^^^^^ can't find crate
    
    For more information about this error, try `rustc --explain E0463`.
    error: could not compile `subcrate` (build script) due to 1 previous error
    

Possible Solution(s)

No response

Notes

About --no-default-features on --workspace

Version

cargo 1.86.0 (adf9b6ad1 2025-02-28)
release: 1.86.0
commit-hash: adf9b6ad14cfa10ff680d5806741a144f7163698
commit-date: 2025-02-28
host: aarch64-unknown-linux-gnu
libgit2: 1.9.0 (sys:0.20.0 vendored)
libcurl: 8.12.0-DEV (sys:0.4.79+curl-8.12.0 vendored ssl:OpenSSL/1.1.1w)
ssl: OpenSSL 1.1.1w  11 Sep 2023
os: Arch Linux [64-bit]
@A4-Tacks A4-Tacks added C-bug Category: bug S-triage Status: This issue is waiting on initial triage. labels May 5, 2025
@epage epage added the A-features Area: features — conditional compilation label May 5, 2025
@epage
Copy link
Contributor

epage commented May 5, 2025

This can be worked around by setting workspace.resolver = "1" which unifies build/normal dependencies.

So somehow feature = "quite" is being set on a Build unit while quote isn't built.

(note: this is a modified version where quote is opt-in instead of default)

$ cargo clean
     Removed 867 files, 153.7MiB total

$ cargo test --workspace
   Compiling subcrate v0.1.0 (/home/epage/src/personal/dump/cargo-15490/rustc-test/subcrate)
   Compiling mid v0.1.0 (/home/epage/src/personal/dump/cargo-15490/rustc-test/mid)
error[E0463]: can't find crate for `quote`
 --> subcrate/build.rs:1:27
  |
1 | #[cfg(feature = "quote")] extern crate quote as _;
  |                           ^^^^^^^^^^^^^^^^^^^^^^^^ can't find crate

For more information about this error, try `rustc --explain E0463`.
error: could not compile `subcrate` (build script) due to 1 previous error

$ cargo test --workspace -F quote
   Compiling proc-macro2 v1.0.95
   Compiling unicode-ident v1.0.18
   Compiling quote v1.0.40
   Compiling subcrate v0.1.0 (/home/epage/src/personal/dump/cargo-15490/rustc-test/subcrate)
   Compiling rustc-test v0.1.0 (/home/epage/src/personal/dump/cargo-15490/rustc-test)
   Compiling mid v0.1.0 (/home/epage/src/personal/dump/cargo-15490/rustc-test/mid)
    Finished `test` profile [unoptimized + debuginfo] target(s) in 0.62s
     Running unittests src/lib.rs (target/debug/deps/mid-b6c7b47a02cb0245)
$ cargo tree --no-default-features -e features --workspace
mid v0.1.0 (/home/epage/src/personal/dump/cargo-15490/rustc-test/mid)
[dev-dependencies]
└── subcrate v0.1.0 (/home/epage/src/personal/dump/cargo-15490/rustc-test/subcrate)

rustc-test v0.1.0 (/home/epage/src/personal/dump/cargo-15490/rustc-test)
├── subcrate v0.1.0 (/home/epage/src/personal/dump/cargo-15490/rustc-test/subcrate)
├── mid feature "default"
│   └── mid v0.1.0 (/home/epage/src/personal/dump/cargo-15490/rustc-test/mid) (*)
└── mid feature "quote"
    ├── mid v0.1.0 (/home/epage/src/personal/dump/cargo-15490/rustc-test/mid) (*)
    └── subcrate feature "quote"
        └── subcrate v0.1.0 (/home/epage/src/personal/dump/cargo-15490/rustc-test/subcrate)

subcrate v0.1.0 (/home/epage/src/personal/dump/cargo-15490/rustc-test/subcrate)

$ cargo tree --no-default-features -e features --workspace -F quote
mid v0.1.0 (/home/epage/src/personal/dump/cargo-15490/rustc-test/mid)
[dev-dependencies]
└── subcrate v0.1.0 (/home/epage/src/personal/dump/cargo-15490/rustc-test/subcrate)
    [build-dependencies]
    └── quote feature "default"
        ├── quote v1.0.40
        │   └── proc-macro2 v1.0.95
        │       └── unicode-ident feature "default"
        │           └── unicode-ident v1.0.18
        └── quote feature "proc-macro"
            ├── quote v1.0.40 (*)
            └── proc-macro2 feature "proc-macro"
                └── proc-macro2 v1.0.95 (*)

rustc-test v0.1.0 (/home/epage/src/personal/dump/cargo-15490/rustc-test)
├── subcrate v0.1.0 (/home/epage/src/personal/dump/cargo-15490/rustc-test/subcrate) (*)
├── mid feature "default"
│   └── mid v0.1.0 (/home/epage/src/personal/dump/cargo-15490/rustc-test/mid) (*)
└── mid feature "quote" (command-line)
    ├── mid v0.1.0 (/home/epage/src/personal/dump/cargo-15490/rustc-test/mid) (*)
    └── subcrate feature "quote" (command-line)
        └── subcrate v0.1.0 (/home/epage/src/personal/dump/cargo-15490/rustc-test/subcrate) (*)

subcrate v0.1.0 (/home/epage/src/personal/dump/cargo-15490/rustc-test/subcrate) (*)

Trying different combinations:

  • This does not reproduce if the dev-dependency is changed to a regular dependency
  • This still reproduces if you change the explicit feature to an implicit feature
  • Switching the build dependency to a regular still reproduces it

Looking through logs:

When we walk the features, the dep is already missing

compare the failing case:

TRACE main:exec:compile_ws:create_bcx:resolve_ws_with_opts:resolve: cargo::core::resolver::features: activate_pkg mid 
TRACE main:exec:compile_ws:create_bcx:resolve_ws_with_opts:resolve: cargo::core::resolver::features: activate_pkg subcrate 
TRACE main:exec:compile_ws:create_bcx:resolve_ws_with_opts:resolve: cargo::core::resolver::features: activate_pkg subcrate 
TRACE main:exec:compile_ws:create_bcx:resolve_ws_with_opts:resolve: cargo::core::resolver::features: activate_pkg rustc-test 
TRACE main:exec:compile_ws:create_bcx:resolve_ws_with_opts:resolve: cargo::core::resolver::features: activate_pkg mid 
TRACE main:exec:compile_ws:create_bcx:resolve_ws_with_opts:resolve: cargo::core::resolver::features: activate_fv mid  quote
TRACE main:exec:compile_ws:create_bcx:resolve_ws_with_opts:resolve: cargo::core::resolver::features: activate_rec mid  feat=quote
TRACE main:exec:compile_ws:create_bcx:resolve_ws_with_opts:resolve: cargo::core::resolver::features: activate_fv mid  subcrate/quote
TRACE main:exec:compile_ws:create_bcx:resolve_ws_with_opts:resolve: cargo::core::resolver::features: activate_dep_feature mid  dep_name=subcrate dep_feature=quote weak=false
TRACE main:exec:compile_ws:create_bcx:resolve_ws_with_opts:resolve: cargo::core::resolver::features: activate_fv subcrate  quote
TRACE main:exec:compile_ws:create_bcx:resolve_ws_with_opts:resolve: cargo::core::resolver::features: activate_rec subcrate  feat=quote
TRACE main:exec:compile_ws:create_bcx:resolve_ws_with_opts:resolve: cargo::core::resolver::features: activate_fv subcrate  dep:quote
TRACE main:exec:compile_ws:create_bcx:resolve_ws_with_opts:resolve: cargo::core::resolver::features: activate_dependency subcrate  dep_name=quote
TRACE main:exec:compile_ws:create_bcx:resolve_ws_with_opts:resolve: cargo::core::resolver::features: to_enable=None
TRACE main:exec:compile_ws:create_bcx:resolve_ws_with_opts:resolve: cargo::core::resolver::features: activate_pkg subcrate 

against the success case:

TRACE main:exec:compile_ws:create_bcx:resolve_ws_with_opts:resolve: cargo::core::resolver::features: activate_pkg mid 
TRACE main:exec:compile_ws:create_bcx:resolve_ws_with_opts:resolve: cargo::core::resolver::features: activate_pkg subcrate 
TRACE main:exec:compile_ws:create_bcx:resolve_ws_with_opts:resolve: cargo::core::resolver::features: activate_pkg subcrate 
TRACE main:exec:compile_ws:create_bcx:resolve_ws_with_opts:resolve: cargo::core::resolver::features: activate_pkg rustc-test 
TRACE main:exec:compile_ws:create_bcx:resolve_ws_with_opts:resolve: cargo::core::resolver::features: activate_fv rustc-test  quote
TRACE main:exec:compile_ws:create_bcx:resolve_ws_with_opts:resolve: cargo::core::resolver::features: activate_rec rustc-test  feat=quote
TRACE main:exec:compile_ws:create_bcx:resolve_ws_with_opts:resolve: cargo::core::resolver::features: activate_fv rustc-test  subcrate/quote
TRACE main:exec:compile_ws:create_bcx:resolve_ws_with_opts:resolve: cargo::core::resolver::features: activate_dep_feature rustc-test  dep_name=subcrate dep_feature=quote weak=false
TRACE main:exec:compile_ws:create_bcx:resolve_ws_with_opts:resolve: cargo::core::resolver::features: activate_fv subcrate  quote
TRACE main:exec:compile_ws:create_bcx:resolve_ws_with_opts:resolve: cargo::core::resolver::features: activate_rec subcrate  feat=quote
TRACE main:exec:compile_ws:create_bcx:resolve_ws_with_opts:resolve: cargo::core::resolver::features: activate_fv subcrate  dep:quote
TRACE main:exec:compile_ws:create_bcx:resolve_ws_with_opts:resolve: cargo::core::resolver::features: activate_dependency subcrate  dep_name=quote
TRACE main:exec:compile_ws:create_bcx:resolve_ws_with_opts:resolve: cargo::core::resolver::features: to_enable=None
TRACE main:exec:compile_ws:create_bcx:resolve_ws_with_opts:resolve: cargo::core::resolver::features: dep_pkg_id="quote"
TRACE main:exec:compile_ws:create_bcx:resolve_ws_with_opts:resolve: cargo::core::resolver::features: fvs=[
    Feature(
        "default",
    ),
]
TRACE main:exec:compile_ws:create_bcx:resolve_ws_with_opts:resolve: cargo::core::resolver::features: activate_pkg quote host
TRACE main:exec:compile_ws:create_bcx:resolve_ws_with_opts:resolve: cargo::core::resolver::features: activate_fv quote host default
TRACE main:exec:compile_ws:create_bcx:resolve_ws_with_opts:resolve: cargo::core::resolver::features: activate_rec quote host feat=default
TRACE main:exec:compile_ws:create_bcx:resolve_ws_with_opts:resolve: cargo::core::resolver::features: activate_fv quote host proc-macro
TRACE main:exec:compile_ws:create_bcx:resolve_ws_with_opts:resolve: cargo::core::resolver::features: activate_rec quote host feat=proc-macro
TRACE main:exec:compile_ws:create_bcx:resolve_ws_with_opts:resolve: cargo::core::resolver::features: activate_fv quote host proc-macro2/proc-macro
TRACE main:exec:compile_ws:create_bcx:resolve_ws_with_opts:resolve: cargo::core::resolver::features: activate_dep_feature quote host dep_name=proc-macro2 dep_feature=proc-macro weak=false
TRACE main:exec:compile_ws:create_bcx:resolve_ws_with_opts:resolve: cargo::core::resolver::features: activate_fv proc-macro2 host proc-macro
TRACE main:exec:compile_ws:create_bcx:resolve_ws_with_opts:resolve: cargo::core::resolver::features: activate_rec proc-macro2 host feat=proc-macro
TRACE main:exec:compile_ws:create_bcx:resolve_ws_with_opts:resolve: cargo::core::resolver::features: activate_pkg proc-macro2 host
TRACE main:exec:compile_ws:create_bcx:resolve_ws_with_opts:resolve: cargo::core::resolver::features: activate_pkg unicode-ident host
TRACE main:exec:compile_ws:create_bcx:resolve_ws_with_opts:resolve: cargo::core::resolver::features: activate_pkg mid 
TRACE main:exec:compile_ws:create_bcx:resolve_ws_with_opts:resolve: cargo::core::resolver::features: activate_fv mid  quote
TRACE main:exec:compile_ws:create_bcx:resolve_ws_with_opts:resolve: cargo::core::resolver::features: activate_rec mid  feat=quote
TRACE main:exec:compile_ws:create_bcx:resolve_ws_with_opts:resolve: cargo::core::resolver::features: activate_fv mid  subcrate/quote
TRACE main:exec:compile_ws:create_bcx:resolve_ws_with_opts:resolve: cargo::core::resolver::features: activate_dep_feature mid  dep_name=subcrate dep_feature=quote weak=false
TRACE main:exec:compile_ws:create_bcx:resolve_ws_with_opts:resolve: cargo::core::resolver::features: activate_fv subcrate  quote
TRACE main:exec:compile_ws:create_bcx:resolve_ws_with_opts:resolve: cargo::core::resolver::features: activate_rec subcrate  feat=quote
TRACE main:exec:compile_ws:create_bcx:resolve_ws_with_opts:resolve: cargo::core::resolver::features: activate_pkg subcrate 
So looking at our walking of dependencies

resolve_ws_with_opts calling resolve_with_registry

   0.006444033s TRACE main:exec:compile_ws:create_bcx:resolve_with_registry:resolve_with_previous: cargo::ops::resolve: previous: graph: Graph {
  - mid v0.1.0 (/home/epage/src/personal/dump/cargo-15490/rustc-test/mid)
    - subcrate v0.1.0 (/home/epage/src/personal/dump/cargo-15490/rustc-test/subcrate)
  - proc-macro2 v1.0.95
    - unicode-ident v1.0.18
  - quote v1.0.40
    - proc-macro2 v1.0.95
  - rustc-test v0.1.0 (/home/epage/src/personal/dump/cargo-15490/rustc-test)
    - mid v0.1.0 (/home/epage/src/personal/dump/cargo-15490/rustc-test/mid)
    - subcrate v0.1.0 (/home/epage/src/personal/dump/cargo-15490/rustc-test/subcrate)
  - subcrate v0.1.0 (/home/epage/src/personal/dump/cargo-15490/rustc-test/subcrate)
    - quote v1.0.40
  - unicode-ident v1.0.18
}

features: {
}

   0.006934862s TRACE main:exec:compile_ws:create_bcx:resolve_with_registry:resolve_with_previous:resolve: cargo::core::resolver: resolved: graph: Graph {
  - mid v0.1.0 (/home/epage/src/personal/dump/cargo-15490/rustc-test/mid)
    - subcrate v0.1.0 (/home/epage/src/personal/dump/cargo-15490/rustc-test/subcrate)
  - proc-macro2 v1.0.95
    - unicode-ident v1.0.18
  - quote v1.0.40
    - proc-macro2 v1.0.95
  - rustc-test v0.1.0 (/home/epage/src/personal/dump/cargo-15490/rustc-test)
    - mid v0.1.0 (/home/epage/src/personal/dump/cargo-15490/rustc-test/mid)
    - subcrate v0.1.0 (/home/epage/src/personal/dump/cargo-15490/rustc-test/subcrate)
  - subcrate v0.1.0 (/home/epage/src/personal/dump/cargo-15490/rustc-test/subcrate)
    - quote v1.0.40
  - unicode-ident v1.0.18
}

features: {
  subcrate v0.1.0 (/home/epage/src/personal/dump/cargo-15490/rustc-test/subcrate): ["quote"]
  proc-macro2 v1.0.95: ["proc-macro"]
  rustc-test v0.1.0 (/home/epage/src/personal/dump/cargo-15490/rustc-test): ["quote"]
  quote v1.0.40: ["default", "proc-macro"]
  mid v0.1.0 (/home/epage/src/personal/dump/cargo-15490/rustc-test/mid): ["quote"]
}

resolve_ws_with_opts calling resolve_with_previous

   0.007338712s TRACE main:exec:compile_ws:create_bcx:resolve_with_previous: cargo::ops::resolve: previous: graph: Graph {
  - mid v0.1.0 (/home/epage/src/personal/dump/cargo-15490/rustc-test/mid)
    - subcrate v0.1.0 (/home/epage/src/personal/dump/cargo-15490/rustc-test/subcrate)
  - proc-macro2 v1.0.95
    - unicode-ident v1.0.18
  - quote v1.0.40
    - proc-macro2 v1.0.95
  - rustc-test v0.1.0 (/home/epage/src/personal/dump/cargo-15490/rustc-test)
    - mid v0.1.0 (/home/epage/src/personal/dump/cargo-15490/rustc-test/mid)
    - subcrate v0.1.0 (/home/epage/src/personal/dump/cargo-15490/rustc-test/subcrate)
  - subcrate v0.1.0 (/home/epage/src/personal/dump/cargo-15490/rustc-test/subcrate)
    - quote v1.0.40
  - unicode-ident v1.0.18
}

features: {
  subcrate v0.1.0 (/home/epage/src/personal/dump/cargo-15490/rustc-test/subcrate): ["quote"]
  proc-macro2 v1.0.95: ["proc-macro"]
  rustc-test v0.1.0 (/home/epage/src/personal/dump/cargo-15490/rustc-test): ["quote"]
  quote v1.0.40: ["default", "proc-macro"]
  mid v0.1.0 (/home/epage/src/personal/dump/cargo-15490/rustc-test/mid): ["quote"]
}

   0.007483405s TRACE main:exec:compile_ws:create_bcx:resolve_with_previous:resolve: cargo::core::resolver: resolved: graph: Graph {
  - mid v0.1.0 (/home/epage/src/personal/dump/cargo-15490/rustc-test/mid)
    - subcrate v0.1.0 (/home/epage/src/personal/dump/cargo-15490/rustc-test/subcrate)
  - rustc-test v0.1.0 (/home/epage/src/personal/dump/cargo-15490/rustc-test)
    - mid v0.1.0 (/home/epage/src/personal/dump/cargo-15490/rustc-test/mid)
    - subcrate v0.1.0 (/home/epage/src/personal/dump/cargo-15490/rustc-test/subcrate)
  - subcrate v0.1.0 (/home/epage/src/personal/dump/cargo-15490/rustc-test/subcrate)
}

features: {
  mid v0.1.0 (/home/epage/src/personal/dump/cargo-15490/rustc-test/mid): ["quote"]
}


@epage epage added the A-dev-dependencies Area: [dev-dependencies] label May 5, 2025
@epage
Copy link
Contributor

epage commented May 5, 2025

Features referencing dev-dependencies is something that has had mixed results

EDIT: Note that this was a resolver error until #9060 was fixed in 2eee644

@epage
Copy link
Contributor

epage commented May 5, 2025

My current reproduction steps

$ cargo init --lib
$ cargo new mid --lib
$ cargo new subcrate --lib

Cargo.toml:

[workspace]
resolver = "2"
members = [ "mid","subcrate"]

[package]
name = "rustc-test"
version = "0.1.0"
edition = "2024"

[dependencies]
mid = { version = "0.1.0", path = "mid", features = ["quote"] }
subcrate = { version = "0.1.0", path = "subcrate", default-features = false }

[features]
quote = ["subcrate/quote"]

mid/Cargo.toml:

[package]
name = "mid"
version = "0.1.0"
edition = "2024"

[dev-dependencies]
subcrate = { path = "../subcrate", default-features = false }

[features]
quote = ["subcrate/quote"]

subcrate/Cargo.toml:

[package]
name = "subcrate"
version = "0.1.0"
edition = "2024"

[dependencies]
quote = { version = "1.0.40", optional = true }

@ehuss
Copy link
Contributor

ehuss commented May 5, 2025

I think I see the problem. It lies in this line here.

The problem is that it is considering dev-dependencies enabled or disabled as a global property. However, there's an interesting interplay of the mid crate being both a root (with no default features, thus its dev-dep isn't activating the feature) and as a dependency (with default features, thus its dev dep feature is activated).

There needs to be some more nuance there, perhaps differentiating if something is being resolved as a root versus as a dependency. Need to think a little if that makes sense.

@epage epage added S-needs-mentor Status: Issue or feature is accepted, but needs a team member to commit to helping and reviewing. and removed S-triage Status: This issue is waiting on initial triage. labels May 5, 2025
ehuss added a commit to ehuss/cargo that referenced this issue May 5, 2025
@ehuss
Copy link
Contributor

ehuss commented May 5, 2025

I have a WIP up here: https://github.com/ehuss/cargo/commits/feature-dev-deps/

The general idea is that the feature resolver needs to mirror the same behavior in the dependency resolver here.

It mostly works except one test is failing. I'm also a little unhappy with the added complexity. It could push this state into FeaturesFor, but I very much don't want to make FeaturesFor even more complicated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-dev-dependencies Area: [dev-dependencies] A-features Area: features — conditional compilation C-bug Category: bug S-needs-mentor Status: Issue or feature is accepted, but needs a team member to commit to helping and reviewing.
Projects
None yet
Development

No branches or pull requests

3 participants