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 keeps suggesting std::iter::ZipImpl trait who has a "new" method. #45781

Closed
crlf0710 opened this issue Nov 5, 2017 · 6 comments
Closed
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-bug Category: This is a bug.

Comments

@crlf0710
Copy link
Member

crlf0710 commented Nov 5, 2017

This is not a real big deal, however rustc keeps suggesting "ZipImpl", which is a implementation detail and rarely is what people want.

Any chance to rename it somehow?

@Mark-Simulacrum
Copy link
Member

Could you provide more context? A sample of the code and the error message suggesting ZipImpl would be helpful.

@ExpHP
Copy link
Contributor

ExpHP commented Nov 5, 2017

struct T;

fn main() {
    T::new();
}
   Compiling playground v0.0.1 (file:///playground)
error[E0599]: no function or associated item named `new` found for type `main::T` in the current scope
 --> src/main.rs:3:5
  |
3 |     T::new();
  |     ^^^^^^
  |
  = help: items from traits can only be used if the trait is implemented and in scope
  = note: the following trait defines an item `new`, perhaps you need to implement it:
          candidate #1: `std::iter::ZipImpl`

@durka
Copy link
Contributor

durka commented Nov 5, 2017

Maybe the suggestions should filter out #[doc(hidden)] items?

@ExpHP
Copy link
Contributor

ExpHP commented Nov 5, 2017

oddly enough, ZipImpl isn't just #[doc(hidden)], but it is, in fact, private.

@kennytm kennytm added A-diagnostics Area: Messages for errors, warnings, and lints C-bug Category: This is a bug. labels Nov 5, 2017
@zackmdavis
Copy link
Member

Currently, we just check that at least one of the type and the trait is local, so indeed, this will false-positive for private traits:

// we approximate the coherence rules to only suggest
// traits that are legal to implement by requiring that
// either the type or trait is local. Multidispatch means
// this isn't perfect (that is, there are cases when
// implementing a trait would be legal but is rejected
// here).
(type_is_local || info.def_id.is_local())
&& self.associated_item(info.def_id, item_name, Namespace::Value).is_some()

@estebank
Copy link
Contributor

CC #25358, #26454.

GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this issue Jan 25, 2018
…etrochenkov

On missing method do not suggest private traits

When encountering a method call for an ADT that doesn't have any
implementation of it, we search for traits that could be implemented
that do have that method. Filter out private non-local traits that would
not be able to be implemented.

This doesn't account for public traits that are in a private scope, but
works as a first approximation and is a more correct behavior than the
current one.

Fix rust-lang#45781.
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this issue Jan 25, 2018
…etrochenkov

On missing method do not suggest private traits

When encountering a method call for an ADT that doesn't have any
implementation of it, we search for traits that could be implemented
that do have that method. Filter out private non-local traits that would
not be able to be implemented.

This doesn't account for public traits that are in a private scope, but
works as a first approximation and is a more correct behavior than the
current one.

Fix rust-lang#45781.
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.
Projects
None yet
Development

No branches or pull requests

7 participants