"Expected type [closure@...]
, found fn pointer" when unnecessarily return
ing a closure
#88097
Labels
A-closures
Area: Closures (`|…| { … }`)
A-diagnostics
Area: Messages for errors, warnings, and lints
A-inference
Area: Type inference
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
Given the following code:
The current output is:
Ideally the code would compile successfully, but if that is infeasible, it would be nice if the diagnostic contained a hint to remove the
return
. (It's rather head-scratching that the closure is being converted to a fn pointer even though the return type has also been resolved to be the closure type.)The
return
is entirely unnecessary here, but I imagine a beginner might include it unthinkingly (as I did) and not be able to even guess that thereturn
has anything to do with the type error.The results are the same on stable 1.54.0, beta, and nightly.
If I modify the closure to not be coercible to a function pointer by capturing a variable, then the code compiles without error or relevant warning:
The text was updated successfully, but these errors were encountered: