1 // Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
11 struct Foo<A = (isize, char)> {
16 fn bar_int(&self) -> isize {
22 fn bar_char(&self) -> char {
29 let (i, c): (isize, char) = self.a;
30 assert_eq!(Foo { a: i }.bar_int(), i);
31 assert_eq!(Foo { a: c }.bar_char(), c);
35 impl<A: Clone> Foo<A> {
41 fn default_foo(x: Foo) {
42 let (i, c): (isize, char) = x.a;
47 assert_eq!(x.baz(), (1, 'a'));
50 #[derive(PartialEq, Debug)]
51 struct BazHelper<T>(T);
53 #[derive(PartialEq, Debug)]
54 // Ensure that we can use previous type parameters in defaults.
55 struct Baz<T, U = BazHelper<T>, V = Option<U>>(T, U, V);
58 default_foo(Foo { a: (1, 'a') });
60 let x: Baz<bool> = Baz(true, BazHelper(false), Some(BazHelper(true)));
61 assert_eq!(x, Baz(true, BazHelper(false), Some(BazHelper(true))));