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

Rustc suggests importing trait inside private module #90258

Closed
Nilstrieb opened this issue Oct 25, 2021 · 3 comments
Closed

Rustc suggests importing trait inside private module #90258

Nilstrieb opened this issue Oct 25, 2021 · 3 comments
Labels
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.

Comments

@Nilstrieb
Copy link
Member

fn main() {
    let _ = [0; 32].slice();
}

The current output is:

error[E0599]: no method named `slice` found for array `[{integer}; 32]` in the current scope
 --> priv.rs:2:18
  |
2 |     let _ = [0; 32].slice();
  |                     ^^^^^ method not found in `[{integer}; 32]`
  |
  = 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:
  |
1 | use std::collections::vec_deque::ring_slices::RingSlices;
  |

error: aborting due to previous error

For more information about this error, try `rustc --explain E0599`.

Here, rustc suggests importing the trait RingSlices, which is inside a private module and can't be used.

If possible, rustc should probably check whether a suggested trait is usable in the current module, and only suggest it if it is.

One thing that is useful about the current version is, that it might suggest that the user should make the module public if they control it. Maybe it should still be emitted if the trait is in the current crate.

Found by @angelsflyinhell, a rust beginner that was a bit confused by this

@Nilstrieb Nilstrieb 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 Oct 25, 2021
Nilstrieb added a commit to Nilstrieb/rust that referenced this issue Oct 25, 2021
This also changes the tests introduced by the previous commits because of another rustc issue (rust-lang#90258)
Nilstrieb added a commit to Nilstrieb/rust that referenced this issue Nov 3, 2021
Suggest adding a new lifetime parameter when two elided lifetimes should match up but don't

Issue rust-lang#90170

This also changes the tests introduced by the previous commits because of another rustc issue (rust-lang#90258)
@nsunderland1
Copy link
Contributor

I've also hit this, but there's another angle here. I have my own trait that was intended to be public, but I forgot to make it pub. rustc suggested that I try importing it, but what I'd really like for it to do is suggest that I make the trait public.

https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=c106a9ccab60655a33e4388f77d0b4c6

@Nilstrieb
Copy link
Member Author

I think it should still suggest it if it's in the same crate. But better now for external crates. If there's some way to find out if the external crate is in the same workspace, then this could be special cased as well to show it again.

@Nilstrieb
Copy link
Member Author

Update: on the current nightly, I don't get the suggestion anymore.

error[E0599]: no method named `slice` found for array `[{integer}; 32]` in the current scope
 --> aaa.rs:2:21
  |
2 |     let _ = [0; 32].slice();
  |                     ^^^^^ help: there is a method with a similar name: `as_slice`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0599`.

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

2 participants