2018-08-30 12:18:55 +00:00
|
|
|
//@ run-pass
|
2018-09-25 21:51:35 +00:00
|
|
|
#![allow(dead_code)]
|
2014-02-20 02:56:33 +00:00
|
|
|
use std::fmt;
|
|
|
|
|
2015-01-20 23:45:07 +00:00
|
|
|
#[derive(Debug)]
|
2013-06-18 00:23:18 +00:00
|
|
|
enum A {}
|
2015-01-20 23:45:07 +00:00
|
|
|
#[derive(Debug)]
|
2013-06-18 00:23:18 +00:00
|
|
|
enum B { B1, B2, B3 }
|
2015-01-20 23:45:07 +00:00
|
|
|
#[derive(Debug)]
|
2015-03-26 00:06:52 +00:00
|
|
|
enum C { C1(isize), C2(B), C3(String) }
|
2015-01-20 23:45:07 +00:00
|
|
|
#[derive(Debug)]
|
2015-03-26 00:06:52 +00:00
|
|
|
enum D { D1{ a: isize } }
|
2015-01-20 23:45:07 +00:00
|
|
|
#[derive(Debug)]
|
2013-06-18 00:23:18 +00:00
|
|
|
struct E;
|
2015-01-20 23:45:07 +00:00
|
|
|
#[derive(Debug)]
|
2015-03-26 00:06:52 +00:00
|
|
|
struct F(isize);
|
2015-01-20 23:45:07 +00:00
|
|
|
#[derive(Debug)]
|
2015-03-26 00:06:52 +00:00
|
|
|
struct G(isize, isize);
|
2015-01-20 23:45:07 +00:00
|
|
|
#[derive(Debug)]
|
2015-03-26 00:06:52 +00:00
|
|
|
struct H { a: isize }
|
2015-01-20 23:45:07 +00:00
|
|
|
#[derive(Debug)]
|
2015-03-26 00:06:52 +00:00
|
|
|
struct I { a: isize, b: isize }
|
2015-01-20 23:45:07 +00:00
|
|
|
#[derive(Debug)]
|
2013-06-18 00:23:18 +00:00
|
|
|
struct J(Custom);
|
2013-05-25 02:35:29 +00:00
|
|
|
|
2013-06-18 00:23:18 +00:00
|
|
|
struct Custom;
|
2015-01-20 23:45:07 +00:00
|
|
|
impl fmt::Debug for Custom {
|
2014-02-20 02:56:33 +00:00
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
2014-05-10 21:05:06 +00:00
|
|
|
write!(f, "yay")
|
2014-02-20 02:56:33 +00:00
|
|
|
}
|
2013-05-06 15:32:34 +00:00
|
|
|
}
|
|
|
|
|
2015-01-20 23:45:07 +00:00
|
|
|
trait ToDebug {
|
2014-12-20 08:09:35 +00:00
|
|
|
fn to_show(&self) -> String;
|
|
|
|
}
|
|
|
|
|
2015-01-20 23:45:07 +00:00
|
|
|
impl<T: fmt::Debug> ToDebug for T {
|
2014-12-20 08:09:35 +00:00
|
|
|
fn to_show(&self) -> String {
|
|
|
|
format!("{:?}", self)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-25 07:43:37 +00:00
|
|
|
pub fn main() {
|
2014-12-20 08:09:35 +00:00
|
|
|
assert_eq!(B::B1.to_show(), "B1".to_string());
|
|
|
|
assert_eq!(B::B2.to_show(), "B2".to_string());
|
2015-01-20 23:45:07 +00:00
|
|
|
assert_eq!(C::C1(3).to_show(), "C1(3)".to_string());
|
2014-12-20 08:09:35 +00:00
|
|
|
assert_eq!(C::C2(B::B2).to_show(), "C2(B2)".to_string());
|
2015-01-20 23:45:07 +00:00
|
|
|
assert_eq!(D::D1{ a: 2 }.to_show(), "D1 { a: 2 }".to_string());
|
2014-12-20 08:09:35 +00:00
|
|
|
assert_eq!(E.to_show(), "E".to_string());
|
2015-01-20 23:45:07 +00:00
|
|
|
assert_eq!(F(3).to_show(), "F(3)".to_string());
|
|
|
|
assert_eq!(G(3, 4).to_show(), "G(3, 4)".to_string());
|
|
|
|
assert_eq!(I{ a: 2, b: 4 }.to_show(), "I { a: 2, b: 4 }".to_string());
|
2014-12-20 08:09:35 +00:00
|
|
|
assert_eq!(J(Custom).to_show(), "J(yay)".to_string());
|
2013-05-25 02:35:29 +00:00
|
|
|
}
|