@@ -484,6 +484,38 @@ struct TestInoutUnsafePointerExclusivity {
484484 }
485485}
486486
487+ // =============================================================================
488+ // Copied dependence on mutable values
489+ // =============================================================================
490+
491+ @_lifetime ( dest: copy source)
492+ func reassign< T: ~ Escapable> ( dest: inout T , source: T ) {
493+ dest = source
494+ }
495+
496+ @_lifetime ( span: borrow array)
497+ func testReassignToBorrowGood( span: inout Span < Int > , array: [ Int ] ) {
498+ reassign ( dest: & span, source: array. span ( ) )
499+ }
500+
501+ // Reassign from a local owned value
502+ @_lifetime ( span: copy span)
503+ func testReassignToLocal( span: inout Span < Int > ) { // expected-error{{lifetime-dependent variable 'span' escapes its scope}}
504+ let array = [ 1 , 2 ] // expected-note{{it depends on the lifetime of variable 'array'}}
505+ reassign ( dest: & span, source: array. span ( ) )
506+ } // expected-note{{this use causes the lifetime-dependent value to escape}}
507+
508+ @_lifetime ( span: copy span)
509+ func testReassignToConsuming( span: inout Span < Int > , array: consuming [ Int ] ) { // expected-error{{lifetime-dependent variable 'span' escapes its}}
510+ reassign ( dest: & span, source: array. span ( ) ) // expected-note{{it depends on this scoped access to variable 'array'}}
511+ } // expected-note{{this use causes the lifetime-dependent value to escape}}
512+
513+ @_lifetime ( span: copy span)
514+ func testReassignToBorrowBad( span: inout Span < Int > , array: [ Int ] ) { // expected-error{{lifetime-dependent variable 'span' escapes its scope}}
515+ // expected-note@-1{{it depends on the lifetime of argument 'array'}}
516+ reassign ( dest: & span, source: array. span ( ) )
517+ } // expected-note{{this use causes the lifetime-dependent value to escape}}
518+
487519// =============================================================================
488520// Scoped dependence on property access
489521// =============================================================================
0 commit comments