@@ -161,8 +161,7 @@ fn parse_section(args: &ArgMatches) -> DepTable {
161
161
/// Clean up the workspace.dependencies, profile, patch, and replace sections of the root manifest
162
162
/// by removing dependencies which no longer have a reference to them.
163
163
fn 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 ( ) ) ?;
166
165
let mut is_modified = true ;
167
166
168
167
let members = workspace
@@ -204,6 +203,7 @@ fn gc_workspace(workspace: &Workspace<'_>) -> CargoResult<()> {
204
203
// Clean up the workspace.dependencies section and replace instances of
205
204
// workspace dependencies with their definitions
206
205
if let Some ( toml_edit:: Item :: Table ( deps_table) ) = workspace_manifest
206
+ . data
207
207
. get_mut ( "workspace" )
208
208
. and_then ( |t| t. get_mut ( "dependencies" ) )
209
209
{
@@ -247,7 +247,7 @@ fn gc_workspace(workspace: &Workspace<'_>) -> CargoResult<()> {
247
247
// - profile.dev.package.foo
248
248
// - profile.release.package."foo:2.1.0"
249
249
if let Some ( toml_edit:: Item :: Table ( profile_section_table) ) =
250
- workspace_manifest. get_mut ( "profile" )
250
+ workspace_manifest. data . get_mut ( "profile" )
251
251
{
252
252
profile_section_table. set_implicit ( true ) ;
253
253
@@ -282,7 +282,7 @@ fn gc_workspace(workspace: &Workspace<'_>) -> CargoResult<()> {
282
282
}
283
283
284
284
// 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" ) {
286
286
table. set_implicit ( true ) ;
287
287
288
288
for ( key, item) in table. iter_mut ( ) {
@@ -298,10 +298,7 @@ fn gc_workspace(workspace: &Workspace<'_>) -> CargoResult<()> {
298
298
}
299
299
300
300
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 ( ) ?;
305
302
}
306
303
307
304
Ok ( ( ) )
@@ -342,12 +339,13 @@ fn spec_has_match(
342
339
343
340
/// Removes unused patches from the manifest
344
341
fn 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 ( ) ) ?;
347
343
let mut modified = false ;
348
344
349
345
// 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
+ {
351
349
patch_section_table. set_implicit ( true ) ;
352
350
353
351
for ( _, item) in patch_section_table. iter_mut ( ) {
@@ -385,10 +383,7 @@ fn gc_unused_patches(workspace: &Workspace<'_>, resolve: &Resolve) -> CargoResul
385
383
}
386
384
387
385
if modified {
388
- cargo_util:: paths:: write (
389
- workspace. root_manifest ( ) ,
390
- workspace_manifest. to_string ( ) . as_bytes ( ) ,
391
- ) ?;
386
+ workspace_manifest. write ( ) ?;
392
387
}
393
388
394
389
Ok ( modified)
0 commit comments