Skip to content

Commit

Permalink
Fix --mutually-exclusive-features containing optional deps (#261)
Browse files Browse the repository at this point in the history
  • Loading branch information
xStrom authored Dec 10, 2024
1 parent 8fa7f67 commit 9017a5f
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
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

0 comments on commit 9017a5f

Please sign in to comment.