Fix LifetimeDependence feature guard for variable accessors.

Guard variable declarations by `#if $LifetimeDependence` if they have a
~Escapable type. Accessing the declaration implies a lifetime dependence.
This commit is contained in:
Andrew Trick
2025-01-14 15:34:32 -08:00
parent 9f1d727322
commit 0e33dfc8b6
3 changed files with 34 additions and 5 deletions

View File

@@ -54,3 +54,24 @@ public func deriveThisOrThat(_ this: consuming BufferView, _ that: consuming Buf
return BufferView(that._ptr, that._count)
}
@_unsafeNonescapableResult
@_transparent
@lifetime(borrow source)
internal func _overrideLifetime<T: ~Copyable & ~Escapable, U: ~Copyable & ~Escapable>(
_ dependent: consuming T, borrowing source: borrowing U) -> T {
dependent
}
public struct Container {
var buffer: UnsafeRawBufferPointer
var object: AnyObject
}
extension Container {
public var storage: BufferView {
get {
let view = BufferView(buffer, 1)
return _overrideLifetime(view, borrowing: self)
}
}
}