Graydon Hoare | d1affff | 2012-12-11 01:32:48 | [diff] [blame] | 1 | // Copyright 2012 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 | |
Erick Tryzelaar | ad5c676 | 2013-08-17 15:37:42 | [diff] [blame] | 11 | use std::cmp::Eq; |
Patrick Walton | 1be40be | 2013-05-21 00:07:24 | [diff] [blame] | 12 | use std::num::NumCast; |
Brian Anderson | 78ee821 | 2012-11-28 20:34:30 | [diff] [blame] | 13 | |
Brendan Zabarauskas | ce6ee7b | 2013-04-13 16:19:35 | [diff] [blame] | 14 | pub trait NumExt: Eq + Num + NumCast {} |
Brian Anderson | 78ee821 | 2012-11-28 20:34:30 | [diff] [blame] | 15 | |
Patrick Walton | 07c3f5c | 2013-02-27 01:12:00 | [diff] [blame] | 16 | impl NumExt for f32 {} |
| 17 | impl NumExt for int {} |
Brian Anderson | 78ee821 | 2012-11-28 20:34:30 | [diff] [blame] | 18 | |
| 19 | fn num_eq_one<T:NumExt>() -> T { |
Patrick Walton | db518ef | 2013-05-15 21:10:42 | [diff] [blame] | 20 | NumCast::from(1) |
Brian Anderson | 78ee821 | 2012-11-28 20:34:30 | [diff] [blame] | 21 | } |
| 22 | |
Graydon Hoare | 89c8ef7 | 2013-02-02 03:43:17 | [diff] [blame] | 23 | pub fn main() { |
Brian Anderson | 78ee821 | 2012-11-28 20:34:30 | [diff] [blame] | 24 | num_eq_one::<int>(); // you need to actually use the function to trigger the ICE |
| 25 | } |