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

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

Open
cyrgani opened this issue Mar 7, 2025 · 1 comment
Open

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

cyrgani opened this issue Mar 7, 2025 · 1 comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints 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

@cyrgani
Copy link
Contributor

cyrgani commented Mar 7, 2025

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

@cyrgani cyrgani added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Mar 7, 2025
@rustbot rustbot added the D-incorrect Diagnostics: A diagnostic that is giving misleading or incorrect information. label Mar 7, 2025
@SauersML
Copy link

A similar issue, on rustc 1.83.0.

For error[E0599]: no method named X found for struct Y in the current scope, the compiler will give a useful hint, which includes:

help: trait `Z` which provides `X` is implemented but not in scope; perhaps you want to import it

     |

1   + use W::ops::Z;

     |

However, it will print this even when W is being used in Cargo.toml like so:
V = { package = "W", version = "0.3.2" }
Therefore, use W::ops::Z; is not the correct solution. Instead, the hint should be:


help: trait `Z` which provides `X` is implemented but not in scope; perhaps you want to import it

     |

1   + use V::ops::Z;

     |

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 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

3 participants