@@ -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 ) ]
@@ -393,7 +386,7 @@ fn phase_cargo_miri(mut args: env::Args) {
393
386
Some ( "run" ) => MiriCommand :: Run ,
394
387
Some ( "setup" ) => MiriCommand :: Setup ,
395
388
// Invalid command.
396
- _ => show_error ( format ! ( "`cargo miri` must be immediately followed by `test `, `run `, or `setup`." ) ) ,
389
+ _ => show_error ( format ! ( "`cargo miri` supports the following subcommands: `run `, `test `, and `setup`." ) ) ,
397
390
} ;
398
391
let verbose = has_arg_flag ( "-v" ) ;
399
392
@@ -424,8 +417,44 @@ fn phase_cargo_miri(mut args: env::Args) {
424
417
host
425
418
} ;
426
419
427
- // Forward all further arguments.
428
- cmd. args ( args) ;
420
+ // Forward all further arguments. We do some processing here because we want to
421
+ // detect people still using the old way of passing flags to Miri
422
+ // (`cargo miri -- -Zmiri-foo`).
423
+ while let Some ( arg) = args. next ( ) {
424
+ cmd. arg ( & arg) ;
425
+ if arg == "--" {
426
+ // Check if the next argument starts with `-Zmiri`. If yes, we assume
427
+ // this is an old-style invocation.
428
+ if let Some ( next_arg) = args. next ( ) {
429
+ if next_arg. starts_with ( "-Zmiri" ) {
430
+ eprintln ! (
431
+ "WARNING: it seems like you are setting Miri's flags in `cargo miri` the old way,\n \
432
+ i.e., by passing them after the first `--`. This style is deprecated; please set\n \
433
+ the MIRIFLAGS environment variable instead. `cargo miri run/test` now interprets\n \
434
+ arguments the exact same way as `cargo run/test`."
435
+ ) ;
436
+ // Old-style invocation. Turn these into MIRIFLAGS.
437
+ let mut miriflags = env:: var ( "MIRIFLAGS" ) . unwrap_or_default ( ) ;
438
+ miriflags. push ( ' ' ) ;
439
+ miriflags. push_str ( & next_arg) ;
440
+ while let Some ( further_arg) = args. next ( ) {
441
+ if further_arg == "--" {
442
+ // End of the Miri flags!
443
+ break ;
444
+ }
445
+ miriflags. push ( ' ' ) ;
446
+ miriflags. push_str ( & further_arg) ;
447
+ }
448
+ env:: set_var ( "MIRIFLAGS" , miriflags) ;
449
+ // Pass the remaining flags to cargo.
450
+ cmd. args ( args) ;
451
+ break ;
452
+ }
453
+ // Not a Miri argument after all, make sure we pass it to cargo.
454
+ cmd. arg ( next_arg) ;
455
+ }
456
+ }
457
+ }
429
458
430
459
// Set `RUSTC_WRAPPER` to ourselves. Cargo will prepend that binary to its usual invocation,
431
460
// i.e., the first argument is `rustc` -- which is what we use in `main` to distinguish
0 commit comments