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