]> git.proxmox.com Git - rustc.git/blame - src/test/run-pass/associated-types/associated-types-struct-field-numbered.rs
New upstream version 1.37.0+dfsg1
[rustc.git] / src / test / run-pass / associated-types / associated-types-struct-field-numbered.rs
CommitLineData
b7449926 1// run-pass
85aaf69f
SL
2// Test that we correctly normalize the type of a struct field
3// which has an associated type.
4
c34b1796 5
85aaf69f
SL
6pub trait UnifyKey {
7 type Value;
8
9 fn dummy(&self) { }
10}
11
12pub struct Node<K:UnifyKey>(K, K::Value);
13
14fn foo<K : UnifyKey<Value=Option<V>>,V : Clone>(node: &Node<K>) -> Option<V> {
15 node.1.clone()
16}
17
18impl UnifyKey for i32 {
19 type Value = Option<u32>;
20}
21
22impl UnifyKey for u32 {
23 type Value = Option<i32>;
24}
25
26pub fn main() {
27 let node: Node<i32> = Node(1, Some(22));
c34b1796 28 assert_eq!(foo(&node), Some(22));
85aaf69f
SL
29
30 let node: Node<u32> = Node(1, Some(22));
c34b1796 31 assert_eq!(foo(&node), Some(22));
85aaf69f 32}