@@ -486,9 +486,7 @@ impl Dependency {
486
486
if str_or_1_len_table ( item) {
487
487
// Nothing to preserve
488
488
* item = self . to_toml ( crate_root) ;
489
- if self . source != Some ( Source :: Workspace ( WorkspaceSource ) ) {
490
- key. fmt ( ) ;
491
- }
489
+ key. fmt ( ) ;
492
490
} else if let Some ( table) = item. as_table_like_mut ( ) {
493
491
match & self . source {
494
492
Some ( Source :: Registry ( src) ) => {
@@ -940,6 +938,7 @@ impl Display for WorkspaceSource {
940
938
mod tests {
941
939
use std:: path:: Path ;
942
940
941
+ use crate :: ops:: cargo_add:: manifest:: LocalManifest ;
943
942
use cargo_util:: paths;
944
943
945
944
use super :: * ;
@@ -1123,6 +1122,25 @@ mod tests {
1123
1122
verify_roundtrip ( & crate_root, key, & item) ;
1124
1123
}
1125
1124
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
+
1126
1144
#[ test]
1127
1145
#[ cfg( windows) ]
1128
1146
fn normalise_windows_style_paths ( ) {
0 commit comments