1 #![feature(generic_associated_types)]
2
3 trait RefCont<'a, T> {
t(&'a self) -> &'a T4 fn t(&'a self) -> &'a T;
5 }
6
7 impl<'a, T> RefCont<'a, T> for &'a T {
t(&'a self) -> &'a T8 fn t(&'a self) -> &'a T {
9 self
10 }
11 }
12
13 impl<'a, T> RefCont<'a, T> for Box<T> {
t(&'a self) -> &'a T14 fn t(&'a self) -> &'a T {
15 self.as_ref()
16 }
17 }
18
19 trait MapLike<K, V> {
20 type VRefCont<'a>: RefCont<'a, V> where Self: 'a;
get<'a>(&'a self, key: &K) -> Option<Self::VRefCont<'a>>21 fn get<'a>(&'a self, key: &K) -> Option<Self::VRefCont<'a>>;
22 }
23
24 impl<K: Ord, V: 'static> MapLike<K, V> for std::collections::BTreeMap<K, V> {
25 type VRefCont<'a> where Self: 'a = &'a V;
get<'a>(&'a self, key: &K) -> Option<&'a V>26 fn get<'a>(&'a self, key: &K) -> Option<&'a V> {
27 std::collections::BTreeMap::get(self, key)
28 }
29 }
30
31 struct Source;
32
33 impl<K, V: Default> MapLike<K, V> for Source {
34 type VRefCont<'a> = Box<V>;
get<'a>(&self, _: &K) -> Option<Box<V>>35 fn get<'a>(&self, _: &K) -> Option<Box<V>> {
36 Some(Box::new(V::default()))
37 }
38 }
39
main()40 fn main() {
41 let m = Box::new(std::collections::BTreeMap::<u8, u8>::new())
42 as Box<dyn MapLike<u8, u8, VRefCont = dyn RefCont<'_, u8>>>;
43 //~^ ERROR missing generics for associated type
44 //~^^ ERROR the trait
45 //~^^^^ ERROR the trait
46 }
47