rust/tests/ui/traits/inheritance/num5.rs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

26 lines
508 B
Rust
Raw Normal View History

//@ run-pass
pub trait NumCast: Sized {
2015-04-18 05:12:20 +00:00
fn from(i: i32) -> Option<Self>;
}
2014-11-10 00:30:52 +00:00
pub trait NumExt: PartialEq + NumCast {}
impl NumExt for f32 {}
impl NumExt for isize {}
2015-04-18 05:12:20 +00:00
impl NumCast for f32 {
fn from(i: i32) -> Option<f32> { Some(i as f32) }
}
impl NumCast for isize {
fn from(i: i32) -> Option<isize> { Some(i as isize) }
}
fn num_eq_one<T:NumExt>() -> T {
2015-01-25 21:05:03 +00:00
NumCast::from(1).unwrap()
}
pub fn main() {
num_eq_one::<isize>(); // you need to actually use the function to trigger the ICE
}