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

Verbose output for simple mistake of using method syntax for associated functions #102354

Closed
Rageking8 opened this issue Sep 27, 2022 · 0 comments · Fixed by #104580
Closed

Verbose output for simple mistake of using method syntax for associated functions #102354

Rageking8 opened this issue Sep 27, 2022 · 0 comments · Fixed by #104580
Labels
A-diagnostics Area: Messages for errors, warnings, and lints D-confusing Diagnostics: Confusing error or lint that should be reworked. D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. D-verbose Diagnostics: Too much output caused by a single piece of incorrect code. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@Rageking8
Copy link
Contributor

Given the following code: link

trait Trait {
    fn func() {}
}

impl Trait for i32 {}

fn main() {
    let x: i32 = 123;
    x.func();
}

The current output is:

Compiling playground v0.0.1 (/playground)
error[[E0599]](https://doc.rust-lang.org/nightly/error-index.html#E0599): no method named `func` found for type `i32` in the current scope
 --> src/main.rs:9:7
  |
9 |     x.func();
  |       ^^^^ this is an associated function, not a method
  |
  = note: found the following associated functions; to be used as methods, functions must have a `self` parameter
note: the candidate is defined in the trait `Trait`
 --> src/main.rs:2:5
  |
2 |     fn func() {}
  |     ^^^^^^^^^
  = help: items from traits can only be used if the trait is implemented and in scope
note: `Trait` defines an item `func`, perhaps you need to implement it
 --> src/main.rs:1:1
  |
1 | trait Trait {
  | ^^^^^^^^^^^
help: use associated function syntax instead
  |
9 |     i32::func();
  |     ~~~~~~~~~
help: disambiguate the associated function for the candidate
  |
9 |     <i32 as Trait>::func(x);
  |     ~~~~~~~~~~~~~~~~~~~~~~~

For more information about this error, try `rustc --explain E0599`.
error: could not compile `playground` due to previous error

In the above current output there are many general help and note messages which may not be super relevant in the above context. On top of that, there are 2 suggested help messages (bottom 2), where the first one (i32::func();) is correct and the second one (<i32 as Trait>::func(x);) is wrong with the extra parameter passed in. Hence, the ideal output should be much leaner and the only help message should the valid one. Thanks.

@rustbot label +D-invalid-suggestion +D-verbose +D-confusing

@Rageking8 Rageking8 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 Sep 27, 2022
@rustbot rustbot added D-confusing Diagnostics: Confusing error or lint that should be reworked. D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. D-verbose Diagnostics: Too much output caused by a single piece of incorrect code. labels Sep 27, 2022
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Oct 28, 2022
…tic-candidates, r=wesleywiser

diagnostics: do not suggest static candidates as traits to import

If it's a static candidate, then it's already implemented. Do not suggest it a second time for implementing.

Partial fix for rust-lang#102354
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Oct 28, 2022
…tic-candidates, r=wesleywiser

diagnostics: do not suggest static candidates as traits to import

If it's a static candidate, then it's already implemented. Do not suggest it a second time for implementing.

Partial fix for rust-lang#102354
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this issue Nov 19, 2022
…ide-sugg, r=compiler-errors

diagnostics: only show one suggestion for method -> assoc fn

Fixes rust-lang#102354
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this issue Nov 19, 2022
…ide-sugg, r=compiler-errors

diagnostics: only show one suggestion for method -> assoc fn

Fixes rust-lang#102354
@bors bors closed this as completed in df7ecbc Nov 19, 2022
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. D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. D-verbose Diagnostics: Too much output caused by a single piece of incorrect code. 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.

2 participants