Closed
Description
Given the following code:
fn fmt(it: &(std::cell::Cell<Option<impl FnOnce()>>,)) {
(it.0.take())()
}
The current output is:
error[E0618]: expected function, found enum variant `(it.0.take())`
--> src/lib.rs:22:5
|
22 | (it.0.take())()
| ^^^^^^^^^^^^^--
| |
| call expression requires function
|
help: `(it.0.take())` is a unit variant, you need to write it without the parentheses
|
22 - (it.0.take())()
22 + (it.0.take())
|
- It classifies the complex expression
(it.0.take())
as a (unit) enum variant in both the message and the note which is obviously incorrect. - It does not mention anywhere that the expression is of type
Option<_>
which would've been really helpful. Looking at the current output, it's really hard to see why the expression is not callable.
( As an aside, one actual fix for the given code is the following: it.0.take().unwrap()()
)
Link to the playground containing the reproducer, an even smaller reproducer and the original code for context.
I decided to select the slightly larger reproducer (containing the 1-tuple) for this issue instead of the smaller one from the playground (which can probably still be shrunk further) to really highlight the complex expression: (it.0.take())
over just it.take()
.
Reproduces on stable and on nightly.
@rustbot label C-bug D-incorrect D-confusing