]> git.lizzy.rs Git - rust.git/blob - src/test/ui/associated-types/associated-types-struct-field-named.rs
feat(rustdoc): open sidebar menu when links inside it are focused
[rust.git] / src / test / ui / associated-types / associated-types-struct-field-named.rs
1 // run-pass
2 // Test that we correctly normalize the type of a struct field
3 // which has an associated type.
4
5
6 pub trait UnifyKey {
7     type Value;
8
9     fn dummy(&self) { }
10 }
11
12 pub struct Node<K:UnifyKey> {
13     pub key: K,
14     pub value: K::Value,
15 }
16
17 fn foo<K : UnifyKey<Value=Option<V>>,V : Clone>(node: &Node<K>) -> Option<V> {
18     node.value.clone()
19 }
20
21 impl UnifyKey for i32 {
22     type Value = Option<u32>;
23 }
24
25 impl UnifyKey for u32 {
26     type Value = Option<i32>;
27 }
28
29 pub fn main() {
30     let node: Node<i32> = Node { key: 1, value: Some(22) };
31     assert_eq!(foo(&node), Some(22));
32
33     let node: Node<u32> = Node { key: 1, value: Some(22) };
34     assert_eq!(foo(&node), Some(22));
35 }