-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Closed as duplicate of#4463
Closed as duplicate of#4463
Copy link
Labels
A-featuresArea: features — conditional compilationArea: features — conditional compilationC-feature-requestCategory: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`S-triageStatus: This issue is waiting on initial triage.Status: This issue is waiting on initial triage.
Description
Problem
Let's say I have a request with two crates, a lib and a bin.
Cargo.toml
[workspace]
resolver = "2"
members = [
"my_lib", "my_bin"
]
[workspace.dependencies]
my_lib = { path = "./my_lib" }
my_lib/Cargo.toml
[package]
name = "my_lib"
version = "0.1.0"
edition = "2021"
[dependencies]
[features]
default = []
feature_b = []
my_lib/src/lib.rs
pub struct MyStruct {
pub a: u64,
#[cfg(feature = "feature_b")]
pub b: u64,
}
my_bin/Cargo.toml
[package]
name = "my_bin"
version = "0.1.0"
edition = "2021"
[dependencies]
my_lib = { workspace = true }
my_bin/src/main.rs
use my_lib::MyStruct;
fn main() {
let my_struct = MyStruct { a: 42 };
println!("{}", my_struct.a);
}
Running cargo check --all-features
at the workspace level I get:
cargo check --all-features
Checking my_lib v0.1.0 (/private/tmp/wrspc/my_lib)
Checking my_bin v0.1.0 (/private/tmp/wrspc/my_bin)
error[E0063]: missing field `b` in initializer of `MyStruct`
--> my_bin/src/main.rs:4:21
|
4 | let my_struct = MyStruct { a: 42 };
| ^^^^^^^^ missing `b`
For more information about this error, try `rustc --explain E0063`.
error: could not compile `my_bin` (bin "my_bin") due to 1 previous error
Meaning it's compiling the my_bin using my_lib with feature.feature_b enabled.
To me it seems like an error, as the my_bin crate doesn't ever specify the use of the feature_b
feature, which is not enabled by default in my_lib
.
Proposed Solution
The behavior I would expect is:
- build my_lib with all ITS features enabled (here, feature_b)
- build my_bin with all ITS features enabled (here, none) but for it's dependencies, only add the features specified, not all existing
Notes
No response
Metadata
Metadata
Assignees
Labels
A-featuresArea: features — conditional compilationArea: features — conditional compilationC-feature-requestCategory: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`S-triageStatus: This issue is waiting on initial triage.Status: This issue is waiting on initial triage.