Skip to content

Need to repeat bounds of Associated Types #20705

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

Closed
bluss opened this issue Jan 7, 2015 · 2 comments
Closed

Need to repeat bounds of Associated Types #20705

bluss opened this issue Jan 7, 2015 · 2 comments
Labels
A-associated-items Area: Associated items (types, constants & functions)

Comments

@bluss
Copy link
Member

bluss commented Jan 7, 2015

Even if the trait in the example declares a bound for its associated type, we have to repeat it to have the code compile.

Remove the where <T as HasNumber>::N: SignedInt and we get a compilation error:

 type `<T as HasNumber>::N` does not implement any method in scope named `abs`
use std::num::SignedInt;

trait HasNumber {
    type N: SignedInt;
    fn number(&self) -> Self::N;
}

fn user<T>(x: T) 
    where
        T: HasNumber,
        <T as HasNumber>::N: SignedInt,
{
    let n = x.number(); // ok
                        // without the repeated bound on T::N, we get this:
    let nabs = n.abs(); // type `<T as HasNumber>::N` does not implement any method in scope named `abs`
}

fn main() {
}

rustc version:

rustc 1.0.0-nightly (ea6f65c5f 2015-01-06 19:47:08 +0000)
binary: rustc
commit-hash: ea6f65c5f1a3f84e010d2cef02a0160804e9567a
commit-date: 2015-01-06 19:47:08 +0000
host: x86_64-unknown-linux-gnu
release: 1.0.0-nightly

cc @nikomatsakis

@jroesch
Copy link
Member

jroesch commented Jan 7, 2015

cc me

@nrc
Copy link
Member

nrc commented Jan 8, 2015

dup of #20559

@nrc nrc closed this as completed Jan 8, 2015
@nrc nrc added the A-associated-items Area: Associated items (types, constants & functions) label Jan 8, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-associated-items Area: Associated items (types, constants & functions)
Projects
None yet
Development

No branches or pull requests

3 participants