]>
Commit | Line | Data |
---|---|---|
5869c6ff XL |
1 | #![feature(generic_associated_types)] |
2 | ||
3 | trait RefCont<'a, T> { | |
4 | fn t(&'a self) -> &'a T; | |
5 | } | |
6 | ||
7 | impl<'a, T> RefCont<'a, T> for &'a T { | |
8 | fn t(&'a self) -> &'a T { | |
9 | self | |
10 | } | |
11 | } | |
12 | ||
13 | impl<'a, T> RefCont<'a, T> for Box<T> { | |
14 | 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>; | |
5869c6ff XL |
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> = &'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>; | |
35 | fn get<'a>(&self, _: &K) -> Option<Box<V>> { | |
36 | Some(Box::new(V::default())) | |
37 | } | |
38 | } | |
39 | ||
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>>>; | |
17df50a5 XL |
43 | //~^ ERROR missing generics for associated type |
44 | //~^^ ERROR the trait | |
45 | //~^^^^ ERROR the trait | |
5869c6ff | 46 | } |