Browse Source

fix(cli): correctly remove Cargo features (#7013)

Lucas Fernandes Nogueira 2 years ago
parent
commit
1253bbf7ae
2 changed files with 12 additions and 5 deletions
  1. 6 0
      .changes/fix-feature-removal.md
  2. 6 5
      tooling/cli/src/interface/rust/manifest.rs

+ 6 - 0
.changes/fix-feature-removal.md

@@ -0,0 +1,6 @@
+---
+'cli.rs': 'patch'
+'cli.js': 'patch'
+---
+
+Fixes Cargo.toml feature rewriting.

+ 6 - 5
tooling/cli/src/interface/rust/manifest.rs

@@ -146,14 +146,15 @@ fn write_features(
       }
 
       // remove features that shouldn't be in the manifest anymore
-      let mut i = 0;
-      while i < features_array.len() {
-        if let Some(f) = features_array.get(i).and_then(|f| f.as_str()) {
+      let mut i = features_array.len();
+      while i != 0 {
+        let index = i - 1;
+        if let Some(f) = features_array.get(index).and_then(|f| f.as_str()) {
           if !features.contains(f) {
-            features_array.remove(i);
+            features_array.remove(index);
           }
         }
-        i += 1;
+        i -= 1;
       }
     } else {
       *manifest_features = Item::Value(Value::Array(toml_array(features)));