I have a type that provides a view into its storage using RawSpan
. Therefore, the view method has an @lifetime
annotation. Because I am interfacing with C, I need to at least save the method in a variable (or get a pointer to the method). However, my friend the compiler keeps telling me Lifetime-dependent value escapes its scope
-- which makes sense, I guess. Or is this a bug because the compiler thinks I am invoking the method?
struct A {
@lifetime(borrow self)
func giveMeAChunkOfData(at index: Int, point: Point) -> RawSpan {
fatalError()
}
}
func _parse(_ a: borrowing A) {
let fn = a.giveMeAChunkOfData(at:point:) // 🛑 Lifetime-dependent value escapes its scope
withUnsafePointer(to: a.giveMeAChunkOfData(at:point:)) { functionPointer in // 🛑 Lifetime-dependent value escapes its scope
}
}
A,
Are you prohibited from referencing functions with @lifetime
annotations?
B,
how do I temporarily get around the error (using the latest main snapshot)? I know this is unsafe, I would like to acknowledge that fact and still be able to take an address of said method. IRL, it is safe in my case.
Concerning B, I have tried some of the trickery in LifetimeManager.swift in the stdlib (_overrideLifetime
functions), even tried 'immortalizing' a
and/or giveMeAChunkOfData
this way, but no luck there.
cheers