here’s something i really thought should be a straightforward composition of noncopyable types, where one buffer is temporarily rebound to another abstraction to avoid copy-on-write:
struct ExampleContext: ~Copyable {
var buffer: [Int]
}
struct ExampleState: ~Copyable {
let buffer: [Int]
}
extension ExampleState {
var context: ExampleContext {
get {
.init(buffer: self.buffer)
}
_modify {
var context: ExampleContext = (consume self).context
defer {
self = .init(buffer: context.buffer)
}
yield &context
}
}
}
error: 'self' used after consume
13 | .init(buffer: self.buffer)
14 | }
15 | _modify {
| `- error: 'self' used after consume
16 | var context: ExampleContext = (consume self).context
| `- note: consumed here
17 | defer {
| `- note: used here
18 | self = .init(buffer: context.buffer)
19 | }
what am i doing wrong here?