Repository: rust
Issue: suggestion in unresolved trait method calls misses crate `as` rename
Labels: C-enhancement,A-diagnostics,T-compiler,D-confusing

Okay get ready, this is quite a combination of pieces to fit together to reproduce this.

If crate A defines a trait (with a method), and crate B rexports A under a new name (via `pub extern crate A as NewName`), and crate C pulls in crate B and makes a call to the trait's method without importing the trait or without implementing it ...

... then the diagnostic produced by rustc comes *close* but just misses the mark, because it ignores B's rename of A in its suggestion.

Under the details below is a complete set of steps to reproduce; here I use four separate instances of the "A" in my example above, in order to enumerate the four combinations of {pub,}{,as _}:

<details>

```
% ls *.rs
case_four.rs	case_three.rs	reexporter.rs
case_one.rs	case_two.rs	test.rs
% cat case_one.rs
```
```rust
#![crate_type="lib"]
pub fn function_in_one() -> &'static str { "find me!" }

pub trait TraitInOne { fn find_me_1() { } }
```
```
% cat case_two.rs
```
```rust
#![crate_type="lib"]
pub fn function_in_two() -> &'static str { "find me!" }

pub trait TraitInTwo { fn find_me_2() { } }
```
```rust
% cat case_three.rs
#![crate_type="lib"]
pub fn function_in_three() -> &'static str { "find me!" }

pub trait TraitInThree { fn find_me_3() { } }
```
```
% cat case_four.rs
```
```rust
#![crate_type="lib"]
pub fn function_in_four() -> &'static str { "find me!" }

pub trait TraitInFour { fn find_me_4() { } }
```
```
% cat reexporter.rs
```
```rust
#![crate_type="lib"]

extern crate case_one;
extern crate case_two as two;
pub extern crate case_three;
pub extern crate case_four as four;
```
```
% cat test.rs
```
```rust
extern crate reexporter;

struct T;

fn main() {
    T.find_me_1();
    T.find_me_2();
    T.find_me_3();
    T.find_me_4();
}
```
```
% rustc --version
rustc 1.29.0-nightly (4f3c7a472 2018-07-17)
% rustc case_one.rs && rustc case_two.rs && rustc case_three.rs && rustc case_four.rs && rustc -L . reexporter.rs
% rustc -L . test.rs
error[E0599]: no method named `find_me_1` found for type `T` in the current scope
 --> test.rs:6:7
  |
3 | struct T;
  | --------- method `find_me_1` not found for this
...
6 |     T.find_me_1();
  |       ^^^^^^^^^
  |
  = help: items from traits can only be used if the trait is implemented and in scope
  = note: the following trait defines an item `find_me_1`, perhaps you need to implement it:
          candidate #1: `case_one::TraitInOne`

error[E0599]: no method named `find_me_2` found for type `T` in the current scope
 --> test.rs:7:7
  |
3 | struct T;
  | --------- method `find_me_2` not found for this
...
7 |     T.find_me_2();
  |       ^^^^^^^^^
  |
  = help: items from traits can only be used if the trait is implemented and in scope
  = note: the following trait defines an item `find_me_2`, perhaps you need to implement it:
          candidate #1: `case_two::TraitInTwo`

error[E0599]: no method named `find_me_3` found for type `T` in the current scope
 --> test.rs:8:7
  |
3 | struct T;
  | --------- method `find_me_3` not found for this
...
8 |     T.find_me_3();
  |       ^^^^^^^^^
  |
  = help: items from traits can only be used if the trait is implemented and in scope
  = note: the following trait defines an item `find_me_3`, perhaps you need to implement it:
          candidate #1: `reexporter::case_three::TraitInThree`

error[E0599]: no method named `find_me_4` found for type `T` in the current scope
 --> test.rs:9:7
  |
3 | struct T;
  | --------- method `find_me_4` not found for this
...
9 |     T.find_me_4();
  |       ^^^^^^^^^
  |
  = help: items from traits can only be used if the trait is implemented and in scope
  = note: the following trait defines an item `find_me_4`, perhaps you need to implement it:
          candidate #1: `reexporter::case_four::TraitInFour`

error: aborting due to 4 previous errors

For more information about this error, try `rustc --explain E0599`.
% 
```

</details>

----

(Also of potential interest after reviewing the results from the cases enumerated in the details block: the diagnostic also suggests the paths `case_one::TraitInOne` and `case_two::TraitInTwo`, even though these crates are themselves not linked by `test.rs` itself. This is probably better than saying nothing at all, but it could be nice to give a hint to the user that they'll need to also add the `extern crate` declarations in `test.rs` itself?)