@@ -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,53 @@ 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
+ self . get_table_mut ( table_path)
422
+ if let Some ( toml_edit:: Item :: Table ( profile_table) ) = self . data . get_mut ( "profile" ) {
423
+ profile_table. set_implicit ( true ) ;
424
+ for ( _, item) in profile_table. iter_mut ( ) {
425
+ if let toml_edit:: Item :: Table ( profile_table) = item {
426
+ profile_table. set_implicit ( true ) ;
427
+ if let Some ( toml_edit:: Item :: Table ( package_table) ) = profile_table. get_mut ( "package" ) {
428
+ package_table. set_implicit ( true ) ;
429
+ package_table. remove ( dep_key) ;
430
+ }
431
+ }
432
+ }
433
+ }
434
+
435
+ // clean up patch sections
436
+ if let Some ( toml_edit:: Item :: Table ( patch_table) ) = self . data . get_mut ( "patch" ) {
437
+ patch_table. set_implicit ( true ) ;
438
+ for ( _, item) in patch_table. iter_mut ( ) {
439
+ if let toml_edit:: Item :: Table ( table) = item {
440
+ table. set_implicit ( true ) ;
441
+ for ( key, item) in table. iter_mut ( ) {
442
+ if key. get ( ) == dep_key {
443
+ * item = toml_edit:: Item :: None ;
444
+ }
445
+ }
446
+ }
447
+ }
448
+ }
449
+
450
+ // clean up replace section
451
+ if let Some ( toml_edit:: Item :: Table ( replace_table) ) = self . data . get_mut ( "replace" ) {
452
+ replace_table. set_implicit ( true ) ;
453
+ for ( key, item) in replace_table. iter_mut ( ) {
454
+ if let Ok ( spec) = PackageIdSpec :: parse ( key. get ( ) ) {
455
+ if spec. name ( ) == dep_key {
456
+ * item = toml_edit:: Item :: None ;
457
+ }
458
+ }
459
+ }
460
+ }
412
461
}
413
462
414
463
fn is_explicit_dep_activation ( & self , dep_key : & str ) -> bool {
@@ -500,7 +549,7 @@ fn fix_feature_activations(
500
549
} )
501
550
. collect ( ) ;
502
551
503
- // Remove found idx in revers order so we don't invalidate the idx.
552
+ // Remove found idx in reverse order so we don't invalidate the idx.
504
553
for idx in remove_list. iter ( ) . rev ( ) {
505
554
feature_values. remove ( * idx) ;
506
555
}
0 commit comments