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

Refactor feature_powerset function to handle mutually exclusive features correctly #235

Merged
merged 1 commit into from
Feb 16, 2024
Merged
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
23 changes: 18 additions & 5 deletions src/features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,9 @@ pub(crate) fn feature_powerset<'a>(
.filter(move |fs| {
// Filter any feature set containing more than one feature from the same mutually
// exclusive group.
let mut count = 0;
for f in fs.iter().flat_map(|f| f.as_group()) {
for group in mutually_exclusive_features {
for group in mutually_exclusive_features {
let mut count = 0;
for f in fs.iter().flat_map(|f| f.as_group()) {
if group.matches(f) {
count += 1;
if count > 1 {
Expand Down Expand Up @@ -353,8 +353,8 @@ mod tests {

let map = map![("tokio", v![]), ("async-std", v![]), ("a", v![]), ("b", v!["a"])];
let list = v!["a", "b", "tokio", "async-std"];
let filtered =
feature_powerset(&list, None, &[], &["tokio".into(), "async-std".into()], &map);
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"],
Expand All @@ -365,6 +365,19 @@ mod tests {
vec!["a", "async-std"],
vec!["b", "async-std"]
]);

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

#[test]
Expand Down