11use std:: env;
22use std:: ffi:: OsString ;
3+ use std:: fmt:: Write as _;
34use std:: fs:: { self , File } ;
4- use std:: iter:: TakeWhile ;
55use std:: io:: { self , BufRead , BufReader , BufWriter , Read , Write } ;
6+ use std:: iter:: TakeWhile ;
67use std:: ops:: Not ;
78use std:: path:: { Path , PathBuf } ;
89use std:: process:: Command ;
9- use std:: fmt:: { Write as _} ;
1010
1111use serde:: { Deserialize , Serialize } ;
1212
@@ -95,7 +95,8 @@ fn show_version() {
9595 // Only use `option_env` on vergen variables to ensure the build succeeds
9696 // when vergen failed to find the git info.
9797 if let Some ( sha) = option_env ! ( "VERGEN_GIT_SHA_SHORT" ) {
98- write ! ( & mut version, " ({} {})" , sha, option_env!( "VERGEN_GIT_COMMIT_DATE" ) . unwrap( ) ) . unwrap ( ) ;
98+ write ! ( & mut version, " ({} {})" , sha, option_env!( "VERGEN_GIT_COMMIT_DATE" ) . unwrap( ) )
99+ . unwrap ( ) ;
99100 }
100101 println ! ( "{}" , version) ;
101102}
@@ -168,8 +169,7 @@ fn forward_patched_extern_arg(args: &mut impl Iterator<Item = String>, cmd: &mut
168169}
169170
170171fn forward_miri_sysroot ( cmd : & mut Command ) {
171- let sysroot =
172- env:: var_os ( "MIRI_SYSROOT" ) . expect ( "the wrapper should have set MIRI_SYSROOT" ) ;
172+ let sysroot = env:: var_os ( "MIRI_SYSROOT" ) . expect ( "the wrapper should have set MIRI_SYSROOT" ) ;
173173 cmd. arg ( "--sysroot" ) ;
174174 cmd. arg ( sysroot) ;
175175}
@@ -471,7 +471,9 @@ fn phase_cargo_miri(mut args: env::Args) {
471471 Some ( "run" ) => MiriCommand :: Run ,
472472 Some ( "setup" ) => MiriCommand :: Setup ,
473473 // Invalid command.
474- _ => show_error ( format ! ( "`cargo miri` supports the following subcommands: `run`, `test`, and `setup`." ) ) ,
474+ _ => show_error ( format ! (
475+ "`cargo miri` supports the following subcommands: `run`, `test`, and `setup`."
476+ ) ) ,
475477 } ;
476478 let verbose = has_arg_flag ( "-v" ) ;
477479
@@ -515,13 +517,14 @@ fn phase_cargo_miri(mut args: env::Args) {
515517 // i.e., the first argument is `rustc` -- which is what we use in `main` to distinguish
516518 // the two codepaths. (That extra argument is why we prefer this over setting `RUSTC`.)
517519 if env:: var_os ( "RUSTC_WRAPPER" ) . is_some ( ) {
518- println ! ( "WARNING: Ignoring `RUSTC_WRAPPER` environment variable, Miri does not support wrapping." ) ;
520+ println ! (
521+ "WARNING: Ignoring `RUSTC_WRAPPER` environment variable, Miri does not support wrapping."
522+ ) ;
519523 }
520524 cmd. env ( "RUSTC_WRAPPER" , & cargo_miri_path) ;
521525
522- let runner_env_name = |triple : & str | {
523- format ! ( "CARGO_TARGET_{}_RUNNER" , triple. to_uppercase( ) . replace( '-' , "_" ) )
524- } ;
526+ let runner_env_name =
527+ |triple : & str | format ! ( "CARGO_TARGET_{}_RUNNER" , triple. to_uppercase( ) . replace( '-' , "_" ) ) ;
525528 let host_runner_env_name = runner_env_name ( & host) ;
526529 let target_runner_env_name = runner_env_name ( target) ;
527530 // Set the target runner to us, so we can interpret the binaries.
@@ -628,7 +631,10 @@ fn phase_rustc(mut args: env::Args, phase: RustcPhase) {
628631 let runnable_crate = !print && is_runnable_crate ( ) ;
629632
630633 if runnable_crate && target_crate {
631- assert ! ( phase != RustcPhase :: Setup , "there should be no interpretation during sysroot build" ) ;
634+ assert ! (
635+ phase != RustcPhase :: Setup ,
636+ "there should be no interpretation during sysroot build"
637+ ) ;
632638 let inside_rustdoc = phase == RustcPhase :: Rustdoc ;
633639 // This is the binary or test crate that we want to interpret under Miri.
634640 // But we cannot run it here, as cargo invoked us as a compiler -- our stdin and stdout are not
@@ -657,7 +663,10 @@ fn phase_rustc(mut args: env::Args, phase: RustcPhase) {
657663 cmd. env ( "MIRI_BE_RUSTC" , "target" ) ;
658664
659665 if verbose {
660- eprintln ! ( "[cargo-miri rustc] captured input:\n {}" , std:: str :: from_utf8( & env. stdin) . unwrap( ) ) ;
666+ eprintln ! (
667+ "[cargo-miri rustc] captured input:\n {}" ,
668+ std:: str :: from_utf8( & env. stdin) . unwrap( )
669+ ) ;
661670 eprintln ! ( "[cargo-miri rustc] {:?}" , cmd) ;
662671 }
663672
@@ -715,7 +724,9 @@ fn phase_rustc(mut args: env::Args, phase: RustcPhase) {
715724 }
716725
717726 // During setup, patch the panic runtime for `libpanic_abort` (mirroring what bootstrap usually does).
718- if phase == RustcPhase :: Setup && get_arg_flag_value ( "--crate-name" ) . as_deref ( ) == Some ( "panic_abort" ) {
727+ if phase == RustcPhase :: Setup
728+ && get_arg_flag_value ( "--crate-name" ) . as_deref ( ) == Some ( "panic_abort" )
729+ {
719730 cmd. arg ( "-C" ) . arg ( "panic=abort" ) ;
720731 }
721732 } else {
@@ -765,12 +776,18 @@ fn phase_runner(binary: &Path, binary_args: env::Args, phase: RunnerPhase) {
765776 . unwrap_or_else ( |_| show_error ( format ! ( "file {:?} not found or `cargo-miri` invoked incorrectly; please only invoke this binary through `cargo miri`" , binary) ) ) ;
766777 let file = BufReader :: new ( file) ;
767778
768- let info = serde_json:: from_reader ( file)
769- . unwrap_or_else ( |_| show_error ( format ! ( "file {:?} contains outdated or invalid JSON; try `cargo clean`" , binary) ) ) ;
779+ let info = serde_json:: from_reader ( file) . unwrap_or_else ( |_| {
780+ show_error ( format ! (
781+ "file {:?} contains outdated or invalid JSON; try `cargo clean`" ,
782+ binary
783+ ) )
784+ } ) ;
770785 let info = match info {
771786 CrateRunInfo :: RunWith ( info) => info,
772787 CrateRunInfo :: SkipProcMacroTest => {
773- eprintln ! ( "Running unit tests of `proc-macro` crates is not currently supported by Miri." ) ;
788+ eprintln ! (
789+ "Running unit tests of `proc-macro` crates is not currently supported by Miri."
790+ ) ;
774791 return ;
775792 }
776793 } ;
@@ -783,7 +800,10 @@ fn phase_runner(binary: &Path, binary_args: env::Args, phase: RunnerPhase) {
783800 if verbose {
784801 if let Some ( old_val) = env:: var_os ( & name) {
785802 if old_val != val {
786- eprintln ! ( "[cargo-miri runner] Overwriting run-time env var {:?}={:?} with build-time value {:?}" , name, old_val, val) ;
803+ eprintln ! (
804+ "[cargo-miri runner] Overwriting run-time env var {:?}={:?} with build-time value {:?}" ,
805+ name, old_val, val
806+ ) ;
787807 }
788808 }
789809 }
@@ -822,11 +842,7 @@ fn phase_runner(binary: &Path, binary_args: env::Args, phase: RunnerPhase) {
822842 // Respect `MIRIFLAGS`.
823843 if let Ok ( a) = env:: var ( "MIRIFLAGS" ) {
824844 // This code is taken from `RUSTFLAGS` handling in cargo.
825- let args = a
826- . split ( ' ' )
827- . map ( str:: trim)
828- . filter ( |s| !s. is_empty ( ) )
829- . map ( str:: to_string) ;
845+ let args = a. split ( ' ' ) . map ( str:: trim) . filter ( |s| !s. is_empty ( ) ) . map ( str:: to_string) ;
830846 cmd. args ( args) ;
831847 }
832848
@@ -845,12 +861,8 @@ fn phase_runner(binary: &Path, binary_args: env::Args, phase: RunnerPhase) {
845861 }
846862
847863 match phase {
848- RunnerPhase :: Rustdoc => {
849- exec_with_pipe ( cmd, & info. stdin )
850- }
851- RunnerPhase :: Cargo => {
852- exec ( cmd)
853- }
864+ RunnerPhase :: Rustdoc => exec_with_pipe ( cmd, & info. stdin ) ,
865+ RunnerPhase :: Cargo => exec ( cmd) ,
854866 }
855867}
856868
@@ -946,7 +958,10 @@ fn main() {
946958 if binary. exists ( ) {
947959 phase_runner ( binary, args, RunnerPhase :: Rustdoc ) ;
948960 } else {
949- show_error ( format ! ( "`cargo-miri` called with non-existing path argument `{}` in rustdoc mode; please invoke this binary through `cargo miri`" , arg) ) ;
961+ show_error ( format ! (
962+ "`cargo-miri` called with non-existing path argument `{}` in rustdoc mode; please invoke this binary through `cargo miri`" ,
963+ arg
964+ ) ) ;
950965 }
951966 } else {
952967 phase_rustc ( args, RustcPhase :: Rustdoc ) ;
@@ -977,9 +992,14 @@ fn main() {
977992 } else if arg. starts_with ( "--" ) {
978993 phase_rustdoc ( arg, args) ;
979994 } else {
980- show_error ( format ! ( "`cargo-miri` called with unexpected first argument `{}`; please only invoke this binary through `cargo miri`" , arg) ) ;
995+ show_error ( format ! (
996+ "`cargo-miri` called with unexpected first argument `{}`; please only invoke this binary through `cargo miri`" ,
997+ arg
998+ ) ) ;
981999 }
9821000 }
983- _ => show_error ( format ! ( "`cargo-miri` called without first argument; please only invoke this binary through `cargo miri`" ) ) ,
1001+ _ => show_error ( format ! (
1002+ "`cargo-miri` called without first argument; please only invoke this binary through `cargo miri`"
1003+ ) ) ,
9841004 }
9851005}
0 commit comments