item paths use the name of the item, which might differ from the name of the import

ea637e7
Opened by Ariel Ben-Yehuda at 2021-12-29 04:26:34

STR

Crate foo:

mod internal {
    pub struct S;
}

pub use internal::S as T;

Crate main:

extern crate foo;

fn main() {
    foo::T
}

Results

error[E0308]: mismatched types
 --> x.rs:4:5
  |
3 | fn main() {
  |           - expected `()` because of default return type
4 |     foo::T
  |     ^^^^^^ expected (), found struct `foo::S`
  |
  = note: expected type `()`
             found type `foo::S`

error: aborting due to previous error

The error message refers to foo::S, which does not exist (only foo::T does)

  1. On today's rustc, the message is even a little more confusing (at least, if the type comes from the same crate, haven't tried it outside of the playground yet):

    mod krate {
        mod internal {
            pub struct S;
        }
        
        pub use self::internal::S as T;
    }
    
    fn main() {
        krate::T
    }
    
    error[E0308]: mismatched types
      --> src/main.rs:10:5
       |
    9  | fn main() {
       |           - expected `()` because of default return type
    10 |     krate::T
       |     ^^^^^^^^ expected `()`, found struct `S`
    

    It doesn't even give a full path for the S type.

    Playground

    Potentially related: https://github.com/rust-lang/rust/issues/44478

    Ben Reeves at 2021-12-29 04:26:34