Skip to content

Unwarranted unsafe optional unwrap in MutableSpan implementation #82829

Closed
@glessard

Description

@glessard

Description

In https://forums.swift.org/t/80854/4, @benrimmington asked an implementation question:

I'm not sure what happens to _start() when the span is empty.

extension MutableSpan where Element: ~Copyable {
  @lifetime(&self)
  mutating public func extracting(_: UnboundedRange) -> Self {
    let newSpan = unsafe Self(_unchecked: _start(), count: _count)
    return unsafe _overrideLifetime(newSpan, mutating: &self)
  }
}

The answer is probably nothing good. This is an error in the implementation.

Expected behavior

There shouldn't be an unsafe unwrap in this code path.

Environment

swift-DEVELOPMENT-SNAPSHOT-2025-06-22-a

Additional information

Also tracked in rdar://155198823

Metadata

Metadata

Assignees

Labels

bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.standard libraryArea: Standard library umbrella

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions