pub fn fix_maybe_exec_rustc(config: &Config) -> CargoResult<bool> {
    let lock_addr = match env::var(FIX_ENV) {
        Ok(s) => s,
        Err(_) => return Ok(false),
    };

    let args = FixArgs::get()?;
    trace!("cargo-fix as rustc got file {:?}", args.file);

    let workspace_rustc = std::env::var("RUSTC_WORKSPACE_WRAPPER")
        .map(PathBuf::from)
        .ok();
    let mut rustc = ProcessBuilder::new(&args.rustc).wrapped(workspace_rustc.as_ref());
    rustc.env_remove(FIX_ENV);

    trace!("start rustfixing {:?}", args.file);
    let fixes = rustfix_crate(&lock_addr, &rustc, &args.file, &args, config)?;

    // Ok now we have our final goal of testing out the changes that we applied.
    // If these changes went awry and actually started to cause the crate to
    // *stop* compiling then we want to back them out and continue to print
    // warnings to the user.
    //
    // If we didn't actually make any changes then we can immediately execute the
    // new rustc, and otherwise we capture the output to hide it in the scenario
    // that we have to back it all out.
    if !fixes.files.is_empty() {
        let mut cmd = rustc.build_command();
        args.apply(&mut cmd);
        cmd.arg("--error-format=json");
        debug!("calling rustc for final verification: {:?}", cmd);
        let output = cmd.output().context("failed to spawn rustc")?;

        if output.status.success() {
            for (path, file) in fixes.files.iter() {
                Message::Fixed {
                    file: path.clone(),
                    fixes: file.fixes_applied,
                }
                .post()?;
            }
        }

        // If we succeeded then we'll want to commit to the changes we made, if
        // any. If stderr is empty then there's no need for the final exec at
        // the end, we just bail out here.
        if output.status.success() && output.stderr.is_empty() {
            return Ok(true);
        }

        // Otherwise, if our rustc just failed, then that means that we broke the
        // user's code with our changes. Back out everything and fall through
        // below to recompile again.
        if !output.status.success() {
            if env::var_os(BROKEN_CODE_ENV).is_none() {
                for (path, file) in fixes.files.iter() {
                    debug!("reverting {:?} due to errors", path);
                    paths::write(path, &file.original_code)?;
                }
            }
            log_failed_fix(&output.stderr, output.status)?;
        }
    }

    // This final fall-through handles multiple cases;
    // - If the fix failed, show the original warnings and suggestions.
    // - If `--broken-code`, show the error messages.
    // - If the fix succeeded, show any remaining warnings.
    let mut cmd = rustc.build_command();
    args.apply(&mut cmd);
    for arg in args.format_args {
        // Add any json/error format arguments that Cargo wants. This allows
        // things like colored output to work correctly.
        cmd.arg(arg);
    }
    debug!("calling rustc to display remaining diagnostics: {:?}", cmd);
    exit_with(cmd.status().context("failed to spawn rustc")?);
}
/// Entry point for `cargo` running as a proxy for `rustc`.
///
/// This is called every time `cargo` is run to check if it is in proxy mode.
///
/// Returns `false` if `fix` is not being run (not in proxy mode). Returns
/// `true` if in `fix` proxy mode, and the fix was complete without any
/// warnings or errors. If there are warnings or errors, this does not return,
/// and the process exits with the corresponding `rustc` exit code.
Entry point for `cargo` running as a proxy for `rustc`.
This is called every time `cargo` is run to check if it is in proxy mode.

