]> git.proxmox.com Git - rustc.git/blob - tests/ui/generic-associated-types/issue-79422.rs
New upstream version 1.68.2+dfsg1
[rustc.git] / tests / ui / generic-associated-types / issue-79422.rs
1 // revisions: base extended
2
3 #![cfg_attr(extended, feature(generic_associated_types_extended))]
4 #![cfg_attr(extended, allow(incomplete_features))]
5
6 trait RefCont<'a, T> {
7 fn t(&'a self) -> &'a T;
8 }
9
10 impl<'a, T> RefCont<'a, T> for &'a T {
11 fn t(&'a self) -> &'a T {
12 self
13 }
14 }
15
16 impl<'a, T> RefCont<'a, T> for Box<T> {
17 fn t(&'a self) -> &'a T {
18 self.as_ref()
19 }
20 }
21
22 trait MapLike<K, V> {
23 type VRefCont<'a>: RefCont<'a, V> where Self: 'a;
24 fn get<'a>(&'a self, key: &K) -> Option<Self::VRefCont<'a>>;
25 }
26
27 impl<K: Ord, V: 'static> MapLike<K, V> for std::collections::BTreeMap<K, V> {
28 type VRefCont<'a> = &'a V where Self: 'a;
29 fn get<'a>(&'a self, key: &K) -> Option<&'a V> {
30 std::collections::BTreeMap::get(self, key)
31 }
32 }
33
34 struct Source;
35
36 impl<K, V: Default> MapLike<K, V> for Source {
37 type VRefCont<'a> = Box<V>;
38 fn get<'a>(&self, _: &K) -> Option<Box<V>> {
39 Some(Box::new(V::default()))
40 }
41 }
42
43 fn main() {
44 let m = Box::new(std::collections::BTreeMap::<u8, u8>::new())
45 //[base]~^ ERROR the trait
46 //[extended]~^^ type mismatch
47 as Box<dyn MapLike<u8, u8, VRefCont = dyn RefCont<'_, u8>>>;
48 //~^ ERROR missing generics for associated type
49 //[base]~^^ ERROR the trait
50 }