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 suggests implementing private trait #25358

Closed
daboross opened this issue May 13, 2015 · 2 comments
Closed

Rust suggests implementing private trait #25358

daboross opened this issue May 13, 2015 · 2 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@daboross
Copy link
Contributor

With the following code:

struct Foo;

fn main() {
    Foo::new();
}

(playpen: http://is.gd/H05mfZ)

Rust tries to help with:

<anon>:4:5: 4:13 help: methods from traits can only be called if the trait is implemented and in scope; the following trait defines a method `new`, perhaps you need to implement it:
<anon>:4:5: 4:13 help: candidate #1: `std::sys_common::thread_info::NewThread`

This trait is impossible to implement however, as it is private - when implemented, rust will give a separate error about the trait being private. If this is the case, rust shouldn't suggest it at all.

Here's a playpen actually implementing the trait in question: http://is.gd/UQakvD

While this really isn't that much of a problem, as it is pretty obvious (to me) that I don't want to implement a NewThread trait, suggestions like this from the compiler may be confusing and discourage new users of the language.

@sfackler sfackler added the A-diagnostics Area: Messages for errors, warnings, and lints label May 13, 2015
@huonw huonw added A-diagnostics Area: Messages for errors, warnings, and lints and removed A-diagnostics Area: Messages for errors, warnings, and lints labels May 13, 2015
@steveklabnik
Copy link
Member

Update: no change.

@steveklabnik steveklabnik added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Mar 9, 2017
@Mark-Simulacrum Mark-Simulacrum added the C-bug Category: This is a bug. label Jul 22, 2017
@estebank
Copy link
Contributor

error[E0599]: no function or associated item named `new` found for type `Foo` in the current scope
 --> src/main.rs:4:5
  |
1 | struct Foo;
  | ----------- function or associated item `new` not found for this
...
4 |     Foo::new();
  |     ^^^^^^^^ function or associated item not found in `Foo`

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

6 participants