Easier display impl in tests

This commit is contained in:
David Tolnay 2019-10-09 07:23:58 -07:00
parent fe4de24dcc
commit 3e7ddeb72d
No known key found for this signature in database
GPG key ID: F9BA143B95FF6D82

View file

@ -1,6 +1,16 @@
use std::fmt::{self, Display}; use std::fmt::{self, Display};
use thiserror::Error; use thiserror::Error;
macro_rules! unimplemented_display {
($ty:ty) => {
impl Display for $ty {
fn fmt(&self, _formatter: &mut fmt::Formatter) -> fmt::Result {
unimplemented!()
}
}
};
}
#[derive(Error, Debug)] #[derive(Error, Debug)]
struct BracedError { struct BracedError {
msg: String, msg: String,
@ -13,20 +23,6 @@ struct TupleError(String, usize);
#[derive(Error, Debug)] #[derive(Error, Debug)]
struct UnitError; struct UnitError;
impl Display for BracedError { unimplemented_display!(BracedError);
fn fmt(&self, _formatter: &mut fmt::Formatter) -> fmt::Result { unimplemented_display!(TupleError);
unimplemented!() unimplemented_display!(UnitError);
}
}
impl Display for TupleError {
fn fmt(&self, _formatter: &mut fmt::Formatter) -> fmt::Result {
unimplemented!()
}
}
impl Display for UnitError {
fn fmt(&self, _formatter: &mut fmt::Formatter) -> fmt::Result {
unimplemented!()
}
}