@@ -2446,6 +2446,95 @@ edition = "2021"
2446
2446
) ;
2447
2447
}
2448
2448
2449
+ #[ cargo_test]
2450
+ fn migrate_removes_project_for_script ( ) {
2451
+ let p = project ( )
2452
+ . file (
2453
+ "foo.rs" ,
2454
+ r#"
2455
+ ---
2456
+ # Before package
2457
+ [ package ] # After package header
2458
+ # After package header line
2459
+ name = "foo"
2460
+ edition = "2021"
2461
+ # After package table
2462
+
2463
+ # Before project
2464
+ [ project ] # After project header
2465
+ # After project header line
2466
+ name = "foo"
2467
+ edition = "2021"
2468
+ # After project table
2469
+ ---
2470
+
2471
+ fn main() {
2472
+ }
2473
+ "# ,
2474
+ )
2475
+ . build ( ) ;
2476
+
2477
+ p. cargo ( "-Zscript fix --edition --allow-no-vcs --manifest-path foo.rs" )
2478
+ . masquerade_as_nightly_cargo ( & [ "script" ] )
2479
+ . with_stderr_data ( str![ [ r#"
2480
+ [MIGRATING] foo.rs from 2021 edition to 2024
2481
+ [FIXED] foo.rs (1 fix)
2482
+ [WARNING] `package.edition` is unspecified, defaulting to `2024`
2483
+ [CHECKING] foo v0.0.0 ([ROOT]/foo)
2484
+ [WARNING] `foo.rs` is already on the latest edition (2024), unable to migrate further
2485
+
2486
+ If you are trying to migrate from the previous edition (2021), the
2487
+ process requires following these steps:
2488
+
2489
+ 1. Start with `edition = "2021"` in `Cargo.toml`
2490
+ 2. Run `cargo fix --edition`
2491
+ 3. Modify `Cargo.toml` to set `edition = "2024"`
2492
+ 4. Run `cargo build` or `cargo test` to verify the fixes worked
2493
+
2494
+ More details may be found at
2495
+ https://doc.rust-lang.org/edition-guide/editions/transitioning-an-existing-project-to-a-new-edition.html
2496
+
2497
+ [ERROR] expected item, found `[`
2498
+ --> foo.rs:1:1
2499
+ |
2500
+ 1 | [[bin]]
2501
+ | ^ expected item
2502
+ |
2503
+ = [NOTE] for a full list of items that can appear in modules, see <https://doc.rust-lang.org/reference/items.html>
2504
+
2505
+ [ERROR] could not compile `foo` (bin "foo" test) due to 1 previous error
2506
+ [WARNING] build failed, waiting for other jobs to finish...
2507
+ [ERROR] could not compile `foo` (bin "foo") due to 1 previous error
2508
+
2509
+ "# ] ] )
2510
+ . with_status ( 101 )
2511
+ . run ( ) ;
2512
+ assert_e2e ( ) . eq (
2513
+ p. read_file ( "foo.rs" ) ,
2514
+ str![ [ r#"
2515
+ [[bin]]
2516
+ name = "foo"
2517
+ path = "[ROOT]/home/.cargo/target/[HASH]/foo.rs"
2518
+
2519
+ [package]
2520
+ autobenches = false
2521
+ autobins = false
2522
+ autoexamples = false
2523
+ autolib = false
2524
+ autotests = false
2525
+ build = false
2526
+ edition = "2021"
2527
+ name = "foo"
2528
+
2529
+ [profile.release]
2530
+ strip = true
2531
+
2532
+ [workspace]
2533
+
2534
+ "# ] ] ,
2535
+ ) ;
2536
+ }
2537
+
2449
2538
#[ cargo_test]
2450
2539
fn migrate_rename_underscore_fields ( ) {
2451
2540
let p = project ( )
0 commit comments