@@ -252,6 +252,59 @@ fn check_version_control(gctx: &GlobalContext, opts: &FixOptions) -> CargoResult
252252}
253253
254254fn 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+
255308 for pkg in pkgs {
256309 let existing_edition = pkg. manifest ( ) . edition ( ) ;
257310 let prepare_for_edition = existing_edition. saturating_next ( ) ;
0 commit comments