]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/issue-4107.rs
d660f300ada99f4ac26cb4a86734966443c22d19
[rust.git] / src / test / run-pass / issue-4107.rs
1 // Copyright 2013 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.
4 //
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.
10
11 pub fn main() {
12     let _id: &Mat2<f64> = &Matrix::identity(1.0);
13 }
14
15 pub trait Index<Index,Result> { fn get(&self, Index) -> Result { panic!() } }
16 pub trait Dimensional<T>: Index<uint, T> { }
17
18 pub struct Mat2<T> { x: T }
19 pub struct Vec2<T> { x: T }
20
21 impl<T> Dimensional<Vec2<T>> for Mat2<T> { }
22 impl<T> Index<uint, Vec2<T>> for Mat2<T> { }
23
24 impl<T> Dimensional<T> for Vec2<T> { }
25 impl<T> Index<uint, T> for Vec2<T> { }
26
27 pub trait Matrix<T,V>: Dimensional<V> {
28     fn identity(t:T) -> Self;
29 }
30
31 impl<T> Matrix<T, Vec2<T>> for Mat2<T> {
32     fn identity(t:T) -> Mat2<T> { Mat2{ x: t } }
33 }