Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trait information is discarded #26564

Closed
yongqli opened this issue Jun 25, 2015 · 3 comments
Closed

Trait information is discarded #26564

yongqli opened this issue Jun 25, 2015 · 3 comments

Comments

@yongqli
Copy link

yongqli commented Jun 25, 2015

I would expect this to compile, but it doesn't. Is this intentional? It seems that M2 discards the f64: Mul<Self, Output=Self> constraint.

use std::ops::{Mul};

pub trait M: Sized where f64: Mul<Self, Output=Self> {
}

pub trait M2: M {
    fn f(self, a: f64) -> Self {
        a * self
    }
}

Error is:

error: the trait `core::ops::Mul<Self>` is not implemented for the type `f64` [E0277]
<anon>:11         a * self
@arielb1
Copy link
Contributor

arielb1 commented Jun 25, 2015

Non-supertrait predicates (i.e. predicates not of the form Self: Trait<..>) are not automatically elaborated. You have to add them manually:

use std::ops::{Mul};

pub trait M: Sized where f64: Mul<Self, Output=Self> {
}

pub trait M2: M
        where f64 : Mul<Self, Output=Self> // <- ADDED
{
    fn f(self, a: f64) -> Self {
        a * self
    }
}

fn main() {}

We should document this better, through.

@yongqli
Copy link
Author

yongqli commented Jun 26, 2015

Should this be an RFC? Because it's quite tedious to repeat things the compiler already knows about.

@steveklabnik
Copy link
Member

Yes, this is currently expected behavior (at least, as I understand it) and would require an RFC to change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants