-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
"did you mean" for misusing a field as a method is misleading #38321
Comments
Why is it misleading? |
@whitequark Are you able to share the project where you encountered this error? |
Because it suggests to write the same thing as is already written. |
The suggestion is telling you to write |
It points to |
I've added a minimal repro to the issue text. |
Also, ideally it would highlight the entire |
I've got. It's a span problem. |
I just ran into this aswell. I agree that it would be more clear if it highlighted the whole
Would be even more helpfull |
Yes, I found this confusing, too. I should submit a PR to fix this tomorrow (have code fix, but still need to correct compile-fail test expectations, but even more than that, need to sleep). |
okay, not literally tomorrow, but soon |
The use of the `span_note` diagnostic method resulted in error messages that some users (including the present author) found very confusing: the code snippet and highlighted span displayed with the "did you mean" note was easy to interpret as a suggested edit (as if it had been set by `span_suggestion`), but was in fact identical to the snippet/span displayed just above, indicating the error in the original code, making it look as if the compiler was suggesting a no-op change. To remedy this, we use `help` instead of `span_note`, and reword one of the affected messages to emphasize the concept of accessing a field being different from calling a method (when the message just said, "did you mean to write `self.foo`", it was not immediately obvious that this was meant in contrast to `self.foo()`, with method-call parens). Resolves rust-lang#38321.
Clarify suggetion for field used as method Instead of ```rust error: no method named `src_addr` found for type `&wire::ipv4::Repr` in the current scope --> src/wire/ipv4.rs:409:34 | 409 | packet.set_src_addr(self.src_addr()); | ^^^^^^^^ | note: did you mean to write `self.src_addr`? --> src/wire/ipv4.rs:409:34 | 409 | packet.set_src_addr(self.src_addr()); | ^^^^^^^^ ``` present ```rust error: no method named `src_addr` found for type `&wire::ipv4::Repr` in the current scope --> src/wire/ipv4.rs:409:34 | 409 | packet.set_src_addr(self.src_addr()); | ^^^^^^^^ field, not a method | = help: did you mean to write `self.src_addr` instead of `self.src_addr(...)`? ``` Fix rust-lang#38321.
The error is currently:
which is of course absurd.
To reproduce:
The text was updated successfully, but these errors were encountered: