@@ -161,8 +161,7 @@ fn parse_section(args: &ArgMatches) -> DepTable {
161161/// Clean up the workspace.dependencies, profile, patch, and replace sections of the root manifest
162162/// by removing dependencies which no longer have a reference to them.
163163fn gc_workspace ( workspace : & Workspace < ' _ > ) -> CargoResult < ( ) > {
164- let mut workspace_manifest: toml_edit:: DocumentMut =
165- cargo_util:: paths:: read ( workspace. root_manifest ( ) ) ?. parse ( ) ?;
164+ let mut workspace_manifest = LocalManifest :: try_new ( workspace. root_manifest ( ) ) ?;
166165 let mut is_modified = true ;
167166
168167 let members = workspace
@@ -204,6 +203,7 @@ fn gc_workspace(workspace: &Workspace<'_>) -> CargoResult<()> {
204203 // Clean up the workspace.dependencies section and replace instances of
205204 // workspace dependencies with their definitions
206205 if let Some ( toml_edit:: Item :: Table ( deps_table) ) = workspace_manifest
206+ . data
207207 . get_mut ( "workspace" )
208208 . and_then ( |t| t. get_mut ( "dependencies" ) )
209209 {
@@ -247,7 +247,7 @@ fn gc_workspace(workspace: &Workspace<'_>) -> CargoResult<()> {
247247 // - profile.dev.package.foo
248248 // - profile.release.package."foo:2.1.0"
249249 if let Some ( toml_edit:: Item :: Table ( profile_section_table) ) =
250- workspace_manifest. get_mut ( "profile" )
250+ workspace_manifest. data . get_mut ( "profile" )
251251 {
252252 profile_section_table. set_implicit ( true ) ;
253253
@@ -282,7 +282,7 @@ fn gc_workspace(workspace: &Workspace<'_>) -> CargoResult<()> {
282282 }
283283
284284 // Clean up the replace section
285- if let Some ( toml_edit:: Item :: Table ( table) ) = workspace_manifest. get_mut ( "replace" ) {
285+ if let Some ( toml_edit:: Item :: Table ( table) ) = workspace_manifest. data . get_mut ( "replace" ) {
286286 table. set_implicit ( true ) ;
287287
288288 for ( key, item) in table. iter_mut ( ) {
@@ -298,10 +298,7 @@ fn gc_workspace(workspace: &Workspace<'_>) -> CargoResult<()> {
298298 }
299299
300300 if is_modified {
301- cargo_util:: paths:: write_atomic (
302- workspace. root_manifest ( ) ,
303- workspace_manifest. to_string ( ) . as_bytes ( ) ,
304- ) ?;
301+ workspace_manifest. write ( ) ?;
305302 }
306303
307304 Ok ( ( ) )
@@ -342,12 +339,13 @@ fn spec_has_match(
342339
343340/// Removes unused patches from the manifest
344341fn gc_unused_patches ( workspace : & Workspace < ' _ > , resolve : & Resolve ) -> CargoResult < bool > {
345- let mut workspace_manifest: toml_edit:: DocumentMut =
346- cargo_util:: paths:: read ( workspace. root_manifest ( ) ) ?. parse ( ) ?;
342+ let mut workspace_manifest = LocalManifest :: try_new ( workspace. root_manifest ( ) ) ?;
347343 let mut modified = false ;
348344
349345 // Clean up the patch section
350- if let Some ( toml_edit:: Item :: Table ( patch_section_table) ) = workspace_manifest. get_mut ( "patch" ) {
346+ if let Some ( toml_edit:: Item :: Table ( patch_section_table) ) =
347+ workspace_manifest. data . get_mut ( "patch" )
348+ {
351349 patch_section_table. set_implicit ( true ) ;
352350
353351 for ( _, item) in patch_section_table. iter_mut ( ) {
@@ -385,10 +383,7 @@ fn gc_unused_patches(workspace: &Workspace<'_>, resolve: &Resolve) -> CargoResul
385383 }
386384
387385 if modified {
388- cargo_util:: paths:: write (
389- workspace. root_manifest ( ) ,
390- workspace_manifest. to_string ( ) . as_bytes ( ) ,
391- ) ?;
386+ workspace_manifest. write ( ) ?;
392387 }
393388
394389 Ok ( modified)
0 commit comments