Skip to content
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

Fix --mutually-exclusive-features containing optional deps. #261

Merged
merged 2 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ Note: In this file, do not use the hard wrap in the middle of a sentence for com

## [Unreleased]

- Fix `--mutually-exclusive-features` interacting with optional dependencies. ([#261](https://github.com/taiki-e/cargo-hack/pull/261), thanks @xStrom)

## [0.6.33] - 2024-11-02

- Allow using `--exclude` without also specifying `--workspace`. ([#258](https://github.com/taiki-e/cargo-hack/pull/258), thanks @xStrom)
Expand Down
30 changes: 29 additions & 1 deletion src/features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,16 @@ impl Feature {
) -> bool {
if let Some(v) = map.get(cur) {
for cur in v {
if cur != root && (group.matches(cur) || rec(group, map, cur, root)) {
let fname = if let Some(slash_idx) = cur.find('/') {
// The fname may still have a '?' suffix, which is fine.
// Because in that case it doesn't activate that dependency, so it can be ignored.
let (fname, _) = cur.split_at(slash_idx);
fname
} else {
// Could be 'dep:something', which is fine because it's not a feature.
cur
};
if fname != root && (group.matches(fname) || rec(group, map, fname, root)) {
return true;
}
}
Expand Down Expand Up @@ -396,6 +405,25 @@ mod tests {
vec!["b", "async-std"]
]);

let map = map![
("tokio", v![]),
("async-std", v![]),
("a", v!["tokio/full"]),
("b", v!["async-std?/alloc"])
];
let list = v!["a", "b", "tokio", "async-std"];
let mutually_exclusive_features = [Feature::group(["tokio", "async-std"])];
let filtered = feature_powerset(&list, None, &[], &mutually_exclusive_features, &map);
assert_eq!(filtered, vec![
vec!["a"],
vec!["b"],
vec!["a", "b"],
vec!["tokio"],
vec!["b", "tokio"],
vec!["async-std"],
vec!["b", "async-std"]
]);

let map = map![("a", v![]), ("b", v!["a"]), ("c", v![]), ("d", v!["b"])];
let list = v!["a", "b", "c", "d"];
let mutually_exclusive_features = [Feature::group(["a", "c"])];
Expand Down
Loading