Skip to content

Commit 5ce1e42

Browse files
committed
refactor(fix): Reload the workspace
This opens the door for fixing the workspace
1 parent 4402351 commit 5ce1e42

File tree

3 files changed

+21
-6
lines changed

3 files changed

+21
-6
lines changed

src/bin/cargo/commands/fix.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ pub fn exec(gctx: &mut GlobalContext, args: &ArgMatches) -> CliResult {
7171
// Unlike other commands default `cargo fix` to all targets to fix as much
7272
// code as we can.
7373
let root_manifest = args.root_manifest(gctx)?;
74-
let ws = Workspace::new(&root_manifest, gctx)?;
74+
let mut ws = Workspace::new(&root_manifest, gctx)?;
75+
ws.set_honor_rust_version(args.honor_rust_version());
7576
let mut opts = args.compile_options(gctx, mode, Some(&ws), ProfileChecking::LegacyTestOnly)?;
7677

7778
if !opts.filter.is_specific() {
@@ -80,7 +81,9 @@ pub fn exec(gctx: &mut GlobalContext, args: &ArgMatches) -> CliResult {
8081
}
8182

8283
ops::fix(
84+
gctx,
8385
&ws,
86+
&root_manifest,
8487
&mut ops::FixOptions {
8588
edition: args.flag("edition"),
8689
idioms: args.flag("edition-idioms"),

src/cargo/core/workspace.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -611,6 +611,10 @@ impl<'gctx> Workspace<'gctx> {
611611
self.honor_rust_version = honor_rust_version;
612612
}
613613

614+
pub fn honor_rust_version(&self) -> Option<bool> {
615+
self.honor_rust_version
616+
}
617+
614618
pub fn resolve_honors_rust_version(&self) -> bool {
615619
self.gctx().cli_unstable().msrv_policy && self.honor_rust_version.unwrap_or(true)
616620
}

src/cargo/ops/fix.rs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,19 @@ pub struct FixOptions {
8787
pub broken_code: bool,
8888
}
8989

90-
pub fn fix(ws: &Workspace<'_>, opts: &mut FixOptions) -> CargoResult<()> {
91-
check_version_control(ws.gctx(), opts)?;
90+
pub fn fix(
91+
gctx: &GlobalContext,
92+
original_ws: &Workspace<'_>,
93+
root_manifest: &Path,
94+
opts: &mut FixOptions,
95+
) -> CargoResult<()> {
96+
check_version_control(gctx, opts)?;
97+
9298
if opts.edition {
93-
check_resolver_change(ws, opts)?;
99+
check_resolver_change(&original_ws, opts)?;
94100
}
101+
let mut ws = Workspace::new(&root_manifest, gctx)?;
102+
ws.set_honor_rust_version(original_ws.honor_rust_version());
95103

96104
// Spin up our lock server, which our subprocesses will use to synchronize fixes.
97105
let lock_server = LockServer::new()?;
@@ -128,7 +136,7 @@ pub fn fix(ws: &Workspace<'_>, opts: &mut FixOptions) -> CargoResult<()> {
128136
server.configure(&mut wrapper);
129137
}
130138

131-
let rustc = ws.gctx().load_global_rustc(Some(ws))?;
139+
let rustc = ws.gctx().load_global_rustc(Some(&ws))?;
132140
wrapper.arg(&rustc.path);
133141
// This is calling rustc in cargo fix-proxy-mode, so it also need to retry.
134142
// The argfile handling are located at `FixArgs::from_args`.
@@ -138,7 +146,7 @@ pub fn fix(ws: &Workspace<'_>, opts: &mut FixOptions) -> CargoResult<()> {
138146
// repeating build until there are no more changes to be applied
139147
opts.compile_opts.build_config.primary_unit_rustc = Some(wrapper);
140148

141-
ops::compile(ws, &opts.compile_opts)?;
149+
ops::compile(&ws, &opts.compile_opts)?;
142150
Ok(())
143151
}
144152

0 commit comments

Comments
 (0)