]> git.lizzy.rs Git - rust.git/blob - src/test/ui/associated-types/associated-types-enum-field-numbered.rs
Merge commit '97a5daa65908e59744e2bc625b14849352231c75' into clippyup
[rust.git] / src / test / ui / associated-types / associated-types-enum-field-numbered.rs
1 // run-pass
2 // Test associated types appearing in tuple-like enum variants.
3
4
5 use self::VarValue::*;
6
7 pub trait UnifyKey {
8     type Value;
9     fn to_index(&self) -> usize;
10 }
11
12 pub enum VarValue<K:UnifyKey> {
13     Redirect(K),
14     Root(K::Value, usize),
15 }
16
17 fn get<'a,K:UnifyKey<Value=Option<V>>,V>(table: &'a Vec<VarValue<K>>, key: &K) -> &'a Option<V> {
18     match table[key.to_index()] {
19         VarValue::Redirect(ref k) => get(table, k),
20         VarValue::Root(ref v, _) => v,
21     }
22 }
23
24 impl UnifyKey for usize {
25     type Value = Option<char>;
26     fn to_index(&self) -> usize { *self }
27 }
28
29 fn main() {
30     let table = vec![/* 0 */ Redirect(1),
31                      /* 1 */ Redirect(3),
32                      /* 2 */ Root(Some('x'), 0),
33                      /* 3 */ Redirect(2)];
34     assert_eq!(get(&table, &0), &Some('x'));
35 }