From b99d7bc77f1b7986954ec8bd2f1c9f80664e8fd4 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Mon, 8 Aug 2022 11:35:54 -0400 Subject: [PATCH] avoid intermediate allocations in show_error macro --- cargo-miri/src/main.rs | 2 +- cargo-miri/src/util.rs | 4 ++-- src/bin/miri.rs | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/cargo-miri/src/main.rs b/cargo-miri/src/main.rs index 30b03c57dba..09e2cd3c286 100644 --- a/cargo-miri/src/main.rs +++ b/cargo-miri/src/main.rs @@ -11,7 +11,7 @@ use std::{env, iter}; -use crate::{phases::*, util::*}; +use crate::phases::*; fn main() { // Rustc does not support non-UTF-8 arguments so we make no attempt either. diff --git a/cargo-miri/src/util.rs b/cargo-miri/src/util.rs index 8095958d21d..8f29eebaac1 100644 --- a/cargo-miri/src/util.rs +++ b/cargo-miri/src/util.rs @@ -14,13 +14,13 @@ pub use crate::arg::*; -pub fn show_error(msg: &str) -> ! { +pub fn show_error(msg: &impl std::fmt::Display) -> ! { eprintln!("fatal error: {msg}"); std::process::exit(1) } macro_rules! show_error { - ($($tt:tt)*) => { show_error(&format!($($tt)*)) }; + ($($tt:tt)*) => { crate::util::show_error(&format_args!($($tt)*)) }; } /// The information to run a crate with the given environment. diff --git a/src/bin/miri.rs b/src/bin/miri.rs index 3325fc97d82..ca0787b2298 100644 --- a/src/bin/miri.rs +++ b/src/bin/miri.rs @@ -152,13 +152,13 @@ fn config(&mut self, config: &mut Config) { } } -fn show_error(msg: &str) -> ! { +fn show_error(msg: &impl std::fmt::Display) -> ! { eprintln!("fatal error: {msg}"); std::process::exit(1) } macro_rules! show_error { - ($($tt:tt)*) => { show_error(&format!($($tt)*)) }; + ($($tt:tt)*) => { show_error(&format_args!($($tt)*)) }; } fn init_early_loggers() {