i don't have much 'real world' experience with noncopyable types, so i may be off here, but i think if you can tolerate the use of underscored (yet longstanding) stdlib APIs, or experimental features, then this can perhaps be achieved by use of the _read
/read
coroutine accessor.
e.g. if i modify your code as so:
struct B: ~Copyable {
let stored = A()
var computed: A {
_read { yield A() }
}
}
then i get the error:
13 | func hello(b: borrowing B) {
14 | let y = b.stored // disallowed: 'b' is borrowed and cannot be consumed
15 | let z = b.computed // allowed
| |- error: 'b.computed' is borrowed and cannot be consumed
| `- note: consumed here
16 | }
17 |