Skip to content

Imports from private std dependency object shouldn't be suggested #138191

Open
@cyrgani

Description

@cyrgani

Code

struct VecReader(Vec<u8>);
impl std::io::Read for VecReader {
    fn read(&mut self, buf: &mut [u8]) -> std::io::Result<usize> {
        self.0.read(buf)
    }
}

Current output

error[E0599]: no method named `read` found for struct `Vec<u8>` in the current scope
 --> src/lib.rs:4:16
  |
4 |         self.0.read(buf)
  |                ^^^^
  |
  = help: items from traits can only be used if the trait is in scope
help: trait `ReadRef` which provides `read` is implemented but not in scope; perhaps you want to import it
  |
1 + use object::read::read_ref::ReadRef;
  |
help: there is a method `read_at` with a similar name
  |
4 |         self.0.read_at(buf)
  |                    +++

Desired output

error[E0599]: no method named `read` found for struct `Vec<u8>` in the current scope
 --> src/lib.rs:4:16
  |
4 |         self.0.read(buf)
  |                ^^^^
  |

Rationale and extra context

object is not a dependency of my crate, so the suggestion cannot work (additionally, object::read::read_ref::ReadRef appears to be private too (?))

Other cases

Rust Version

rustc 1.87.0-nightly (b74da9613 2025-03-06)
binary: rustc
commit-hash: b74da9613a8cb5ba67a985f71325be0b7b16c0dd
commit-date: 2025-03-06
host: x86_64-unknown-linux-gnu
release: 1.87.0-nightly
LLVM version: 20.1.0

Anything else?

No response

@rustbot label D-incorrect

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsD-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

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions