@@ -252,6 +252,59 @@ fn check_version_control(gctx: &GlobalContext, opts: &FixOptions) -> CargoResult
252
252
}
253
253
254
254
fn migrate_manifests ( ws : & Workspace < ' _ > , pkgs : & [ & Package ] ) -> CargoResult < ( ) > {
255
+ // HACK: Duplicate workspace migration logic between virtual manifests and real manifests to
256
+ // reduce multiple Migrating messages being reported for the same file to the user
257
+ if matches ! ( ws. root_maybe( ) , MaybePackage :: Virtual ( _) ) {
258
+ // Warning: workspaces do not have an edition so this should only include changes needed by
259
+ // packages that preserve the behavior of the workspace on all editions
260
+ let highest_edition = pkgs
261
+ . iter ( )
262
+ . map ( |p| p. manifest ( ) . edition ( ) )
263
+ . max ( )
264
+ . unwrap_or_default ( ) ;
265
+ let prepare_for_edition = highest_edition. saturating_next ( ) ;
266
+ if highest_edition == prepare_for_edition
267
+ || ( !prepare_for_edition. is_stable ( ) && !ws. gctx ( ) . nightly_features_allowed )
268
+ {
269
+ //
270
+ } else {
271
+ let mut manifest_mut = LocalManifest :: try_new ( ws. root_manifest ( ) ) ?;
272
+ let document = & mut manifest_mut. data ;
273
+ let mut fixes = 0 ;
274
+
275
+ if Edition :: Edition2024 <= prepare_for_edition {
276
+ let root = document. as_table_mut ( ) ;
277
+
278
+ if let Some ( workspace) = root
279
+ . get_mut ( "workspace" )
280
+ . and_then ( |t| t. as_table_like_mut ( ) )
281
+ {
282
+ // strictly speaking, the edition doesn't apply to this table but it should be safe
283
+ // enough
284
+ fixes += rename_dep_fields_2024 ( workspace, "dependencies" ) ;
285
+ }
286
+ }
287
+
288
+ if 0 < fixes {
289
+ // HACK: As workspace migration is a special case, only report it if something
290
+ // happened
291
+ let file = ws. root_manifest ( ) ;
292
+ let file = file. strip_prefix ( ws. root ( ) ) . unwrap_or ( file) ;
293
+ let file = file. display ( ) ;
294
+ ws. gctx ( ) . shell ( ) . status (
295
+ "Migrating" ,
296
+ format ! ( "{file} from {highest_edition} edition to {prepare_for_edition}" ) ,
297
+ ) ?;
298
+
299
+ let verb = if fixes == 1 { "fix" } else { "fixes" } ;
300
+ let msg = format ! ( "{file} ({fixes} {verb})" ) ;
301
+ ws. gctx ( ) . shell ( ) . status ( "Fixed" , msg) ?;
302
+
303
+ manifest_mut. write ( ) ?;
304
+ }
305
+ }
306
+ }
307
+
255
308
for pkg in pkgs {
256
309
let existing_edition = pkg. manifest ( ) . edition ( ) ;
257
310
let prepare_for_edition = existing_edition. saturating_next ( ) ;
@@ -268,15 +321,15 @@ fn migrate_manifests(ws: &Workspace<'_>, pkgs: &[&Package]) -> CargoResult<()> {
268
321
format ! ( "{file} from {existing_edition} edition to {prepare_for_edition}" ) ,
269
322
) ?;
270
323
324
+ let mut manifest_mut = LocalManifest :: try_new ( pkg. manifest_path ( ) ) ?;
325
+ let document = & mut manifest_mut. data ;
326
+ let mut fixes = 0 ;
327
+
271
328
let ws_original_toml = match ws. root_maybe ( ) {
272
329
MaybePackage :: Package ( package) => package. manifest ( ) . original_toml ( ) ,
273
330
MaybePackage :: Virtual ( manifest) => manifest. original_toml ( ) ,
274
331
} ;
275
332
if Edition :: Edition2024 <= prepare_for_edition {
276
- let mut manifest_mut = LocalManifest :: try_new ( pkg. manifest_path ( ) ) ?;
277
- let document = & mut manifest_mut. data ;
278
- let mut fixes = 0 ;
279
-
280
333
let root = document. as_table_mut ( ) ;
281
334
282
335
if let Some ( workspace) = root
@@ -331,14 +384,14 @@ fn migrate_manifests(ws: &Workspace<'_>, pkgs: &[&Package]) -> CargoResult<()> {
331
384
ws_original_toml,
332
385
) ;
333
386
}
387
+ }
334
388
335
- if 0 < fixes {
336
- let verb = if fixes == 1 { "fix" } else { "fixes" } ;
337
- let msg = format ! ( "{file} ({fixes} {verb})" ) ;
338
- ws. gctx ( ) . shell ( ) . status ( "Fixed" , msg) ?;
389
+ if 0 < fixes {
390
+ let verb = if fixes == 1 { "fix" } else { "fixes" } ;
391
+ let msg = format ! ( "{file} ({fixes} {verb})" ) ;
392
+ ws. gctx ( ) . shell ( ) . status ( "Fixed" , msg) ?;
339
393
340
- manifest_mut. write ( ) ?;
341
- }
394
+ manifest_mut. write ( ) ?;
342
395
}
343
396
}
344
397
0 commit comments