How to use the methods of the original type from a type alias?

405 views Asked by At

The question might be a bit abstract, but I actually have a fairly simple example:

extern crate num;

use num::rational::Rational;

fn doit() -> Rational { Rational::new_raw(3, 5) }

And I get the error:

134:42 error: unresolved name `Rational::new_raw`.
fn doit() -> Rational { Rational::new_raw(3, 5) }
                        ^~~~~~~~~~~~~~~~~

So, the error is not on Rational itself (well imported, no problem elsewhere) but on trying to use Rational::new_raw. Now, from the documentation we get:

type Rational = Ratio<int>;

and

impl<T: Clone + Integer + Ord> Ratio<T> {
    fn new_raw(numer: T, denom: T) -> Ratio<T>;
    // ...
}

which makes me think it should be possible, but somehow... fails.

I have a work-around (forgetting that I have an alias at hand):

fn doit() -> Rational { Ratio::<int>::new_raw(3, 5) }

but the point of view of creating an alias is generally to avoid worrying about its actual representation so it is a bit annoying.

For reference, since rust-0.11 is a moving target:

$ rustc --version
rustc 0.11.0-pre-nightly (022a7b3 2014-05-22 01:06:25 -0700)
host: x86_64-unknown-linux-gnu

Is there a proper way to get this to work, or is this considered a bug ?

1

There are 1 answers

0
huon On BEST ANSWER

This is (mostly) intended behaviour at the moment: type is literally just an alias for a type, and doesn't allow for calling static methods. Issues #6894 and #11047 cover this.