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