@@ -9,6 +9,7 @@ use anyhow::Context as _;
99use super :: dependency:: Dependency ;
1010use crate :: core:: dependency:: DepKind ;
1111use crate :: core:: FeatureValue ;
12+ use crate :: core:: PackageIdSpec ;
1213use crate :: util:: interning:: InternedString ;
1314use crate :: CargoResult ;
1415
@@ -393,6 +394,7 @@ impl LocalManifest {
393394 let explicit_dep_activation = self . is_explicit_dep_activation ( dep_key) ;
394395 let status = self . dep_status ( dep_key) ;
395396
397+ // clean up features
396398 if let Some ( toml_edit:: Item :: Table ( feature_table) ) =
397399 self . data . as_table_mut ( ) . get_mut ( "features" )
398400 {
@@ -409,6 +411,49 @@ impl LocalManifest {
409411 }
410412 }
411413 }
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+ }
412457 }
413458
414459 fn is_explicit_dep_activation ( & self , dep_key : & str ) -> bool {
@@ -500,7 +545,7 @@ fn fix_feature_activations(
500545 } )
501546 . collect ( ) ;
502547
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.
504549 for idx in remove_list. iter ( ) . rev ( ) {
505550 feature_values. remove ( * idx) ;
506551 }
0 commit comments