Deleted
Would it work to change popFirst to return a sending value? I doubt it because RBI can only merge regions not split regions. An example:
class NonSendable {}
struct MyContainer {
var item: NonSendable?
mutating func getAndSend() -> sending NonSendable? {
guard let item else { return nil }
self.item = nil
return item // error: sending 'item.some' risks causing data races
}
}
The proposed Disconnected wrapper works because it's Sendable.
EDIT: I saw you mentioned requirements like consuming the element in append, but I don’t think that alone is sufficient. Containers in pratical code have much larger API surfaces than Disconnected, making them hard to get right. I actually think it’s impossible to get them working without Disconnected, because there are no way to prove to compiler that different elements in a container don't reference to each other (please correct me if I’m wrong). That’s why I don’t agree with @Dmitriy_Ignatyev. Disconnected is the only approach that works in some scenarios. On the other hand it’s unknown how long we would need to wait for a similar language feature. Regarding concerns about boilerplate code, it can be hided from user. See an example in this post.
Sorry, I just realized that it's always possible to use nonisolated(unsafe) if one is sure it doesn't cause problem. IMO using Disconnected wrapper is much safer than using nonisolated(unsafe) in ad-hoc way. +1 from me.