@@ -12,28 +12,21 @@ use rustc_version::VersionMeta;
12
12
13
13
const XARGO_MIN_VERSION : ( u32 , u32 , u32 ) = ( 0 , 3 , 22 ) ;
14
14
15
- const CARGO_MIRI_HELP : & str = r#"Interprets bin crates and tests in Miri
15
+ const CARGO_MIRI_HELP : & str = r#"Runs binary crates and tests in Miri
16
16
17
17
Usage:
18
- cargo miri [subcommand] [<cargo options>...] [--] [<miri options>...] [--] [< program/test suite options>...]
18
+ cargo miri [subcommand] [<cargo options>...] [--] [<program/test suite options>...]
19
19
20
20
Subcommands:
21
- run Run binaries (default)
21
+ run Run binaries
22
22
test Run tests
23
23
setup Only perform automatic setup, but without asking questions (for getting a proper libstd)
24
24
25
- Common options:
26
- -h, --help Print this message
27
- --features Features to compile for the package
28
- -V, --version Print version info and exit
29
-
30
- Other [options] are the same as `cargo check`. Everything after the first "--" is
31
- passed verbatim to Miri, which will pass everything after the second "--" verbatim
32
- to the interpreted program.
25
+ The cargo options are exactly the same as for `cargo run` and `cargo test`, respectively.
33
26
34
27
Examples:
35
- cargo miri run -- -Zmiri-disable-stacked-borrows
36
- cargo miri test -- -- test-suite-filter
28
+ cargo miri run
29
+ cargo miri test -- test-suite-filter
37
30
"# ;
38
31
39
32
#[ derive( Copy , Clone , Debug , PartialEq , Eq ) ]
@@ -390,7 +383,7 @@ fn phase_cargo_miri(mut args: env::Args) {
390
383
Some ( "run" ) => MiriCommand :: Run ,
391
384
Some ( "setup" ) => MiriCommand :: Setup ,
392
385
// Invalid command.
393
- _ => show_error ( format ! ( "`cargo miri` must be immediately followed by `test `, `run `, or `setup`." ) ) ,
386
+ _ => show_error ( format ! ( "`cargo miri` supports the following subcommands: `run `, `test `, and `setup`." ) ) ,
394
387
} ;
395
388
let verbose = has_arg_flag ( "-v" ) ;
396
389
@@ -421,8 +414,44 @@ fn phase_cargo_miri(mut args: env::Args) {
421
414
host
422
415
} ;
423
416
424
- // Forward all further arguments.
425
- cmd. args ( args) ;
417
+ // Forward all further arguments. We do some processing here because we want to
418
+ // detect people still using the old way of passing flags to Miri
419
+ // (`cargo miri -- -Zmiri-foo`).
420
+ while let Some ( arg) = args. next ( ) {
421
+ cmd. arg ( & arg) ;
422
+ if arg == "--" {
423
+ // Check if the next argument starts with `-Zmiri`. If yes, we assume
424
+ // this is an old-style invocation.
425
+ if let Some ( next_arg) = args. next ( ) {
426
+ if next_arg. starts_with ( "-Zmiri" ) {
427
+ eprintln ! (
428
+ "WARNING: it seems like you are setting Miri's flags in `cargo miri` the old way,\n \
429
+ i.e., by passing them after the first `--`. This style is deprecated; please set\n \
430
+ the MIRIFLAGS environment variable instead. `cargo miri run/test` now interprets\n \
431
+ arguments the exact same way as `cargo run/test`."
432
+ ) ;
433
+ // Old-style invocation. Turn these into MIRIFLAGS.
434
+ let mut miriflags = env:: var ( "MIRIFLAGS" ) . unwrap_or_default ( ) ;
435
+ miriflags. push ( ' ' ) ;
436
+ miriflags. push_str ( & next_arg) ;
437
+ while let Some ( further_arg) = args. next ( ) {
438
+ if further_arg == "--" {
439
+ // End of the Miri flags!
440
+ break ;
441
+ }
442
+ miriflags. push ( ' ' ) ;
443
+ miriflags. push_str ( & further_arg) ;
444
+ }
445
+ env:: set_var ( "MIRIFLAGS" , miriflags) ;
446
+ // Pass the remaining flags to cargo.
447
+ cmd. args ( args) ;
448
+ break ;
449
+ }
450
+ // Not a Miri argument after all, make sure we pass it to cargo.
451
+ cmd. arg ( next_arg) ;
452
+ }
453
+ }
454
+ }
426
455
427
456
// Set `RUSTC_WRAPPER` to ourselves. Cargo will prepend that binary to its usual invocation,
428
457
// i.e., the first argument is `rustc` -- which is what we use in `main` to distinguish
0 commit comments