Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
glandium opened this issue Mar 10, 2020 · 2 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-bug Category: This is a bug. D-incorrect Diagnostics: A diagnostic that is giving misleading or incorrect information. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@glandium
Copy link
Contributor

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.lhy31512.workers.dev-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
@glandium glandium added the C-bug Category: This is a bug. label Mar 10, 2020
@Mark-Simulacrum Mark-Simulacrum added A-diagnostics Area: Messages for errors, warnings, and lints D-incorrect Diagnostics: A diagnostic that is giving misleading or incorrect information. labels Mar 10, 2020
@ehuss
Copy link
Contributor

ehuss commented Mar 10, 2020

I think this is a duplicate of #26454.

@Centril Centril added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Mar 10, 2020
@carols10cents
Copy link
Member

Yes, closing as duplicate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-bug Category: This is a bug. D-incorrect Diagnostics: A diagnostic that is giving misleading or incorrect information. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

5 participants