Skip to content

Borrowed Tuple Elements Cause Consumption Error #74346

@minacle

Description

@minacle

Description

When a tuple is borrowed, using individual elements of the tuple causes a compiler error indicating that the tuple is borrowed and cannot be consumed. This error occurs even though the tuple itself is not directly used, only its elements are accessed. This seems to be a bug, as borrowing should allow the access of individual elements without consuming the entire tuple.

Reproduction

func f(tuple: borrowing (Int, Int)) {
    let x = tuple.0
    let y = tuple.1
    print("\(x), \(y)")
}

This code snippet results in the compiler error:

'tuple' is borrowed and cannot be consumed

Expected behavior

The individual elements of the borrowed tuple should be accessible without causing a compiler error. The tuple itself is not being consumed, only its elements are being accessed, so the borrow should be valid.

Environment

Xcode 16.0 beta (16A5171c) ← Swift 6.0 (6.0.0.3.300)

swift-driver version: 1.109.2 Apple Swift version 6.0 (swiftlang-6.0.0.3.300 clang-1600.0.20.10)
Target: arm64-apple-macosx14.0

Xcode 16.0 beta 2 (16A5171r) ← Swift 6.0 (6.0.0.4.52)

swift-driver version: 1.110 Apple Swift version 6.0 (swiftlang-6.0.0.4.52 clang-1600.0.21.1.3)
Target: arm64-apple-macosx14.0

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.ownershipFeature: Ownership modifiers and semantics

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions