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 //~^ WARNING the feature `generic_associated_types` is incomplete
13 #![feature(associated_type_defaults)]
15 // FIXME(#44265): "lifetime parameters are not allowed on this type" errors will be addressed in a
18 // A Collection trait and collection families. Based on
19 // http://smallcultfollowing.com/babysteps/blog/2016/11/03/
20 // associated-type-constructors-part-2-family-traits/
23 type Iter<'iter>: Iterator<Item=&'iter T>;
24 type Family: CollectionFamily;
25 // Test associated type defaults with parameters
26 type Sibling<U>: Collection<U> =
27 <<Self as Collection<T>>::Family as CollectionFamily>::Member<U>;
28 //~^ ERROR type parameters are not allowed on this type [E0109]
32 fn add(&mut self, value: T);
34 fn iterate<'iter>(&'iter self) -> Self::Iter<'iter>;
35 //~^ ERROR lifetime parameters are not allowed on this type [E0110]
38 trait CollectionFamily {
39 type Member<T>: Collection<T, Family = Self>;
44 impl CollectionFamily for VecFamily {
45 type Member<T> = Vec<T>;
48 impl<T> Collection<T> for Vec<T> {
49 type Iter<'iter> = std::slice::Iter<'iter, T>;
50 type Family = VecFamily;
56 fn add(&mut self, value: T) {
60 fn iterate<'iter>(&'iter self) -> Self::Iter<'iter> {
61 //~^ ERROR lifetime parameters are not allowed on this type [E0110]
66 fn floatify<C>(ints: &C) -> <<C as Collection<i32>>::Family as CollectionFamily>::Member<f32>
67 //~^ ERROR type parameters are not allowed on this type [E0109]
71 let mut res = C::Family::Member::<f32>::empty();
72 for &v in ints.iterate() {
78 fn floatify_sibling<C>(ints: &C) -> <C as Collection<i32>>::Sibling<f32>
79 //~^ ERROR type parameters are not allowed on this type [E0109]
83 let mut res = C::Family::Member::<f32>::empty();
84 for &v in ints.iterate() {
91 let a = vec![1i32, 2, 3];
93 println!("{}", b.iterate().next());
94 let c = floatify_sibling(a);
95 println!("{}", c.iterate().next());