Skip to content

Rust compiler should avoid mentioning private traits as solution to missing methods #69900

@glandium

Description

@glandium

Building the following code targeting Windows:

extern crate clap;

fn main() {
    let foo = std::ffi::OsString::from("foo").as_bytes();
}

says:

error[E0599]: no method named `as_bytes` found for struct `std::ffi::OsString` in the current scope
 --> src/main.rs:4:47
  |
4 |     let foo = std::ffi::OsString::from("foo").as_bytes();
  |                                               ^^^^^^^^ method not found in `std::ffi::OsString`
  |
  = help: items from traits can only be used if the trait is in scope
help: the following trait is implemented but not in scope; perhaps add a `use` for it:
  |
3 | use crate::clap::osstringext::OsStrExt3;
  |

If you add the suggested use, you get:

error[E0603]: module `osstringext` is private
   --> src/main.rs:3:18
    |
3   | use crate::clap::osstringext::OsStrExt3;
    |                  ^^^^^^^^^^^ this module is private
    |
note: the module `osstringext` is defined here
   --> /home/glandium/.cargo/registry/src/github.com-1ecc6299db9ec823/clap-2.33.0/src/lib.rs:568:1
    |
568 | mod osstringext;
    | ^^^^^^^^^^^^^^^^

I could get behind the suggesting if the module was local to the crate being built, but from an external crate, it's not helpful.

Meta

rustc --version --verbose:

rustc 1.43.0-nightly (3dbade652 2020-03-09)
binary: rustc
commit-hash: 3dbade652ed8ebac70f903e01f51cd92c4e4302c
commit-date: 2020-03-09
host: x86_64-unknown-linux-gnu
release: 1.43.0-nightly
LLVM version: 9.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsC-bugCategory: This is a bug.D-incorrectDiagnostics: A diagnostic that is giving misleading or incorrect information.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions