1 // Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
11 // Test associated types appearing in tuple-like enum variants.
13 use self::VarValue::*;
17 fn to_index(&self) -> usize;
20 pub enum VarValue<K:UnifyKey> {
22 Root(K::Value, usize),
25 fn get<'a,K:UnifyKey<Value=Option<V>>,V>(table: &'a Vec<VarValue<K>>, key: &K) -> &'a Option<V> {
26 match table[key.to_index()] {
27 VarValue::Redirect(ref k) => get(table, k),
28 VarValue::Root(ref v, _) => v,
32 impl UnifyKey for usize {
33 type Value = Option<char>;
34 fn to_index(&self) -> usize { *self }
38 let table = vec![/* 0 */ Redirect(1),
40 /* 2 */ Root(Some('x'), 0),
42 assert_eq!(get(&table, &0), &Some('x'));