1
1
use std:: env;
2
2
use std:: ffi:: OsString ;
3
+ use std:: fmt:: Write as _;
3
4
use std:: fs:: { self , File } ;
4
- use std:: iter:: TakeWhile ;
5
5
use std:: io:: { self , BufRead , BufReader , BufWriter , Read , Write } ;
6
+ use std:: iter:: TakeWhile ;
6
7
use std:: ops:: Not ;
7
8
use std:: path:: { Path , PathBuf } ;
8
9
use std:: process:: Command ;
9
- use std:: fmt:: { Write as _} ;
10
10
11
11
use serde:: { Deserialize , Serialize } ;
12
12
@@ -95,7 +95,8 @@ fn show_version() {
95
95
// Only use `option_env` on vergen variables to ensure the build succeeds
96
96
// when vergen failed to find the git info.
97
97
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 ( ) ;
99
100
}
100
101
println ! ( "{}" , version) ;
101
102
}
@@ -168,8 +169,7 @@ fn forward_patched_extern_arg(args: &mut impl Iterator<Item = String>, cmd: &mut
168
169
}
169
170
170
171
fn 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" ) ;
173
173
cmd. arg ( "--sysroot" ) ;
174
174
cmd. arg ( sysroot) ;
175
175
}
@@ -471,7 +471,9 @@ fn phase_cargo_miri(mut args: env::Args) {
471
471
Some ( "run" ) => MiriCommand :: Run ,
472
472
Some ( "setup" ) => MiriCommand :: Setup ,
473
473
// 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
+ ) ) ,
475
477
} ;
476
478
let verbose = has_arg_flag ( "-v" ) ;
477
479
@@ -515,13 +517,14 @@ fn phase_cargo_miri(mut args: env::Args) {
515
517
// i.e., the first argument is `rustc` -- which is what we use in `main` to distinguish
516
518
// the two codepaths. (That extra argument is why we prefer this over setting `RUSTC`.)
517
519
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
+ ) ;
519
523
}
520
524
cmd. env ( "RUSTC_WRAPPER" , & cargo_miri_path) ;
521
525
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( '-' , "_" ) ) ;
525
528
let host_runner_env_name = runner_env_name ( & host) ;
526
529
let target_runner_env_name = runner_env_name ( target) ;
527
530
// 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) {
628
631
let runnable_crate = !print && is_runnable_crate ( ) ;
629
632
630
633
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
+ ) ;
632
638
let inside_rustdoc = phase == RustcPhase :: Rustdoc ;
633
639
// This is the binary or test crate that we want to interpret under Miri.
634
640
// 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) {
657
663
cmd. env ( "MIRI_BE_RUSTC" , "target" ) ;
658
664
659
665
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
+ ) ;
661
670
eprintln ! ( "[cargo-miri rustc] {:?}" , cmd) ;
662
671
}
663
672
@@ -715,7 +724,9 @@ fn phase_rustc(mut args: env::Args, phase: RustcPhase) {
715
724
}
716
725
717
726
// 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
+ {
719
730
cmd. arg ( "-C" ) . arg ( "panic=abort" ) ;
720
731
}
721
732
} else {
@@ -765,12 +776,18 @@ fn phase_runner(binary: &Path, binary_args: env::Args, phase: RunnerPhase) {
765
776
. unwrap_or_else ( |_| show_error ( format ! ( "file {:?} not found or `cargo-miri` invoked incorrectly; please only invoke this binary through `cargo miri`" , binary) ) ) ;
766
777
let file = BufReader :: new ( file) ;
767
778
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
+ } ) ;
770
785
let info = match info {
771
786
CrateRunInfo :: RunWith ( info) => info,
772
787
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
+ ) ;
774
791
return ;
775
792
}
776
793
} ;
@@ -783,7 +800,10 @@ fn phase_runner(binary: &Path, binary_args: env::Args, phase: RunnerPhase) {
783
800
if verbose {
784
801
if let Some ( old_val) = env:: var_os ( & name) {
785
802
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
+ ) ;
787
807
}
788
808
}
789
809
}
@@ -822,11 +842,7 @@ fn phase_runner(binary: &Path, binary_args: env::Args, phase: RunnerPhase) {
822
842
// Respect `MIRIFLAGS`.
823
843
if let Ok ( a) = env:: var ( "MIRIFLAGS" ) {
824
844
// 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) ;
830
846
cmd. args ( args) ;
831
847
}
832
848
@@ -845,12 +861,8 @@ fn phase_runner(binary: &Path, binary_args: env::Args, phase: RunnerPhase) {
845
861
}
846
862
847
863
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) ,
854
866
}
855
867
}
856
868
@@ -946,7 +958,10 @@ fn main() {
946
958
if binary. exists ( ) {
947
959
phase_runner ( binary, args, RunnerPhase :: Rustdoc ) ;
948
960
} 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
+ ) ) ;
950
965
}
951
966
} else {
952
967
phase_rustc ( args, RustcPhase :: Rustdoc ) ;
@@ -977,9 +992,14 @@ fn main() {
977
992
} else if arg. starts_with ( "--" ) {
978
993
phase_rustdoc ( arg, args) ;
979
994
} 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
+ ) ) ;
981
999
}
982
1000
}
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
+ ) ) ,
984
1004
}
985
1005
}
0 commit comments