rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
96.74k stars 12.5k forks source link

Poor error message with type alias and external crate #44478

Open mrmonday opened 7 years ago

mrmonday commented 7 years ago

The following code: https://play.rust-lang.org/?gist=3a06bcc680135c042135ca45984379f7&version=stable

extern crate num;

use num::One;
use num::rational::BigRational;

fn main() {
    BigRational::pow(&BigRational::one(), 23);
}

Gives the following error:

error[E0599]: no function or associated item named `pow` found for type `num::rational::Ratio<num::BigInt>` in the current scope
 --> src/main.rs:7:5
  |
7 |     BigRational::pow(BigRational::one(), 23);
  |     ^^^^^^^^^^^^^^^^
  |
  = note: the method `pow` exists but the following trait bounds were not satisfied:
          `num::BigInt : num::PrimInt`

This is poor for several reasons:

BGR360 commented 2 years ago

The error message is now different:

error[E0308]: mismatched types
 --> src/main.rs:7:22
  |
7 |     BigRational::pow(BigRational::one(), 23);
  |                      ^^^^^^^^^^^^^^^^^^
  |                      |
  |                      expected `&Ratio<BigInt>`, found struct `Ratio`
  |                      help: consider borrowing here: `&BigRational::one()`
  |
  = note: expected reference `&Ratio<BigInt>`
                found struct `Ratio<BigInt>`

While it does give a nice (and correct) suggestion, it still doesn't substitute the type alias for the actual type, which I think would be a nice touch.