SE-0427: Noncopyable Generics

I want to point out something stupid that should still be valid:

struct X: ~Copyable {}
extension X: Copyable {}

With this code, X is Copyable. This demonstrates that ~Copyable does not mean "unconditionally non-copyable" when applied to a non-generic type. It really does mean "suppress Copyable" or "don't include an implicit conformance to Copyable" here.

This example is silly when written like this, but I could see it being reasonable for macro-generated declarations* that work on both generic and non-generic types. (Rust has run into that kind of thing, though their macros are much less constrained than Swift's are.)

* when macros support generating declarations and extensions at the same time, can't remember if they do yet

9 Likes