let u = Foo ()
print (type (of: u))
// error: Metatype 'Foo.Type' cannot be cast to 'Any' because 'Foo' is noncopyable
print("\(type (of: u))")
// error: Noncopyable type 'Foo' cannot be erased to copyable existential type 'Any'
I was expecting it to be able to take ~Copyable things, but it doesn't.
According to proposal that has introduced noncopyable types, that is currently not allowed by the language:
At this time, as noted above, generic types are still always required to beCopyable, so noncopyable types themselves are not allowed to be used as a generic type argument. This means a noncopyable type cannot:
conform to any protocols, except for Sendable.
serve as a type witness for an associatedtype requirement.
be used as a type argument when instantiating generic types or calling generic functions.
be cast to (or from) Any or any other existential.
be accessed through reflection.
appear in a tuple.
I suppose that would be possible with SE-0427 that introduces noncopyable generics.
The nice thing about type(of:) is that it can be written naturally without any internal black magic. This makes it easy to write your own overload that takes non-copyable types.