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

Confusing diagnostic when argument type in impl FnOnce() is not found #113566

Closed
GoldsteinE opened this issue Jul 11, 2023 · 2 comments · Fixed by #113578
Closed

Confusing diagnostic when argument type in impl FnOnce() is not found #113566

GoldsteinE opened this issue Jul 11, 2023 · 2 comments · Fixed by #113578
Assignees
Labels
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.

Comments

@GoldsteinE
Copy link
Contributor

GoldsteinE commented Jul 11, 2023

Code

type Foo = Bar;

fn check(f: impl FnOnce(Foo), val: Foo) {
    f(val);
}

Current output

Compiling playground v0.0.1 (/playground)
error[E0412]: cannot find type `Bar` in this scope
 --> src/lib.rs:1:12
  |
1 | type Foo = Bar;
  |            ^^^ not found in this scope

error[E0618]: expected function, found `impl FnOnce(Foo)`
 --> src/lib.rs:4:5
  |
3 | fn check(f: impl FnOnce(Foo), val: Foo) {
  |          - `f` has type `impl FnOnce(Foo)`
4 |     f(val);
  |     ^-----
  |     |
  |     call expression requires function

Some errors have detailed explanations: E0412, E0618.
For more information about an error, try `rustc --explain E0412`.
error: could not compile `playground` (lib) due to 2 previous errors

Desired output

Compiling playground v0.0.1 (/playground)
error[E0412]: cannot find type `Bar` in this scope
 --> src/lib.rs:1:12
  |
1 | type Foo = Bar;
  |            ^^^ not found in this scope


Some errors have detailed explanations: E0412, E0618.
For more information about an error, try `rustc --explain E0412`.
error: could not compile `playground` (lib) due to 2 previous errors

Rationale and extra context

Saying that impl FnOnce() is not a function is confusing and distracts from the real issue. I think compiler should either report nothing on the line with the call or say something about unknown types in function signature.

Other cases

type Foo = Bar;

// Doesn’t exhibit this issue
fn check(f: impl FnOnce() -> Foo) {
    f();
}

Anything else?

No response

@GoldsteinE GoldsteinE 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 11, 2023
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Jul 11, 2023
@compiler-errors
Copy link
Member

compiler-errors commented Jul 11, 2023

I think this regressed in #106309. I still think that PR is worthwhile, even though this regression makes this error a bit more confusing, since it fixed other confusing errors 🤣 -- let me see if I can suppress it via other means.

@compiler-errors compiler-errors self-assigned this Jul 11, 2023
@Noratrieb Noratrieb removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Jul 12, 2023
@chriskrycho
Copy link
Contributor

I ran into this today, and the current status is extremely non-obvious when the actual underlying issue is a mismatch in the argument types for a closure passed vs. what is expected. The "expected function, found…" is difficult for an end user to understand; I figured out that it was actually a mismatched argument type only because I could connect it to the kind of refactor I was in the middle of and thinking through what other errors happened to be "in scope".

@bors bors closed this as completed in a6bf68d Jul 26, 2023
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 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