// run-pass // Test for issue #4183: use of Self in supertraits. pub static FUZZY_EPSILON: f64 = 0.1; pub trait FuzzyEq { fn fuzzy_eq(&self, other: &Self) -> bool; fn fuzzy_eq_eps(&self, other: &Self, epsilon: &Eps) -> bool; } trait Float: Sized+FuzzyEq { fn two_pi() -> Self; } impl FuzzyEq for f32 { fn fuzzy_eq(&self, other: &f32) -> bool { self.fuzzy_eq_eps(other, &(FUZZY_EPSILON as f32)) } fn fuzzy_eq_eps(&self, other: &f32, epsilon: &f32) -> bool { (*self - *other).abs() < *epsilon } } impl Float for f32 { fn two_pi() -> f32 { 6.28318530717958647692528676655900576_f32 } } impl FuzzyEq for f64 { fn fuzzy_eq(&self, other: &f64) -> bool { self.fuzzy_eq_eps(other, &(FUZZY_EPSILON as f64)) } fn fuzzy_eq_eps(&self, other: &f64, epsilon: &f64) -> bool { (*self - *other).abs() < *epsilon } } impl Float for f64 { fn two_pi() -> f64 { 6.28318530717958647692528676655900576_f64 } } fn compare(f1: F) -> bool { let f2 = Float::two_pi(); f1.fuzzy_eq(&f2) } pub fn main() { assert!(compare::(6.28318530717958647692528676655900576)); assert!(compare::(6.29)); assert!(compare::(6.3)); assert!(compare::(6.19)); assert!(!compare::(7.28318530717958647692528676655900576)); assert!(!compare::(6.18)); assert!(compare::(6.28318530717958647692528676655900576)); assert!(compare::(6.29)); assert!(compare::(6.3)); assert!(compare::(6.19)); assert!(!compare::(7.28318530717958647692528676655900576)); assert!(!compare::(6.18)); }