@@ -9,6 +9,7 @@ use anyhow::Context as _;
9
9
use super :: dependency:: Dependency ;
10
10
use crate :: core:: dependency:: DepKind ;
11
11
use crate :: core:: FeatureValue ;
12
+ use crate :: core:: PackageIdSpec ;
12
13
use crate :: util:: interning:: InternedString ;
13
14
use crate :: CargoResult ;
14
15
@@ -393,6 +394,7 @@ impl LocalManifest {
393
394
let explicit_dep_activation = self . is_explicit_dep_activation ( dep_key) ;
394
395
let status = self . dep_status ( dep_key) ;
395
396
397
+ // clean up features
396
398
if let Some ( toml_edit:: Item :: Table ( feature_table) ) =
397
399
self . data . as_table_mut ( ) . get_mut ( "features" )
398
400
{
@@ -409,6 +411,49 @@ impl LocalManifest {
409
411
}
410
412
}
411
413
}
414
+
415
+ // continue only if the dep is fully removed
416
+ if status != DependencyStatus :: None {
417
+ return ;
418
+ }
419
+
420
+ // clean up profile sections
421
+ let profile_table_path = [
422
+ "profile" . to_owned ( ) ,
423
+ "dev" . to_owned ( ) ,
424
+ "package" . to_owned ( ) ,
425
+ dep_key. to_owned ( ) ,
426
+ ] ;
427
+ if let Ok ( item @ toml_edit:: Item :: Table ( _) ) = self . get_table_mut ( & profile_table_path) {
428
+ * item = toml_edit:: Item :: None
429
+ }
430
+
431
+ // clean up patch sections
432
+ if let Some ( toml_edit:: Item :: Table ( patch_table) ) = self . data . get_mut ( "patch" ) {
433
+ patch_table. set_implicit ( true ) ;
434
+ for ( _, item) in patch_table. iter_mut ( ) {
435
+ if let toml_edit:: Item :: Table ( table) = item {
436
+ table. set_implicit ( true ) ;
437
+ for ( key, item) in table. iter_mut ( ) {
438
+ if key. get ( ) == dep_key {
439
+ * item = toml_edit:: Item :: None ;
440
+ }
441
+ }
442
+ }
443
+ }
444
+ }
445
+
446
+ // clean up replace section
447
+ if let Some ( toml_edit:: Item :: Table ( replace_table) ) = self . data . get_mut ( "replace" ) {
448
+ replace_table. set_implicit ( true ) ;
449
+ for ( key, item) in replace_table. iter_mut ( ) {
450
+ if let Ok ( spec) = PackageIdSpec :: parse ( key. get ( ) ) {
451
+ if spec. name ( ) == dep_key {
452
+ * item = toml_edit:: Item :: None ;
453
+ }
454
+ }
455
+ }
456
+ }
412
457
}
413
458
414
459
fn is_explicit_dep_activation ( & self , dep_key : & str ) -> bool {
@@ -500,7 +545,7 @@ fn fix_feature_activations(
500
545
} )
501
546
. collect ( ) ;
502
547
503
- // Remove found idx in revers order so we don't invalidate the idx.
548
+ // Remove found idx in reverse order so we don't invalidate the idx.
504
549
for idx in remove_list. iter ( ) . rev ( ) {
505
550
feature_values. remove ( * idx) ;
506
551
}
0 commit comments