@@ -152,11 +152,15 @@ impl rustc_driver::Callbacks for MiriBeRustCompilerCalls {
152
152
}
153
153
}
154
154
155
- fn show_error ( msg : String ) -> ! {
156
- eprintln ! ( "fatal error: {}" , msg ) ;
155
+ fn show_error ( msg : & impl std :: fmt :: Display ) -> ! {
156
+ eprintln ! ( "fatal error: {msg}" ) ;
157
157
std:: process:: exit ( 1 )
158
158
}
159
159
160
+ macro_rules! show_error {
161
+ ( $( $tt: tt) * ) => { show_error( & format_args!( $( $tt) * ) ) } ;
162
+ }
163
+
160
164
fn init_early_loggers ( ) {
161
165
// Note that our `extern crate log` is *not* the same as rustc's; as a result, we have to
162
166
// initialize them both, and we always initialize `miri`'s first.
@@ -234,19 +238,19 @@ fn host_sysroot() -> Option<String> {
234
238
env:: var_os ( "RUSTUP_TOOLCHAIN" ) . or_else ( || env:: var_os ( "MULTIRUST_TOOLCHAIN" ) )
235
239
{
236
240
if toolchain_runtime != toolchain {
237
- show_error ( format ! (
241
+ show_error ! (
238
242
"This Miri got built with local toolchain `{toolchain}`, but now is being run under a different toolchain. \n \
239
243
Make sure to run Miri in the toolchain it got built with, e.g. via `cargo +{toolchain} miri`."
240
- ) ) ;
244
+ )
241
245
}
242
246
}
243
247
format ! ( "{}/toolchains/{}" , home, toolchain)
244
248
}
245
249
_ => option_env ! ( "RUST_SYSROOT" )
246
250
. unwrap_or_else ( || {
247
- show_error ( format ! (
251
+ show_error ! (
248
252
"To build Miri without rustup, set the `RUST_SYSROOT` env var at build time" ,
249
- ) )
253
+ )
250
254
} )
251
255
. to_owned ( ) ,
252
256
} )
@@ -272,9 +276,9 @@ fn run_compiler(
272
276
// Using the built-in default here would be plain wrong, so we *require*
273
277
// the env var to make sure things make sense.
274
278
Some ( env:: var ( "MIRI_SYSROOT" ) . unwrap_or_else ( |_| {
275
- show_error ( format ! (
279
+ show_error ! (
276
280
"Miri was invoked in 'target' mode without `MIRI_SYSROOT` or `--sysroot` being set"
277
- ) )
281
+ )
278
282
} ) )
279
283
} else {
280
284
host_default_sysroot
@@ -379,7 +383,9 @@ fn main() {
379
383
miri_config. check_abi = false ;
380
384
} else if arg == "-Zmiri-disable-isolation" {
381
385
if matches ! ( isolation_enabled, Some ( true ) ) {
382
- panic ! ( "-Zmiri-disable-isolation cannot be used along with -Zmiri-isolation-error" ) ;
386
+ show_error ! (
387
+ "-Zmiri-disable-isolation cannot be used along with -Zmiri-isolation-error"
388
+ ) ;
383
389
} else {
384
390
isolation_enabled = Some ( false ) ;
385
391
}
@@ -390,7 +396,9 @@ fn main() {
390
396
miri_config. track_outdated_loads = true ;
391
397
} else if let Some ( param) = arg. strip_prefix ( "-Zmiri-isolation-error=" ) {
392
398
if matches ! ( isolation_enabled, Some ( false ) ) {
393
- panic ! ( "-Zmiri-isolation-error cannot be used along with -Zmiri-disable-isolation" ) ;
399
+ show_error ! (
400
+ "-Zmiri-isolation-error cannot be used along with -Zmiri-disable-isolation"
401
+ ) ;
394
402
} else {
395
403
isolation_enabled = Some ( true ) ;
396
404
}
@@ -402,7 +410,7 @@ fn main() {
402
410
"warn-nobacktrace" =>
403
411
miri:: IsolatedOp :: Reject ( miri:: RejectOpWith :: WarningWithoutBacktrace ) ,
404
412
_ =>
405
- panic ! (
413
+ show_error ! (
406
414
"-Zmiri-isolation-error must be `abort`, `hide`, `warn`, or `warn-nobacktrace`"
407
415
) ,
408
416
} ;
@@ -426,11 +434,11 @@ fn main() {
426
434
) ;
427
435
} else if let Some ( param) = arg. strip_prefix ( "-Zmiri-seed=" ) {
428
436
if miri_config. seed . is_some ( ) {
429
- panic ! ( "Cannot specify -Zmiri-seed multiple times!" ) ;
437
+ show_error ! ( "Cannot specify -Zmiri-seed multiple times!" ) ;
430
438
}
431
439
let seed = u64:: from_str_radix ( param, 16 )
432
- . unwrap_or_else ( |_| panic ! (
433
- "-Zmiri-seed should only contain valid hex digits [0-9a-fA-F] and fit into a u64 (max 16 characters)"
440
+ . unwrap_or_else ( |_| show_error ! (
441
+ "-Zmiri-seed should only contain valid hex digits [0-9a-fA-F] and must fit into a u64 (max 16 characters)"
434
442
) ) ;
435
443
miri_config. seed = Some ( seed) ;
436
444
} else if let Some ( param) = arg. strip_prefix ( "-Zmiri-env-exclude=" ) {
@@ -441,7 +449,7 @@ fn main() {
441
449
let ids: Vec < u64 > = match parse_comma_list ( param) {
442
450
Ok ( ids) => ids,
443
451
Err ( err) =>
444
- panic ! (
452
+ show_error ! (
445
453
"-Zmiri-track-pointer-tag requires a comma separated list of valid `u64` arguments: {}" ,
446
454
err
447
455
) ,
@@ -450,14 +458,14 @@ fn main() {
450
458
if let Some ( id) = id {
451
459
miri_config. tracked_pointer_tags . insert ( id) ;
452
460
} else {
453
- panic ! ( "-Zmiri-track-pointer-tag requires nonzero arguments" ) ;
461
+ show_error ! ( "-Zmiri-track-pointer-tag requires nonzero arguments" ) ;
454
462
}
455
463
}
456
464
} else if let Some ( param) = arg. strip_prefix ( "-Zmiri-track-call-id=" ) {
457
465
let ids: Vec < u64 > = match parse_comma_list ( param) {
458
466
Ok ( ids) => ids,
459
467
Err ( err) =>
460
- panic ! (
468
+ show_error ! (
461
469
"-Zmiri-track-call-id requires a comma separated list of valid `u64` arguments: {}" ,
462
470
err
463
471
) ,
@@ -466,14 +474,14 @@ fn main() {
466
474
if let Some ( id) = id {
467
475
miri_config. tracked_call_ids . insert ( id) ;
468
476
} else {
469
- panic ! ( "-Zmiri-track-call-id requires a nonzero argument" ) ;
477
+ show_error ! ( "-Zmiri-track-call-id requires a nonzero argument" ) ;
470
478
}
471
479
}
472
480
} else if let Some ( param) = arg. strip_prefix ( "-Zmiri-track-alloc-id=" ) {
473
481
let ids: Vec < miri:: AllocId > = match parse_comma_list :: < NonZeroU64 > ( param) {
474
482
Ok ( ids) => ids. into_iter ( ) . map ( miri:: AllocId ) . collect ( ) ,
475
483
Err ( err) =>
476
- panic ! (
484
+ show_error ! (
477
485
"-Zmiri-track-alloc-id requires a comma separated list of valid non-zero `u64` arguments: {}" ,
478
486
err
479
487
) ,
@@ -483,11 +491,11 @@ fn main() {
483
491
let rate = match param. parse :: < f64 > ( ) {
484
492
Ok ( rate) if rate >= 0.0 && rate <= 1.0 => rate,
485
493
Ok ( _) =>
486
- panic ! (
494
+ show_error ! (
487
495
"-Zmiri-compare-exchange-weak-failure-rate must be between `0.0` and `1.0`"
488
496
) ,
489
497
Err ( err) =>
490
- panic ! (
498
+ show_error ! (
491
499
"-Zmiri-compare-exchange-weak-failure-rate requires a `f64` between `0.0` and `1.0`: {}" ,
492
500
err
493
501
) ,
@@ -496,9 +504,9 @@ fn main() {
496
504
} else if let Some ( param) = arg. strip_prefix ( "-Zmiri-preemption-rate=" ) {
497
505
let rate = match param. parse :: < f64 > ( ) {
498
506
Ok ( rate) if rate >= 0.0 && rate <= 1.0 => rate,
499
- Ok ( _) => panic ! ( "-Zmiri-preemption-rate must be between `0.0` and `1.0`" ) ,
507
+ Ok ( _) => show_error ! ( "-Zmiri-preemption-rate must be between `0.0` and `1.0`" ) ,
500
508
Err ( err) =>
501
- panic ! (
509
+ show_error ! (
502
510
"-Zmiri-preemption-rate requires a `f64` between `0.0` and `1.0`: {}" ,
503
511
err
504
512
) ,
@@ -510,7 +518,7 @@ fn main() {
510
518
} else if let Some ( param) = arg. strip_prefix ( "-Zmiri-report-progress=" ) {
511
519
let interval = match param. parse :: < u32 > ( ) {
512
520
Ok ( i) => i,
513
- Err ( err) => panic ! ( "-Zmiri-report-progress requires a `u32`: {}" , err) ,
521
+ Err ( err) => show_error ! ( "-Zmiri-report-progress requires a `u32`: {}" , err) ,
514
522
} ;
515
523
miri_config. report_progress = Some ( interval) ;
516
524
} else if let Some ( param) = arg. strip_prefix ( "-Zmiri-measureme=" ) {
@@ -520,7 +528,7 @@ fn main() {
520
528
"0" => BacktraceStyle :: Off ,
521
529
"1" => BacktraceStyle :: Short ,
522
530
"full" => BacktraceStyle :: Full ,
523
- _ => panic ! ( "-Zmiri-backtrace may only be 0, 1, or full" ) ,
531
+ _ => show_error ! ( "-Zmiri-backtrace may only be 0, 1, or full" ) ,
524
532
} ;
525
533
} else {
526
534
// Forward to rustc.
0 commit comments