]> git.proxmox.com Git - rustc.git/blame - src/test/ui/generic-associated-types/issue-79422.rs
New upstream version 1.55.0+dfsg1
[rustc.git] / src / test / ui / generic-associated-types / issue-79422.rs
CommitLineData
5869c6ff
XL
1#![feature(generic_associated_types)]
2
3trait RefCont<'a, T> {
4 fn t(&'a self) -> &'a T;
5}
6
7impl<'a, T> RefCont<'a, T> for &'a T {
8 fn t(&'a self) -> &'a T {
9 self
10 }
11}
12
13impl<'a, T> RefCont<'a, T> for Box<T> {
14 fn t(&'a self) -> &'a T {
15 self.as_ref()
16 }
17}
18
19trait 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
24impl<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
31struct Source;
32
33impl<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
40fn 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}