// run-pass struct Foo { a: A } impl Foo { fn bar_int(&self) -> isize { self.a } } impl Foo { fn bar_char(&self) -> char { self.a } } impl Foo { fn bar(&self) { let (i, c): (isize, char) = self.a; assert_eq!(Foo { a: i }.bar_int(), i); assert_eq!(Foo { a: c }.bar_char(), c); } } impl Foo { fn baz(&self) -> A { self.a.clone() } } fn default_foo(x: Foo) { let (i, c): (isize, char) = x.a; assert_eq!(i, 1); assert_eq!(c, 'a'); x.bar(); assert_eq!(x.baz(), (1, 'a')); } #[derive(PartialEq, Debug)] struct BazHelper(T); #[derive(PartialEq, Debug)] // Ensure that we can use previous type parameters in defaults. struct Baz, V = Option>(T, U, V); fn main() { default_foo(Foo { a: (1, 'a') }); let x: Baz = Baz(true, BazHelper(false), Some(BazHelper(true))); assert_eq!(x, Baz(true, BazHelper(false), Some(BazHelper(true)))); }