File tree Expand file tree Collapse file tree 2 files changed +27
-1
lines changed
Expand file tree Collapse file tree 2 files changed +27
-1
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ " cli.rs " : patch
3+ " cli.js " : patch
4+ ---
5+
6+ Preserve the ` Cargo.toml ` formatting when the features array is not changed.
Original file line number Diff line number Diff line change @@ -125,7 +125,27 @@ fn write_features(
125125 }
126126 }
127127 }
128- * manifest_features = Item :: Value ( Value :: Array ( toml_array ( features) ) ) ;
128+ if let Some ( features_array) = manifest_features. as_array_mut ( ) {
129+ // add features that aren't in the manifest
130+ for feature in features. iter ( ) {
131+ if !features_array. iter ( ) . any ( |f| f. as_str ( ) == Some ( feature) ) {
132+ features_array. insert ( 0 , feature. as_str ( ) ) ;
133+ }
134+ }
135+
136+ // remove features that shouldn't be in the manifest anymore
137+ let mut i = 0 ;
138+ while i < features_array. len ( ) {
139+ if let Some ( f) = features_array. get ( i) . and_then ( |f| f. as_str ( ) ) {
140+ if !features. contains ( f) {
141+ features_array. remove ( i) ;
142+ }
143+ }
144+ i += 1 ;
145+ }
146+ } else {
147+ * manifest_features = Item :: Value ( Value :: Array ( toml_array ( features) ) ) ;
148+ }
129149 Ok ( true )
130150 } else if let Some ( dep) = item. as_value_mut ( ) {
131151 match dep {
You can’t perform that action at this time.
0 commit comments