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
[move-only-object] Use closureCapture to emit more informative diagnostic on lets being captured in a closure.
Specifically, previously we said something along the lines of...
'x' has guaranteed ownership but was consumed
even for lets. This is pretty misleading. Using @closureCapture, we can now emit
a much better diagnostic:
'x' consumed in closure. This is illegal since if the closure is invoked more than once the binding will be uninitialized on later invocations.
I am also going to use this technique to emit a similar diagnostic for vars that
are captured by a closure. It will be slightly different since vars will behave
like inout parameters.
"'%0' consumed in closure. This is illegal since if the closure is invoked more than once the binding will be uninitialized on later invocations", (StringRef))
// expected-error @-1 {{'x' has guaranteed ownership but was consumed}}
2051
-
// expected-error @-2 {{'x' has guaranteed ownership but was consumed due to being captured by a closure}}
2051
+
// expected-error @-2 {{'x' consumed in closure. This is illegal since if the closure is invoked more than once the binding will be uninitialized on later invocations}}
2052
2052
letf={ // expected-note {{closure capture}}
2053
2053
letx2= x // expected-error {{'x2' consumed more than once}}
2054
2054
// expected-note @-1 {{consuming use}}
@@ -2082,7 +2082,7 @@ public func closureClassUseAfterConsumeArg(_ argX: Klass) {
2082
2082
2083
2083
publicfunc closureCaptureClassUseAfterConsume(_ x:Klass){ // expected-error {{'x' has guaranteed ownership but was consumed}}
2084
2084
letx2= x // expected-note {{consuming use}}
2085
-
// expected-error @-1 {{'x2' has guaranteed ownership but was consumed}}
2085
+
// expected-error @-1 {{'x2' consumed in closure. This is illegal since if the closure is invoked more than once the binding will be uninitialized on later invocations}}
publicfunc closureCaptureClassUseAfterConsumeError(_ x:Klass){ // expected-error {{'x' has guaranteed ownership but was consumed}}
2095
2095
letx2= x
2096
2096
// expected-error @-1 {{'x2' consumed more than once}}
2097
-
// expected-error @-2 {{'x2' has guaranteed ownership but was consumed}}
2097
+
// expected-error @-2 {{'x2' consumed in closure. This is illegal since if the closure is invoked more than once the binding will be uninitialized on later invocations}}
// expected-error @-1 {{'x2' has guaranteed ownership but was consumed}}
2110
+
// expected-error @-1 {{'x2' consumed in closure. This is illegal since if the closure is invoked more than once the binding will be uninitialized on later invocations}}
2111
2111
// expected-error @-2 {{'x2' has guaranteed ownership but was consumed due to being captured by a closure}}
2112
2112
letf={ // expected-note {{closure capture}}
2113
2113
classUseMoveOnlyWithoutEscaping(x2)
@@ -2118,7 +2118,7 @@ public func closureCaptureClassArgUseAfterConsume(_ x2: Klass) {
// expected-error @-1 {{'x2' has guaranteed ownership but was consumed}}
2121
+
// expected-error @-1 {{'x2' consumed in closure. This is illegal since if the closure is invoked more than once the binding will be uninitialized on later invocations}}
// expected-error @-1 {{'x2' consumed more than once}}
2132
-
// expected-error @-2 {{'x2' has guaranteed ownership but was consumed}}
2132
+
// expected-error @-2 {{'x2' consumed in closure. This is illegal since if the closure is invoked more than once the binding will be uninitialized on later invocations}}
publicfunc deferCaptureClassUseAfterConsume(_ x:Klass){ // expected-error {{'x' has guaranteed ownership but was consumed}}
2144
2144
letx2= x // expected-note {{consuming use}}
2145
-
// expected-error @-1 {{'x2' has guaranteed ownership but was consumed}}
2145
+
// expected-error @-1 {{'x2' consumed in closure. This is illegal since if the closure is invoked more than once the binding will be uninitialized on later invocations}}
publicfunc deferCaptureClassUseAfterConsume2(_ x:Klass){ // expected-error {{'x' has guaranteed ownership but was consumed}}
2155
2155
letx2= x // expected-error {{'x2' consumed more than once}}
2156
2156
// expected-note @-1 {{consuming use}}
2157
-
// expected-error @-2 {{'x2' has guaranteed ownership but was consumed}}
2157
+
// expected-error @-2 {{'x2' consumed in closure. This is illegal since if the closure is invoked more than once the binding will be uninitialized on later invocations}}
// expected-error @-1 {{'x2' has guaranteed ownership but was consumed}}
2168
+
// expected-error @-1 {{'x2' consumed in closure. This is illegal since if the closure is invoked more than once the binding will be uninitialized on later invocations}}
2169
2169
classUseMoveOnlyWithoutEscaping(x2)
2170
2170
defer{
2171
2171
classUseMoveOnlyWithoutEscaping(x2)
@@ -2176,7 +2176,7 @@ public func deferCaptureClassArgUseAfterConsume(_ x2: Klass) {
// expected-error @-1 {{'x2' has guaranteed ownership but was consumed}}
2179
+
// expected-error @-1 {{'x2' consumed in closure. This is illegal since if the closure is invoked more than once the binding will be uninitialized on later invocations}}
// expected-error @-1 {{'x2' consumed more than once}}
2190
-
// expected-error @-2 {{'x2' has guaranteed ownership but was consumed}}
2190
+
// expected-error @-2 {{'x2' consumed in closure. This is illegal since if the closure is invoked more than once the binding will be uninitialized on later invocations}}
publicfunc closureAndDeferCaptureClassUseAfterConsume(_ x:Klass){ // expected-error {{'x' has guaranteed ownership but was consumed}}
2200
2200
letx2= x // expected-note {{consuming use}}
2201
-
// expected-error @-1 {{'x2' has guaranteed ownership but was consumed}}
2201
+
// expected-error @-1 {{'x2' consumed in closure. This is illegal since if the closure is invoked more than once the binding will be uninitialized on later invocations}}
publicfunc closureAndDeferCaptureClassUseAfterConsume2(_ x:Klass){ // expected-error {{'x' has guaranteed ownership but was consumed}}
2214
2214
letx2= x // expected-note {{consuming use}}
2215
-
// expected-error @-1 {{'x2' has guaranteed ownership but was consumed}}
2216
-
// expected-error @-2 {{'x2' has guaranteed ownership but was consumed}}
2215
+
// expected-error @-1 {{'x2' consumed in closure. This is illegal since if the closure is invoked more than once the binding will be uninitialized on later invocations}}
2216
+
// expected-error @-2 {{'x2' consumed in closure. This is illegal since if the closure is invoked more than once the binding will be uninitialized on later invocations}}
publicfunc closureAndDeferCaptureClassUseAfterConsume3(_ x:Klass){ // expected-error {{'x' has guaranteed ownership but was consumed}}
2230
2230
letx2= x // expected-error {{'x2' consumed more than once}}
2231
2231
// expected-note @-1 {{consuming use}}
2232
-
// expected-error @-2 {{'x2' has guaranteed ownership but was consumed}}
2233
-
// expected-error @-3 {{'x2' has guaranteed ownership but was consumed}}
2232
+
// expected-error @-2 {{'x2' consumed in closure. This is illegal since if the closure is invoked more than once the binding will be uninitialized on later invocations}}
2233
+
// expected-error @-3 {{'x2' consumed in closure. This is illegal since if the closure is invoked more than once the binding will be uninitialized on later invocations}}
// expected-error @-1 {{'x2' has guaranteed ownership but was consumed}}
2248
+
// expected-error @-1 {{'x2' consumed in closure. This is illegal since if the closure is invoked more than once the binding will be uninitialized on later invocations}}
2249
2249
// expected-error @-2 {{'x2' has guaranteed ownership but was consumed due to being captured by a closure}}
2250
2250
letf={ // expected-note {{closure capture}}
2251
2251
defer{
@@ -2259,7 +2259,7 @@ public func closureAndDeferCaptureClassArgUseAfterConsume(_ x2: Klass) {
// expected-error @-1 {{'x2' has guaranteed ownership but was consumed}}
2262
+
// expected-error @-1 {{'x2' consumed in closure. This is illegal since if the closure is invoked more than once the binding will be uninitialized on later invocations}}
2263
2263
letf={
2264
2264
defer{
2265
2265
classUseMoveOnlyWithoutEscaping(x2)
@@ -2273,7 +2273,7 @@ public func closureAndDeferCaptureClassOwnedArgUseAfterConsume(_ x2: __owned Kla
// expected-error @-1 {{'x2' consumed more than once}}
2276
-
// expected-error @-2 {{'x2' has guaranteed ownership but was consumed}}
2276
+
// expected-error @-2 {{'x2' consumed in closure. This is illegal since if the closure is invoked more than once the binding will be uninitialized on later invocations}}
2277
2277
letf={ // expected-note {{consuming use}}
2278
2278
defer{
2279
2279
classUseMoveOnlyWithoutEscaping(x2)
@@ -2288,7 +2288,7 @@ public func closureAndDeferCaptureClassOwnedArgUseAfterConsume2(_ x2: __owned Kl
2288
2288
2289
2289
publicfunc closureAndClosureCaptureClassUseAfterConsume(_ x:Klass){ // expected-error {{'x' has guaranteed ownership but was consumed}}
2290
2290
letx2= x // expected-note {{consuming use}}
2291
-
// expected-error @-1 {{'x2' has guaranteed ownership but was consumed}}
2291
+
// expected-error @-1 {{'x2' consumed in closure. This is illegal since if the closure is invoked more than once the binding will be uninitialized on later invocations}}
2292
2292
// expected-error @-2 {{'x2' has guaranteed ownership but was consumed due to being captured by a closure}}
publicfunc closureAndClosureCaptureClassUseAfterConsume2(_ x:Klass){ // expected-error {{'x' has guaranteed ownership but was consumed}}
2305
2305
letx2= x // expected-error {{'x2' consumed more than once}}
2306
2306
// expected-note @-1 {{consuming use}}
2307
-
// expected-error @-2 {{'x2' has guaranteed ownership but was consumed}}
2307
+
// expected-error @-2 {{'x2' consumed in closure. This is illegal since if the closure is invoked more than once the binding will be uninitialized on later invocations}}
2308
2308
// expected-error @-3 {{'x2' has guaranteed ownership but was consumed due to being captured by a closure}}
// expected-error @-1 {{'x2' has guaranteed ownership but was consumed}}
2323
+
// expected-error @-1 {{'x2' consumed in closure. This is illegal since if the closure is invoked more than once the binding will be uninitialized on later invocations}}
2324
2324
// expected-error @-2 {{'x2' has guaranteed ownership but was consumed due to being captured by a closure}}
2325
2325
// expected-error @-3 {{'x2' has guaranteed ownership but was consumed due to being captured by a closure}}
2326
2326
letf={ // expected-note {{closure capture}}
@@ -2335,7 +2335,7 @@ public func closureAndClosureCaptureClassArgUseAfterConsume(_ x2: Klass) {
// expected-error @-1 {{'x2' has guaranteed ownership but was consumed}}
2338
+
// expected-error @-1 {{'x2' consumed in closure. This is illegal since if the closure is invoked more than once the binding will be uninitialized on later invocations}}
2339
2339
// expected-error @-2 {{'x2' has guaranteed ownership but was consumed due to being captured by a closure}}
2340
2340
letf={
2341
2341
letg={ // expected-note {{closure capture}}
@@ -2350,7 +2350,7 @@ public func closureAndClosureCaptureClassOwnedArgUseAfterConsume(_ x2: __owned K
// expected-error @-1 {{'x2' consumed more than once}}
2353
-
// expected-error @-2 {{'x2' has guaranteed ownership but was consumed}}
2353
+
// expected-error @-2 {{'x2' consumed in closure. This is illegal since if the closure is invoked more than once the binding will be uninitialized on later invocations}}
2354
2354
// expected-error @-3 {{'x2' has guaranteed ownership but was consumed due to being captured by a closure}}
0 commit comments