@@ -241,6 +241,22 @@ func copySpan<T>(_ arg: Span<T>) -> /* */ Span<T> { arg }
241
241
@lifetime ( borrow arg)
242
242
func reborrowSpan< T> ( _ arg: Span < T > ) -> Span < T > { arg }
243
243
244
+ @lifetime ( & arg)
245
+ func reborrowGenericInout< T: ~ Escapable> ( _ arg: inout T ) -> T { arg }
246
+
247
+ @lifetime ( copy arg)
248
+ func inheritSpan< T> ( _ arg: Span < T > ) -> Span < T > { arg }
249
+
250
+ @lifetime ( copy arg)
251
+ func inheritGeneric< T: ~ Escapable> ( _ arg: consuming T ) -> T { arg }
252
+
253
+ public struct NE : ~ Escapable { }
254
+
255
+ @lifetime ( & ne)
256
+ func borrowNE< T: ~ Escapable> ( ne: inout T ) -> T {
257
+ ne
258
+ }
259
+
244
260
// =============================================================================
245
261
// Initialization
246
262
// =============================================================================
@@ -340,6 +356,30 @@ func testInheritedCopyVar(_ arg: [Int] ) {
340
356
parse ( result) // ✅ Safe: within lifetime of 'a'
341
357
}
342
358
359
+ @lifetime ( copy span)
360
+ public func testBorrowInheritedArg< T> ( _ span: Span < T > ) -> Span < T > {
361
+ reborrowSpan ( span) // expected-error {{lifetime-dependent value escapes its scope}}
362
+ // expected-note @-2{{it depends on the lifetime of argument 'span'}}
363
+ } // expected-note {{this use causes the lifetime-dependent value to escape}}
364
+
365
+ @lifetime ( copy t)
366
+ public func testBorrowInheritedInoutArg< T: ~ Escapable> ( _ t: inout T ) -> T {
367
+ // expected-error @-1{{lifetime-dependent variable 't' escapes its scope}}
368
+ // expected-note @-2{{it depends on the lifetime of argument 't'}}
369
+ reborrowGenericInout ( & t)
370
+ // expected-note @-1{{this use causes the lifetime-dependent value to escape}}
371
+ }
372
+
373
+ @lifetime ( copy span)
374
+ public func testCopyInheritedArg< T> ( _ span: Span < T > ) -> Span < T > {
375
+ inheritSpan ( span)
376
+ }
377
+
378
+ @lifetime ( copy t)
379
+ public func testCopyInheritedGenericArg< T: ~ Escapable> ( _ t: consuming T ) -> T {
380
+ inheritGeneric ( t)
381
+ }
382
+
343
383
// =============================================================================
344
384
// Scoped dependence on inherited dependence
345
385
// =============================================================================
@@ -364,6 +404,23 @@ func testScopedOfInheritedWithLet(_ arg: [Int] ) {
364
404
_ = result
365
405
} // expected-note {{this use of the lifetime-dependent value is out of scope}}
366
406
407
+ // Test a scoped dependence on an inherited inout argument.
408
+ //
409
+ // If testScopedOfInheritedWithLet is not an error, then its result can outlive its borrowed value:
410
+ // let ne1 = NE()
411
+ // var ne2 = ne1
412
+ // let dep = foo(ne: &ne2)
413
+ // _ = consume ne2
414
+ // _ = dep
415
+ //
416
+ @lifetime ( copy ne)
417
+ public func testScopedOfInheritedInout< T: ~ Escapable> ( ne: inout T ) -> T {
418
+ // expected-error @-1{{lifetime-dependent variable 'ne' escapes its scope}}
419
+ // expected-note @-2{{it depends on the lifetime of argument 'ne'}}
420
+ borrowNE ( ne: & ne)
421
+ // expected-note @-1{{this use causes the lifetime-dependent value to escape}}
422
+ }
423
+
367
424
// =============================================================================
368
425
// Scoped dependence on trivial values
369
426
// =============================================================================
0 commit comments