[Second review] SE-0390: Noncopyable structs and enums

And how would you apply these in a constraint context, like enum Optional<Wrapped: ~Copyable>? As a constraint, it’s inherently negative, since both copyable and non-copyable types can be used here.

I only parsed a tiny fraction of this conversation. But if the prefix operator is too terse and anything else is too long, how about an alternative solution via a proper type alias?

@suppress_attribute
public typealias NonCopyable = Copyable

struct Foo: NonCopyable {}

We can always adjust the aliased name to fit the protocol it tries to suppress and the actual marker could be a properly named attribute.

It's simple, easy to search and parse.

this just sounds like “@noncopyable as a protocol” but with more steps…

Well if we move the attribute in front of the protocol then you can decide if you want to use the attribute directly or via a type alias.

typealias NonCopyable = @attribute Copyable

struct Foo: NonCopyable {}
struct Bar: @attribute Copyable {} // verbose

It's a bit inspired by @escaping and @autoclosure in terms of attribute position.

I’m pretty sure this exists as _fixLifetime or something like that, and then withExtendedLifetime is just defer { _fixLifetime(x) }; return try body(). Of course, as indicated by the underscore on its name, _fixLifetime isn’t meant to be used in general (though it’s not clear to me why).

This proposal has been accepted with minor modifications.

Thank you to everyone who participated in this review.

Steve Canon
Review Manager

4 Likes