-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
First complains on wrong types and wrong arguments count and then complains that the function doesn't exist #106929
Comments
I think this might be due to the desugaring of the |
@estebank , I removed |
Here is even more reduced example: struct Client;
impl Client {
fn post<T: std::ops::Add>(&self, _: T, _: T) {}
}
fn f() {
let c = Client;
post(c, ());
} |
Ok, now I see. What's happening is that the E0425 is recovering a resolution error for |
Don't typecheck recovered method call from suggestion Only make the use-dot-operator-to-call-method suggestion, but do not double down and use the recovered type to perform method call typechecking as it will produce confusing diagnostics relevant for the *fixed* code. ### Code Sample ```rust struct Client; impl Client { fn post<T: std::ops::Add>(&self, _: T, _: T) {} } fn f() { let c = Client; post(c, ()); } ``` ### Before This PR ``` error[[E0277]](https://doc.rust-lang.org/stable/error_codes/E0277.html): cannot add `()` to `()` --> src/lib.rs:9:5 | 9 | post(c, ()); | ^^^^^^^^^^^ no implementation for `() + ()` | = help: the trait `Add` is not implemented for `()` note: required by a bound in `Client::post` --> src/lib.rs:4:16 | 4 | fn post<T: std::ops::Add>(&self, _: T, _: T) {} | ^^^^^^^^^^^^^ required by this bound in `Client::post` error[[E0061]](https://doc.rust-lang.org/stable/error_codes/E0061.html): this function takes 2 arguments but 1 argument was supplied --> src/lib.rs:9:5 | 9 | post(c, ()); | ^^^^ an argument of type `()` is missing | note: method defined here --> src/lib.rs:4:8 | 4 | fn post<T: std::ops::Add>(&self, _: T, _: T) {} | ^^^^ ----- ---- ---- help: provide the argument | 9 | post((), ())(c, ()); | ++++++++ error[[E0425]](https://doc.rust-lang.org/stable/error_codes/E0425.html): cannot find function `post` in this scope --> src/lib.rs:9:5 | 9 | post(c, ()); | ^^^^ not found in this scope | help: use the `.` operator to call the method `post` on `&Client` | 9 - post(c, ()); 9 + c.post(()); | Some errors have detailed explanations: E0061, E0277, E0425. For more information about an error, try `rustc --explain E0061`. ``` ### After This PR ``` error[E0425]: cannot find function `post` in this scope --> tests/ui/typeck/issue-106929.rs:9:5 | 9 | post(c, ()); | ^^^^ not found in this scope | help: use the `.` operator to call the method `post` on `&Client` | 9 - post(c, ()); 9 + c.post(()); | error: aborting due to previous error For more information about this error, try `rustc --explain E0425`. ``` Fixes rust-lang#106929.
Yes, the bug is fixed |
Code
Current output
Desired output
I think errors should be in other order
Rationale and extra context
Provided code is minimal reproducer extracted from actual code from my project.
In some point I had function
post
in my code called frommain
. But then I commentedpost
and forgot about that. Then I run compiler and saw these very strange error messages. I usually read compiler errors from begin to end. The first error said that I have no&Key: IntoUrl
satisfied. This is very strange. Why I should have&Key: IntoUrl
satisfied? I stared at this very strange error for some time. And then I decided to see other error messages. And then I suddenly saw error message (at 3rd place) thatpost
is not defined at all! At this moment I understood thatpost
is commented (remember: my actual code is big, so it is easy to miss this).So, the problem is so: rustc is simply too smart. Rustc should simply complain that
post
is not defined. But rustc goes further and "fixes" it and then complains thatpost
is called with wrong number of arguments and that bounds are not satisfied. And moreover rustc gives error messages in wrong order: first complains that traits are not satisfied and argument number is wrong and then complains that there is nopost
at all!Remember: I usually read first error message only and ignore the rest.
Rustc version is 1.66.1 stable
Other cases
No response
Anything else?
No response
The text was updated successfully, but these errors were encountered: