I am currently exploring some uses cases for ~Copyable
types. I think a rather simple example is this:
struct NC: ~Copyable {}
func fn(closure: (consuming NC) -> Void) {
let nc = NC()
closure(nc)
}
struct Consumer {
init(_: consuming NC) {}
}
At call site, I would have assumed that it should look like this:
fn { nc in
_ = Consumer(nc)
}
However, the compiler tells me: 'nc' is borrowed and cannot be consumed
. It is not borrowed, since I specified the closure argument as consuming
, right?
A temporary workaround was this:
fn { (nc: consuming NC) in
_ = Consumer(nc)
}
To me this seems like a bug, however I want to verify that I am not missing anything. Would someone mind to clarify? I could not find anything about this in the pitch and nothing really similar in the forums.