1 // Copyright 2012 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 #![feature(generic_associated_types)]
12 #![feature(associated_type_defaults)]
14 //FIXME(#44265): "lifetime parameters are not allowed on this type" errors will be addressed in a
17 // A Collection trait and collection families. Based on
18 // http://smallcultfollowing.com/babysteps/blog/2016/11/03/
19 // associated-type-constructors-part-2-family-traits/
22 type Iter<'iter>: Iterator<Item=&'iter T>;
23 type Family: CollectionFamily;
24 // Test associated type defaults with parameters
25 type Sibling<U>: Collection<U> =
26 <<Self as Collection<T>>::Family as CollectionFamily>::Member<U>;
27 //~^ ERROR type parameters are not allowed on this type [E0109]
31 fn add(&mut self, value: T);
33 fn iterate<'iter>(&'iter self) -> Self::Iter<'iter>;
34 //~^ ERROR lifetime parameters are not allowed on this type [E0110]
37 trait CollectionFamily {
38 type Member<T>: Collection<T, Family = Self>;
43 impl CollectionFamily for VecFamily {
44 type Member<T> = Vec<T>;
47 impl<T> Collection<T> for Vec<T> {
48 type Iter<'iter> = std::slice::Iter<'iter, T>;
49 type Family = VecFamily;
55 fn add(&mut self, value: T) {
59 fn iterate<'iter>(&'iter self) -> Self::Iter<'iter> {
60 //~^ ERROR lifetime parameters are not allowed on this type [E0110]
65 fn floatify<C>(ints: &C) -> <<C as Collection<i32>>::Family as CollectionFamily>::Member<f32>
66 //~^ ERROR type parameters are not allowed on this type [E0109]
70 let mut res = C::Family::Member::<f32>::empty();
71 for &v in ints.iterate() {
77 fn floatify_sibling<C>(ints: &C) -> <C as Collection<i32>>::Sibling<f32>
78 //~^ ERROR type parameters are not allowed on this type [E0109]
82 let mut res = C::Family::Member::<f32>::empty();
83 for &v in ints.iterate() {
90 let a = vec![1i32, 2, 3];
92 println!("{}", b.iterate().next());
93 let c = floatify_sibling(a);
94 println!("{}", c.iterate().next());