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