Skip to content

Commit

Permalink
docs: Improve comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Orion Gonzalez committed Feb 17, 2025
1 parent 3b784a4 commit aec9450
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
9 changes: 6 additions & 3 deletions src/bin/cargo/commands/fix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,6 @@ pub fn exec(gctx: &mut GlobalContext, args: &ArgMatches) -> CliResult {
args.get_one::<String>("profile").map(String::as_str),
Some("test")
);
let mode = CompileMode::Check { test };

// Unlike other commands default `cargo fix` to all targets to fix as much
// code as we can.
let root_manifest = args.root_manifest(gctx)?;
Expand All @@ -79,7 +77,12 @@ pub fn exec(gctx: &mut GlobalContext, args: &ArgMatches) -> CliResult {
let lockfile_path = args.lockfile_path(gctx)?;
ws.set_requested_lockfile_path(lockfile_path.clone());

let mut opts = args.compile_options(gctx, mode, Some(&ws), ProfileChecking::LegacyTestOnly)?;
let mut opts = args.compile_options(
gctx,
CompileMode::Check { test },
Some(&ws),
ProfileChecking::LegacyTestOnly,
)?;

if !opts.filter.is_specific() {
// cargo fix with no target selection implies `--all-targets`.
Expand Down
16 changes: 9 additions & 7 deletions src/cargo/ops/fix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,27 @@
//! diagnostics with suggested fixes that can be applied to the files on the
//! filesystem, and validate that those changes didn't break anything.
//!
//! Cargo begins by launching a `LockServer` thread in the background to
//! Cargo begins by launching a [`LockServer`] thread in the background to
//! listen for network connections to coordinate locking when multiple targets
//! are built simultaneously. It ensures each package has only one fix running
//! at once.
//!
//! The `RustfixDiagnosticServer` is launched in a background thread (in
//! The [`RustfixDiagnosticServer`] is launched in a background thread (in
//! `JobQueue`) to listen for network connections to coordinate displaying
//! messages to the user on the console (so that multiple processes don't try
//! to print at the same time).
//!
//! Cargo begins a normal `cargo check` operation with itself set as a proxy
//! for rustc by setting `primary_unit_rustc` in the build config. When
//! for rustc by setting [BuildConfig::primary_unit_rustc] in the build config. When
//! cargo launches rustc to check a crate, it is actually launching itself.
//! The `FIX_ENV_INTERNAL` environment variable is set so that cargo knows it is in
//! fix-proxy-mode.
//! The `FIX_ENV_INTERNAL` environment variable is set to the value of the [`LockServer`]'s
//! address so that cargo knows it is in fix-proxy-mode.
//!
//! Each proxied cargo-as-rustc detects it is in fix-proxy-mode (via `FIX_ENV_INTERNAL`
//! environment variable in `main`) and does the following:
//!
//! - Acquire a lock from the `LockServer` from the master cargo process.
//! - Launches the real rustc (`rustfix_and_fix`), looking at the JSON output
//! - Acquire a lock from the [`LockServer`] from the master cargo process.
//! - Launches the real rustc ([`rustfix_and_fix`]), looking at the JSON output
//! for suggested fixes.
//! - Uses the `rustfix` crate to apply the suggestions to the files on the
//! file system.
Expand All @@ -35,6 +35,8 @@
//! applied cleanly, rustc is run again to verify the suggestions didn't
//! break anything. The change will be backed out if it fails (unless
//! `--broken-code` is used).
//!
//! [BuildConfig]: crate::core::compiler::BuildConfig
use std::collections::{BTreeSet, HashMap, HashSet};
use std::ffi::OsString;
Expand Down

0 comments on commit aec9450

Please sign in to comment.