mirror of
https://github.com/rust-lang/cargo.git
synced 2025-09-28 11:20:36 +00:00
fix(fix): Migrate cargo script manifests across editions
At this point it is unlikely for a script to be written for pre-2024 edition and migrated to 2024+ but this code is independent of Editions so this means we have one less bug and are better prepared for the next edition. When we add `cargo fix` support for regular manifest warnings, we'll need to take into account cargo scripts. This is a part of #12207.
This commit is contained in:
parent
a609028eae
commit
ed3947f2ef
@ -61,6 +61,7 @@ use crate::ops::resolve::WorkspaceResolve;
|
||||
use crate::ops::{self, CompileOptions};
|
||||
use crate::util::diagnostic_server::{Message, RustfixDiagnosticServer};
|
||||
use crate::util::errors::CargoResult;
|
||||
use crate::util::toml_mut::manifest::LocalManifest;
|
||||
use crate::util::GlobalContext;
|
||||
use crate::util::{existing_vcs_repo, LockServer, LockServerClient};
|
||||
use crate::{drop_eprint, drop_eprintln};
|
||||
@ -272,7 +273,8 @@ fn migrate_manifests(ws: &Workspace<'_>, pkgs: &[&Package]) -> CargoResult<()> {
|
||||
MaybePackage::Virtual(manifest) => manifest.original_toml(),
|
||||
};
|
||||
if Edition::Edition2024 <= prepare_for_edition {
|
||||
let mut document = pkg.manifest().document().clone().into_mut();
|
||||
let mut manifest_mut = LocalManifest::try_new(pkg.manifest_path())?;
|
||||
let document = &mut manifest_mut.data;
|
||||
let mut fixes = 0;
|
||||
|
||||
let root = document.as_table_mut();
|
||||
@ -335,9 +337,7 @@ fn migrate_manifests(ws: &Workspace<'_>, pkgs: &[&Package]) -> CargoResult<()> {
|
||||
let msg = format!("{file} ({fixes} {verb})");
|
||||
ws.gctx().shell().status("Fixed", msg)?;
|
||||
|
||||
let s = document.to_string();
|
||||
let new_contents_bytes = s.as_bytes();
|
||||
cargo_util::paths::write_atomic(pkg.manifest_path(), new_contents_bytes)?;
|
||||
manifest_mut.write()?;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2479,57 +2479,27 @@ fn main() {
|
||||
.with_stderr_data(str![[r#"
|
||||
[MIGRATING] foo.rs from 2021 edition to 2024
|
||||
[FIXED] foo.rs (1 fix)
|
||||
[WARNING] `package.edition` is unspecified, defaulting to `2024`
|
||||
[CHECKING] foo v0.0.0 ([ROOT]/foo)
|
||||
[WARNING] `foo.rs` is already on the latest edition (2024), unable to migrate further
|
||||
|
||||
If you are trying to migrate from the previous edition (2021), the
|
||||
process requires following these steps:
|
||||
|
||||
1. Start with `edition = "2021"` in `Cargo.toml`
|
||||
2. Run `cargo fix --edition`
|
||||
3. Modify `Cargo.toml` to set `edition = "2024"`
|
||||
4. Run `cargo build` or `cargo test` to verify the fixes worked
|
||||
|
||||
More details may be found at
|
||||
https://doc.rust-lang.org/edition-guide/editions/transitioning-an-existing-project-to-a-new-edition.html
|
||||
|
||||
[ERROR] expected item, found `[`
|
||||
--> foo.rs:1:1
|
||||
|
|
||||
1 | [[bin]]
|
||||
| ^ expected item
|
||||
|
|
||||
= [NOTE] for a full list of items that can appear in modules, see <https://doc.rust-lang.org/reference/items.html>
|
||||
|
||||
[ERROR] could not compile `foo` (bin "foo" test) due to 1 previous error
|
||||
[WARNING] build failed, waiting for other jobs to finish...
|
||||
[ERROR] could not compile `foo` (bin "foo") due to 1 previous error
|
||||
[MIGRATING] [ROOT]/home/.cargo/target/[HASH]/foo.rs from 2021 edition to 2024
|
||||
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
|
||||
|
||||
"#]])
|
||||
.with_status(101)
|
||||
.run();
|
||||
assert_e2e().eq(
|
||||
p.read_file("foo.rs"),
|
||||
str![[r#"
|
||||
[[bin]]
|
||||
name = "foo"
|
||||
path = "[ROOT]/home/.cargo/target/[HASH]/foo.rs"
|
||||
|
||||
[package]
|
||||
autobenches = false
|
||||
autobins = false
|
||||
autoexamples = false
|
||||
autolib = false
|
||||
autotests = false
|
||||
build = false
|
||||
---
|
||||
# Before package
|
||||
[ package ] # After package header
|
||||
# After package header line
|
||||
name = "foo"
|
||||
edition = "2021"
|
||||
name = "foo"
|
||||
# After project table
|
||||
---
|
||||
|
||||
[profile.release]
|
||||
strip = true
|
||||
|
||||
[workspace]
|
||||
fn main() {
|
||||
}
|
||||
|
||||
"#]],
|
||||
);
|
||||
|
Loading…
x
Reference in New Issue
Block a user