@@ -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 ( ) ;
@@ -268,15 +321,15 @@ fn migrate_manifests(ws: &Workspace<'_>, pkgs: &[&Package]) -> CargoResult<()> {
268321 format ! ( "{file} from {existing_edition} edition to {prepare_for_edition}" ) ,
269322 ) ?;
270323
324+ let mut manifest_mut = LocalManifest :: try_new ( pkg. manifest_path ( ) ) ?;
325+ let document = & mut manifest_mut. data ;
326+ let mut fixes = 0 ;
327+
271328 let ws_original_toml = match ws. root_maybe ( ) {
272329 MaybePackage :: Package ( package) => package. manifest ( ) . original_toml ( ) ,
273330 MaybePackage :: Virtual ( manifest) => manifest. original_toml ( ) ,
274331 } ;
275332 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-
280333 let root = document. as_table_mut ( ) ;
281334
282335 if let Some ( workspace) = root
@@ -331,14 +384,14 @@ fn migrate_manifests(ws: &Workspace<'_>, pkgs: &[&Package]) -> CargoResult<()> {
331384 ws_original_toml,
332385 ) ;
333386 }
387+ }
334388
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) ?;
339393
340- manifest_mut. write ( ) ?;
341- }
394+ manifest_mut. write ( ) ?;
342395 }
343396 }
344397
0 commit comments