Returns `false` if `fix` is not being run (not in proxy mode). Returns
`true` if in `fix` proxy mode, and the fix was complete without any
warnings or errors. If there are warnings or errors, this does not return,
and the process exits with the corresponding `rustc` exit code.
Entry point for ` cargo ` running as a proxy for ` rustc ` . This is called every time ` cargo ` is run to check if it is in proxy mode . Returns ` false ` if ` fix ` is not being run ( not in proxy mode ) . Returns ` true ` if in ` fix ` proxy mode and the fix was complete without any warnings or errors . If there are warnings or errors this does not return and the process exits with the corresponding ` rustc ` exit code .
pub fn fix_maybe_exec_rustc(config: &Config) -> CargoResult<bool> {
    let lock_addr = match env::var(FIX_ENV) {
        Ok(s) => s,
        Err(_) => return Ok(false),
    };
    let args = FixArgs::get()?;
    trace!("cargo-fix as rustc got file {:?}", args.file);
    let workspace_rustc = std::env::var("RUSTC_WORKSPACE_WRAPPER")
        .map(PathBuf::from)
        .ok();
    let mut rustc = ProcessBuilder::new(&args.rustc).wrapped(workspace_rustc.as_ref());
    rustc.env_remove(FIX_ENV);
    trace!("start rustfixing {:?}", args.file);
    let fixes = rustfix_crate(&lock_addr, &rustc, &args.file, &args, config)?;
    // Ok now we have our final goal of testing out the changes that we applied.
    // If these changes went awry and actually started to cause the crate to
    // *stop* compiling then we want to back them out and continue to print
    // warnings to the user.
    //
    // If we didn't actually make any changes then we can immediately execute the
    // new rustc, and otherwise we capture the output to hide it in the scenario
    // that we have to back it all out.
    if !fixes.files.is_empty() {
        let mut cmd = rustc.build_command();
        args.apply(&mut cmd);
        cmd.arg("--error-format=json");
        debug!("calling rustc for final verification: {:?}", cmd);
        let output = cmd.output().context("failed to spawn rustc")?;
        if output.status.success() {
            for (path, file) in fixes.files.iter() {
                Message::Fixed {
                    file: path.clone(),
                    fixes: file.fixes_applied,
                }
                .post()?;
            }
        }
        // If we succeeded then we'll want to commit to the changes we made, if
        // any. If stderr is empty then there's no need for the final exec at
        // the end, we just bail out here.
        if output.status.success() && output.stderr.is_empty() {
            return Ok(true);
        }
        // Otherwise, if our rustc just failed, then that means that we broke the
        // user's code with our changes. Back out everything and fall through
        // below to recompile again.
        if !output.status.success() {
            if env::var_os(BROKEN_CODE_ENV).is_none() {
                for (path, file) in fixes.files.iter() {
                    debug!("reverting {:?} due to errors", path);
                    paths::write(path, &file.original_code)?;
                }
            }
            log_failed_fix(&output.stderr, output.status)?;
        }
    }
    // This final fall-through handles multiple cases;
    // - If the fix failed, show the original warnings and suggestions.
    // - If `--broken-code`, show the error messages.
    // - If the fix succeeded, show any remaining warnings.
    let mut cmd = rustc.build_command();
    args.apply(&mut cmd);
    for arg in args.format_args {
        // Add any json/error format arguments that Cargo wants. This allows
        // things like colored output to work correctly.
        cmd.arg(arg);
    }
    debug!("calling rustc to display remaining diagnostics: {:?}", cmd);
    exit_with(cmd.status().context("failed to spawn rustc")?);
}
pub fn fix_maybe_exec_rustc ( config : & Config ) -> CargoResult < bool > { let lock_addr = match env :: var ( FIX_ENV ) { Ok ( s ) => s , Err ( _ ) => return Ok ( false ) , } ; let args = FixArgs :: get ( ) ? ; trace ! ( " " args file ) ; let workspace_rustc = std :: env :: var ( " " ) . map ( PathBuf :: from ) . ok ( ) ; let mut rustc = ProcessBuilder :: new ( & args . rustc ) . wrapped ( workspace_rustc . as_ref ( ) ) ; rustc . env_remove ( FIX_ENV ) ; trace ! ( " " args file ) ; let fixes = rustfix_crate ( & lock_addr , & rustc , & args . file , & args , config ) ? ; // Ok now we have our final goal of testing out the changes that we applied. // If these changes went awry and actually started to cause the crate to // *stop* compiling then we want to back them out and continue to print // warnings to the user. // // If we didn't actually make any changes then we can immediately execute the // new rustc, and otherwise we capture the output to hide it in the scenario // that we have to back it all out. if ! fixes . files . is_empty ( ) { let mut cmd = rustc . build_command ( ) ; args . apply ( & mut cmd ) ; cmd . arg ( " " ) ; debug ! ( " " cmd ) ; let output = cmd . output ( ) . context ( " " ) ? ; if output . status . success ( ) { for ( path , file ) in fixes . files . iter ( ) { Message :: Fixed { file : path . clone ( ) , fixes : file . fixes_applied , } . post ( ) ? ; } } // If we succeeded then we'll want to commit to the changes we made, if // any. If stderr is empty then there's no need for the final exec at // the end, we just bail out here. if output . status . success ( ) && output . stderr . is_empty ( ) { return Ok ( true ) ; } // Otherwise, if our rustc just failed, then that means that we broke the // user's code with our changes. Back out everything and fall through // below to recompile again. if ! output . status . success ( ) { if env :: var_os ( BROKEN_CODE_ENV ) . is_none ( ) { for ( path , file ) in fixes . files . iter ( ) { debug ! ( " " path ) ; paths :: write ( path , & file . original_code ) ? ; } } log_failed_fix ( & output . stderr , output . status ) ? ; } } // This final fall-through handles multiple cases; // - If the fix failed, show the original warnings and suggestions. // - If `--broken-code`, show the error messages. // - If the fix succeeded, show any remaining warnings. let mut cmd = rustc . build_command ( ) ; args . apply ( & mut cmd ) ; for arg in args . format_args { // Add any json/error format arguments that Cargo wants. This allows // things like colored output to work correctly. cmd . arg ( arg ) ; } debug ! ( " " cmd ) ; exit_with ( cmd . status ( ) . context ( " " ) ? ) ; }
Entry point for `cargo` running as a proxy for `rustc`.
Entry point for ` cargo ` running as a proxy for ` rustc ` .
config
&Config
config
&Config