]> git.proxmox.com Git - rustc.git/blame - src/test/run-pass/trait-inheritance-num2.rs
Imported Upstream version 1.0.0~beta.3
[rustc.git] / src / test / run-pass / trait-inheritance-num2.rs
CommitLineData
1a4d82fc 1// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
223e47cc
LB
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// A more complex example of numeric extensions
12
9346a6ac 13pub trait TypeExt {}
223e47cc
LB
14
15impl TypeExt for u8 {}
16impl TypeExt for u16 {}
17impl TypeExt for u32 {}
18impl TypeExt for u64 {}
c34b1796 19impl TypeExt for usize {}
223e47cc
LB
20
21impl TypeExt for i8 {}
22impl TypeExt for i16 {}
23impl TypeExt for i32 {}
24impl TypeExt for i64 {}
c34b1796 25impl TypeExt for isize {}
223e47cc
LB
26
27impl TypeExt for f32 {}
28impl TypeExt for f64 {}
223e47cc
LB
29
30
9346a6ac 31pub trait NumExt: TypeExt + PartialEq + PartialOrd {}
223e47cc
LB
32
33impl NumExt for u8 {}
34impl NumExt for u16 {}
35impl NumExt for u32 {}
36impl NumExt for u64 {}
c34b1796 37impl NumExt for usize {}
223e47cc
LB
38
39impl NumExt for i8 {}
40impl NumExt for i16 {}
41impl NumExt for i32 {}
42impl NumExt for i64 {}
c34b1796 43impl NumExt for isize {}
223e47cc
LB
44
45impl NumExt for f32 {}
46impl NumExt for f64 {}
223e47cc
LB
47
48
49pub trait UnSignedExt: NumExt {}
50
51impl UnSignedExt for u8 {}
52impl UnSignedExt for u16 {}
53impl UnSignedExt for u32 {}
54impl UnSignedExt for u64 {}
c34b1796 55impl UnSignedExt for usize {}
223e47cc
LB
56
57
58pub trait SignedExt: NumExt {}
59
60impl SignedExt for i8 {}
61impl SignedExt for i16 {}
62impl SignedExt for i32 {}
63impl SignedExt for i64 {}
c34b1796 64impl SignedExt for isize {}
223e47cc
LB
65
66impl SignedExt for f32 {}
67impl SignedExt for f64 {}
223e47cc
LB
68
69
70pub trait IntegerExt: NumExt {}
71
72impl IntegerExt for u8 {}
73impl IntegerExt for u16 {}
74impl IntegerExt for u32 {}
75impl IntegerExt for u64 {}
c34b1796 76impl IntegerExt for usize {}
223e47cc
LB
77
78impl IntegerExt for i8 {}
79impl IntegerExt for i16 {}
80impl IntegerExt for i32 {}
81impl IntegerExt for i64 {}
c34b1796 82impl IntegerExt for isize {}
223e47cc
LB
83
84
1a4d82fc 85pub trait FloatExt: NumExt {}
223e47cc
LB
86
87impl FloatExt for f32 {}
88impl FloatExt for f64 {}
223e47cc
LB
89
90
1a4d82fc 91fn test_float_ext<T:FloatExt>(n: T) { println!("{}", n < n) }
223e47cc
LB
92
93pub fn main() {
94 test_float_ext(1f32);
95}