]> git.lizzy.rs Git - rust.git/blob - src/test/ui/generic-associated-types/issue-79422.rs
Auto merge of #90535 - tmiasko:clone-from, r=oli-obk
[rust.git] / src / test / ui / generic-associated-types / issue-79422.rs
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> where Self: '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;
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>>>;
43       //~^ ERROR missing generics for associated type
44       //~^^ ERROR the trait
45       //~^^^^ ERROR the trait
46 }