-
Notifications
You must be signed in to change notification settings - Fork 13.8k
Closed
Labels
A-associated-itemsArea: Associated items (types, constants & functions)Area: Associated items (types, constants & functions)
Description
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
Metadata
Metadata
Assignees
Labels
A-associated-itemsArea: Associated items (types, constants & functions)Area: Associated items (types, constants & functions)