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

Calling a trait method as a free function yields odd diagnostics #98938

Closed
yoshuawuyts opened this issue Jul 5, 2022 · 4 comments
Closed

Calling a trait method as a free function yields odd diagnostics #98938

yoshuawuyts opened this issue Jul 5, 2022 · 4 comments
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints D-confusing Diagnostics: Confusing error or lint that should be reworked. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@yoshuawuyts
Copy link
Member

yoshuawuyts commented Jul 5, 2022

Given the following code: playground

trait Foo {
    fn bar() {}
}

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

The current output is:

error[E0283]: type annotations needed
 --> src/main.rs:4:5
  |
4 |     Foo::bar();
  |     ^^^^^^^^ cannot infer type
  |
  = note: cannot satisfy `_: Foo`

Ideally the output should look like:

Cannot call trait method as a free function. It needs an actual type to be implemented on for it to be called.

For bonus points: The trait is currently not callable since it's not implemented for anything. It needs to actually be implemented. "It looks like you're trying to call this trait method, but nothing implements it."

@yoshuawuyts yoshuawuyts 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 Jul 5, 2022
@wesleywiser wesleywiser added the D-confusing Diagnostics: Confusing error or lint that should be reworked. label Jul 6, 2022
@obeis
Copy link
Contributor

obeis commented Jul 10, 2022

@rustbot claim

@aticu
Copy link
Contributor

aticu commented Jul 19, 2022

This is addressed by #98028. The error message is now

error[E0790]: cannot call associated function on trait without specifying the corresponding `impl` type
 --> test.rs:6:5
  |
2 |     fn bar() {}
  |     ----------- `Foo::bar` defined here
...
6 |     Foo::bar();
  |     ^^^^^^^^ cannot call associated function of trait

@compiler-errors
Copy link
Member

Heads up @obeis #99308

@compiler-errors
Copy link
Member

I'm gonna close this since it seems like it's fixed. Feel free to file another bug if there are additional changes desired 😄

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-confusing Diagnostics: Confusing error or lint that should be reworked. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants