You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/ReferenceGuides/LifetimeAnnotation.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -18,7 +18,7 @@ The `@lifetime` annotation is enforced both in the body of the function and at e
18
18
19
19
## Default lifetimes
20
20
21
-
The Swift 6.2 compiler provided default `@_lifetime` behavior whenever it can do so without ambiguity. Often, despite ambiguity, an "obvious" default exists, but we wanted to introduce defaults slowly after developers have enough experience to inform discussion about them. This document tracks the current state of the implementation as it progresses from the original 6.2 implementation. Corresponding tests are in `test/Sema/lifetime_depend_infer.swift`; searching for "DEFAULT:" highlights the rules defined below...
21
+
The Swift 6.2 compiler provided default `@_lifetime` behavior whenever it can do so without ambiguity. Often, despite ambiguity, an obvious default exists, but we wanted to introduce defaults slowly after developers have enough experience to inform discussion about them. This document tracks the current state of the implementation as it progresses from the original 6.2 implementation. Corresponding tests are in `test/Sema/lifetime_depend_infer.swift`; searching for "DEFAULT:" highlights the rules defined below...
@_lifetime // expected-error{{expected '(' after lifetime dependence specifier}}
23
-
func testMissingLParenError(_ ne:NE)->NE{ // expected-error{{cannot infer the lifetime dependence scope on a function with a ~Escapable parameter, specify '@_lifetime(borrow ne)' or '@_lifetime(copy ne)'}}
23
+
func testMissingLParenError(_ ne:NE)->NE{
24
24
ne
25
25
}
26
26
27
27
@_lifetime() // expected-error{{expected 'copy', 'borrow', or '&' followed by an identifier, index or 'self' in lifetime dependence specifier}}
28
-
func testMissingDependence(_ ne:NE)->NE{ // expected-error{{cannot infer the lifetime dependence scope on a function with a ~Escapable parameter, specify '@_lifetime(borrow ne)' or '@_lifetime(copy ne)'}}
func sameTypeConsumingParam(ne:consumingNE)->NE{ ne }
31
+
32
+
func sameTypeBorrowingParam(ne:borrowingNE)->NE{ ne }
33
+
34
+
func sameTypeInoutParam(ne:inoutNE)->NE{ ne } // expected-error{{cannot infer the lifetime dependence scope on a function with a ~Escapable parameter, specify '@_lifetime(borrow ne)' or '@_lifetime(copy ne)'}}
func twoParamsInout_NEResult(c:inoutC, _:Int)->NEImmortal{NEImmortal()} // expected-error{{a function with a ~Escapable result requires '@_lifetime(...)'}}
73
107
74
-
func neParam_NEResult(ne:NE)->NE{ ne } // expected-error{{cannot infer the lifetime dependence scope on a function with a ~Escapable parameter, specify '@_lifetime(borrow ne)' or '@_lifetime(copy ne)'}}
108
+
func neParam_NEResult(ne:NE)->NE{ ne }
75
109
76
110
@_lifetime(ne) // expected-error{{cannot infer the lifetime dependence scope on a function with a ~Escapable parameter, specify '@_lifetime(borrow ne)' or '@_lifetime(copy ne)'}}
77
111
func neParamLifetime_NEResult(ne:NE)->NE{ ne }
78
112
79
-
func neParamBorrow_NEResult(ne:borrowingNE)->NE{ ne } // expected-error{{cannot infer the lifetime dependence scope on a function with a ~Escapable parameter, specify '@_lifetime(borrow ne)' or '@_lifetime(copy ne)'}}
113
+
func neParamBorrow_NEResult(ne:borrowingNE)->NE{ ne }
80
114
81
115
@_lifetime(ne) // expected-error{{cannot infer the lifetime dependence scope on a function with a ~Escapable parameter, specify '@_lifetime(borrow ne)' or '@_lifetime(copy ne)'}}
82
116
func neParamBorrowLifetime_NEResult(ne:borrowingNE)->NE{ ne }
83
117
84
-
func neParamConsume_NEResult(ne:consumingNE)->NE{ ne } // expected-error{{cannot infer the lifetime dependence scope on a function with a ~Escapable parameter, specify '@_lifetime(borrow ne)' or '@_lifetime(copy ne)'}}
118
+
func neParamConsume_NEResult(ne:consumingNE)->NE{ ne }
85
119
86
120
@_lifetime(ne) // expected-error{{cannot infer the lifetime dependence scope on a function with a ~Escapable parameter, specify '@_lifetime(borrow ne)' or '@_lifetime(copy ne)'}}
87
121
func neParamConsumeLifetime_NEResult(ne:consumingNE)->NE{ ne }
88
122
89
-
func neParam_IntParam_NEResult(ne:NE, _:Int)->NE{ ne } // expected-error{{a function with a ~Escapable result requires '@_lifetime(...)'}}
123
+
func neParam_IntParam_NEResult(ne:NE, _:Int)->NE{ ne }
func noParam_NEResult()->NonEscapableSelf{self} // expected-error{{cannot infer the lifetime dependence scope on a method with a ~Escapable parameter, specify '@_lifetime(borrow self)' or '@_lifetime(copy self)'}}
238
+
extensionNonEscapableSelf /* where Self: ~Escapable */{
239
+
func noParam_NEResult()->NonEscapableSelf{self}
206
240
207
241
@_lifetime(self) // expected-error{{cannot infer the lifetime dependence scope on a method with a ~Escapable parameter, specify '@_lifetime(borrow self)' or '@_lifetime(copy self)'}}
@_lifetime(self) // expected-error{{cannot infer the lifetime dependence scope on a method with a ~Escapable parameter, specify '@_lifetime(borrow self)' or '@_lifetime(copy self)'}}
func inoutParam_inoutNEParam_void(_:inoutNE, _:inoutNE){} // OK
265
299
300
+
266
301
func inoutNEParam_NEResult(ne:inoutNE)->NE{ ne } // expected-error{{cannot infer the lifetime dependence scope on a function with a ~Escapable parameter, specify '@_lifetime(borrow ne)' or '@_lifetime(copy ne)'}}
Copy file name to clipboardExpand all lines: test/Sema/lifetime_depend_noattr.swift
+3-3Lines changed: 3 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -13,18 +13,18 @@
13
13
structEmptyNonEscapable:~Escapable {} // OK - no dependence
14
14
15
15
// Don't allow non-Escapable return values.
16
-
func neReturn(span:RawSpan)->RawSpan{ span } // expected-error{{cannot infer the lifetime dependence scope on a function with a ~Escapable parameter, specify '@_lifetime(borrow span)' or '@_lifetime(copy span)'}}
16
+
func neReturn(span:RawSpan)->RawSpan{ span }
17
17
18
18
func neInout(span:inoutRawSpan){} // OK - inferred
19
19
20
20
structS{
21
-
func neReturn(span:RawSpan)->RawSpan{ span } // expected-error{{a method with a ~Escapable result requires '@_lifetime(...)}}
21
+
func neReturn(span:RawSpan)->RawSpan{ span }
22
22
23
23
func neInout(span:inoutRawSpan){} // OK - inferred
24
24
}
25
25
26
26
classC{
27
-
func neReturn(span:RawSpan)->RawSpan{ span } // expected-error{{a method with a ~Escapable result requires '@_lifetime(...)'}}
27
+
func neReturn(span:RawSpan)->RawSpan{ span }
28
28
29
29
func neInout(span:inoutRawSpan){} // OK - inferred
0 commit comments