I've been working with non-copyable types lately, and noticed an odd difference in the way switch enumeration cases treat them vs. other places.
Pattern matching in control flow statements that aren't switch
statements seem to be implicit consumes of non-copyable enums:
enum NoncopyableEnum: ~Copyable {
case someValue
}
func doSomething(with enumValue: borrowing NoncopyableEnum) { // 'enumValue' is borrowed and cannot be consumed
if case .someValue = enumValue { // this triggers the above compiler error
// hello, hr?
}
}
whereas switch
statements aren't:
enum NoncopyableEnum: ~Copyable {
case someValue
}
func doSomething(with enumValue: borrowing NoncopyableEnum) {
switch enumValue {
case .someValue: break // aww you're so sweet
}
}
Am I missing something obvious as to why it's reasonable these two instances be treated differently, or is this a bug?