Skip to main content
Journey Uncommon Logo
JourneyUncommon
hardSwiftownership borrowing consumingSingle-choice MCQ

Consider a non-copyable struct (`~Copyable`) holding a file descriptor with a `deinit`. After it is passed to a `consuming` function, why is using the original binding afterward a compile-time error rather than a runtime crash?

struct FD: ~Copyable { let raw: Int32 deinit { close(raw) } } func takeOver(_ fd: consuming FD) { /* ... */ } let fd = FD(raw: open("/tmp/x", 0)) takeOver(fd) use(fd) // ?