From cd6306bb38c9b6c2f07a6f1a644b1b2118b5a92e Mon Sep 17 00:00:00 2001 From: Taiki Endo Date: Sun, 22 Oct 2023 13:36:56 +0900 Subject: [PATCH] Do not use BTreeSet in Features::new --- CHANGELOG.md | 4 +++- src/features.rs | 9 ++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6960e070..cb76caa1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,13 +10,15 @@ Note: In this file, do not use the hard wrap in the middle of a sentence for com ## [Unreleased] +- Fix handling of optional dependency as features when namespaced features are not used together. This fixes a regression introduced in 0.6.11. + ## [0.6.12] - 2023-10-18 - Fix compatibility with old Cargo. This fixes a regression introduced in 0.6.11. ## [0.6.11] - 2023-10-18 -- Fix handling of weak dependency features when namespaced features is not used together. +- Fix handling of weak dependency features when namespaced features are not used together. - Improve performance by passing `--no-deps` to `cargo metadata` except when using `--include-deps-features`. diff --git a/src/features.rs b/src/features.rs index f1060f27..6d9ce76f 100644 --- a/src/features.rs +++ b/src/features.rs @@ -23,7 +23,7 @@ impl Features { ) -> Self { let package = &metadata.packages[id]; - let mut features: BTreeSet<_> = manifest.features.keys().map(Feature::from).collect(); + let mut features: Vec<_> = manifest.features.keys().map(Feature::from).collect(); let mut has_namespaced_features = false; // features with `dep:` prefix // package.features.values() does not provide a way to determine the `dep:` specified by the user. @@ -40,7 +40,10 @@ impl Features { // treated as implicit features. if !has_namespaced_features { for name in package.optional_deps() { - features.insert(name.into()); + let feature = Feature::from(name); + if !features.contains(&feature) { + features.push(feature); + } } } let deps_features_start = features.len(); @@ -64,7 +67,7 @@ impl Features { } } - Self { features: features.into_iter().collect(), optional_deps_start, deps_features_start } + Self { features, optional_deps_start, deps_features_start } } pub(crate) fn normal(&self) -> &[Feature] {