@@ -486,9 +486,7 @@ impl Dependency {
486486 if str_or_1_len_table ( item) {
487487 // Nothing to preserve
488488 * item = self . to_toml ( crate_root) ;
489- if self . source != Some ( Source :: Workspace ( WorkspaceSource ) ) {
490- key. fmt ( ) ;
491- }
489+ key. fmt ( ) ;
492490 } else if let Some ( table) = item. as_table_like_mut ( ) {
493491 match & self . source {
494492 Some ( Source :: Registry ( src) ) => {
@@ -940,6 +938,7 @@ impl Display for WorkspaceSource {
940938mod tests {
941939 use std:: path:: Path ;
942940
941+ use crate :: ops:: cargo_add:: manifest:: LocalManifest ;
943942 use cargo_util:: paths;
944943
945944 use super :: * ;
@@ -1123,6 +1122,25 @@ mod tests {
11231122 verify_roundtrip ( & crate_root, key, & item) ;
11241123 }
11251124
1125+ #[ test]
1126+ fn overwrite_with_workspace_source_fmt_key ( ) {
1127+ let crate_root =
1128+ paths:: normalize_path ( & std:: env:: current_dir ( ) . unwrap ( ) . join ( Path :: new ( "./" ) ) ) ;
1129+ let toml = "dep = \" 1.0\" \n " ;
1130+ let manifest = toml. parse ( ) . unwrap ( ) ;
1131+ let mut local = LocalManifest {
1132+ path : crate_root. clone ( ) ,
1133+ manifest,
1134+ } ;
1135+ assert_eq ! ( local. manifest. to_string( ) , toml) ;
1136+ for ( key, item) in local. data . clone ( ) . iter ( ) {
1137+ let dep = Dependency :: from_toml ( & crate_root, key, item) . unwrap ( ) ;
1138+ let dep = dep. set_source ( WorkspaceSource :: new ( ) ) ;
1139+ local. insert_into_table ( & vec ! [ ] , & dep) . unwrap ( ) ;
1140+ assert_eq ! ( local. data. to_string( ) , "dep.workspace = true\n " ) ;
1141+ }
1142+ }
1143+
11261144 #[ test]
11271145 #[ cfg( windows) ]
11281146 fn normalise_windows_style_paths ( ) {
0 commit comments