Skip to content

Problem with self when inheriting generic traits. #4183

Closed
@brendanzab

Description

@brendanzab
extern mod std;
use std::cmp::FuzzyEq;

trait Float: FuzzyEq<Self> {
    static pure fn two_pi() -> Self;
}

impl f32: Float {
    static pure fn two_pi() -> f32 { 6.28318530717958647692528676655900576_f32 }
}

struct Radians<T>(T);

impl<T:Copy Float> Radians<T> {
    static pure fn full_turn() -> Radians<T> { Radians(Float::two_pi())    }
}

fn main() {}
src/float.rs:16:55: 16:68 error: mismatched types: expected `@FuzzyEq<'a>` but found `@FuzzyEq<self>` (expected type parameter but found self)
src/float.rs:16     static pure fn full_turn() -> Radians<T> { Radians(Float::two_pi())    }
                                                                       ^~~~~~~~~~~~~
error: aborting due to previous error

Update: changed to capitalized Self
Update: Use FuzzyEq trait from std::cmp

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions