Skip to content

Commit

Permalink
Use debug formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
jefftt committed Dec 1, 2022
1 parent 699355f commit 28d209a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
19 changes: 13 additions & 6 deletions mockall/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1146,7 +1146,7 @@
use downcast::*;
use std::{
any,
fmt::{Debug, Display},
fmt::Debug,
marker::PhantomData,
ops::{Range, RangeFrom, RangeFull, RangeInclusive, RangeTo,
RangeToInclusive},
Expand Down Expand Up @@ -1469,9 +1469,9 @@ pub struct ArgPrinter<'a, T>(pub &'a T);

#[doc(hidden)]
pub struct DebugPrint<'a, T: Debug>(pub &'a T);
impl<'a, T> Display for DebugPrint<'a, T> where T: Debug {
impl<'a, T> Debug for DebugPrint<'a, T> where T: Debug {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{:?}", self.0)
Debug::fmt(self.0, f)
}
}
#[doc(hidden)]
Expand All @@ -1483,10 +1483,17 @@ impl<'a, T: Debug> ViaDebug<T> for &ArgPrinter<'a, T> {
}

#[doc(hidden)]
pub trait ViaNothing { fn debug_string(&self) -> &'static str; }
pub struct NothingPrint;
impl Debug for NothingPrint {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "?")
}
}
#[doc(hidden)]
pub trait ViaNothing { fn debug_string(&self) -> NothingPrint; }
impl<'a, T> ViaNothing for ArgPrinter<'a, T> {
fn debug_string(&self) -> &'static str {
"?"
fn debug_string(&self) -> NothingPrint {
NothingPrint
}
}

Expand Down
2 changes: 1 addition & 1 deletion mockall_derive/src/mock_function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,7 @@ impl MockFunction {
} else {
format!("{}::{}", self.mod_ident, self.sig.ident)
};
let fields = vec!["{}"; argnames.len()].join(", ");
let fields = vec!["{:?}"; argnames.len()].join(", ");
let fstr = format!("{}({})", name, fields);
quote!(std::format!(#fstr, #((&&&::mockall::ArgPrinter(&#argnames)).debug_string()),*))
}
Expand Down

0 comments on commit 28d209a

Please sign in to comment.