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

Constraint information is not propagated #1178

Open
yongqli opened this issue Jun 26, 2015 · 2 comments
Open

Constraint information is not propagated #1178

yongqli opened this issue Jun 26, 2015 · 2 comments
Labels
T-lang Relevant to the language team, which will review and decide on the RFC.

Comments

@yongqli
Copy link

yongqli commented Jun 26, 2015

I would expect this code to compile, but it does not:

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
    }
}

Having to repeat constraints leads to more verbose code and is only repeating information that the compiler already knows.

See previous discussion: rust-lang/rust#26564

@withoutboats
Copy link
Contributor

I didn't even know constraining by something like f64: Mul<Self, Output=Self> was valid.

Binary operator overloads are somewhat unusual in that there is no inherent conceptual Self trait (lhs being chosen arbitrary), but for most traits there would be little reason to attempt to constrain it in this way. And really, there is not much reason I can see not to write:

pub trait M: Sized + Mul<f64, Output=Self>

@nrc nrc added the T-lang Relevant to the language team, which will review and decide on the RFC. label Aug 25, 2016
@daxpedda
Copy link

daxpedda commented Dec 9, 2022

I believe this is a duplicate of #2089.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T-lang Relevant to the language team, which will review and decide on the RFC.
Projects
None yet
Development

No branches or pull requests

4 participants