Skip to content

Commit 577e76b

Browse files
committed
[move-only] Change closure capture diagnostic for let patterns to say that it cannot be captured by an escaping closure.
rdar://109742587
1 parent c3fbe24 commit 577e76b

File tree

6 files changed

+31
-30
lines changed

6 files changed

+31
-30
lines changed

include/swift/AST/DiagnosticsSIL.def

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -758,11 +758,10 @@ ERROR(sil_movechecking_value_used_after_consume, none,
758758
"'%0' used after consume", (StringRef))
759759
ERROR(sil_movechecking_guaranteed_value_consumed, none,
760760
"'%0' is borrowed and cannot be consumed", (StringRef))
761-
762-
// FIXME: this diagnostic shouldn't ever be emitted now. rdar://109742587 (closures may still try to consume captures, e.g., borrowed parameters)
763-
ERROR(sil_movechecking_guaranteed_value_captured_by_closure, none,
764-
"'%0' is borrowed and cannot be consumed by closure capture", (StringRef))
765-
761+
ERROR(sil_movechecking_borrowed_parameter_captured_by_closure, none,
762+
"'%0' cannot be captured by an escaping closure since it is a borrowed "
763+
"parameter",
764+
(StringRef))
766765
ERROR(sil_movechecking_capture_consumed, none,
767766
"noncopyable '%0' cannot be consumed when captured by a closure", (StringRef))
768767
ERROR(sil_movechecking_inout_not_reinitialized_before_end_of_function, none,

lib/SILOptimizer/Mandatory/MoveOnlyDiagnostics.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ void DiagnosticEmitter::emitObjectGuaranteedDiagnostic(
203203
// See if we have any closure capture uses and emit a better diagnostic.
204204
if (getCanonicalizer().hasPartialApplyConsumingUse()) {
205205
diagnose(astContext, markedValue,
206-
diag::sil_movechecking_guaranteed_value_captured_by_closure,
206+
diag::sil_movechecking_borrowed_parameter_captured_by_closure,
207207
varName);
208208
emitObjectDiagnosticsForPartialApplyUses(varName);
209209
registerDiagnosticEmitted(markedValue);

test/SILGen/moveonly_escaping_closure.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ struct SingleElt {
1313
}
1414

1515
func consumeVal(_ x: consuming SingleElt) {}
16+
func consumeVal(_ x: consuming Empty) {}
1617
func borrowVal(_ x: borrowing SingleElt) {}
1718
func borrowConsumeVal(_ x: borrowing SingleElt, _ y: consuming SingleElt) {}
1819

@@ -1339,7 +1340,7 @@ struct ClosureHolder {
13391340
}
13401341
}
13411342

1342-
func closureCoroutineAssignmentLetBorrowingArgument(_ e: borrowing Empty) { // expected-error {{'e' is borrowed and cannot be consumed by closure capture}}
1343+
func closureCoroutineAssignmentLetBorrowingArgument(_ e: borrowing Empty) { // expected-error {{'e' cannot be captured by an escaping closure since it is a borrowed parameter}}
13431344
let f: () -> () = { // expected-note {{closure capturing 'e' here}}
13441345
_ = e
13451346
}

test/SILOptimizer/moveonly_addresschecker_diagnostics.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3494,7 +3494,7 @@ public func closureVarAndDeferCaptureClassUseAfterConsume3(_ x: borrowing Klass)
34943494

34953495
public func closureVarAndDeferCaptureClassArgUseAfterConsume(_ x2: borrowing Klass) {
34963496
// expected-error @-1 {{noncopyable 'x2' cannot be consumed when captured by a closure}}
3497-
// expected-error @-2 {{'x2' is borrowed and cannot be consumed by closure capture}}
3497+
// expected-error @-2 {{'x2' cannot be captured by an escaping closure since it is a borrowed parameter}}
34983498
var f = {}
34993499
f = {// expected-note {{closure capturing 'x2' here}}
35003500
defer {
@@ -3636,8 +3636,8 @@ public func closureVarAndClosureCaptureClassUseAfterConsume3(_ x: borrowing Klas
36363636

36373637
public func closureVarAndClosureCaptureClassArgUseAfterConsume(_ x2: borrowing Klass) {
36383638
// expected-error @-1 {{noncopyable 'x2' cannot be consumed when captured by a closure}}
3639-
// expected-error @-2 {{'x2' is borrowed and cannot be consumed by closure capture}}
3640-
// expected-error @-3 {{'x2' is borrowed and cannot be consumed by closure capture}}
3639+
// expected-error @-2 {{'x2' cannot be captured by an escaping closure since it is a borrowed parameter}}
3640+
// expected-error @-3 {{'x2' cannot be captured by an escaping closure since it is a borrowed parameter}}
36413641
var f = {}
36423642
f = {// expected-note {{closure capturing 'x2' here}}
36433643
var g = {}

test/SILOptimizer/moveonly_objectchecker_diagnostics.swift

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2731,7 +2731,7 @@ public func enumPatternMatchSwitch2WhereClause2OwnedArg2(_ x2: consuming EnumTy)
27312731
/////////////////////////////
27322732

27332733
public func closureLetClassUseAfterConsume1(_ x: borrowing Klass) {
2734-
// expected-error @-1 {{'x' is borrowed and cannot be consumed}}
2734+
// expected-error @-1 {{'x' cannot be captured by an escaping closure since it is a borrowed parameter}}
27352735
// expected-error @-2 {{noncopyable 'x' cannot be consumed when captured by a closure}}
27362736
let f = { // expected-note {{closure capturing 'x' here}}
27372737
let x2 = x // expected-error {{'x2' consumed more than once}}
@@ -2830,7 +2830,7 @@ public func closureLetCaptureClassUseAfterConsumeError(_ x: borrowing Klass) { /
28302830

28312831
public func closureLetCaptureClassArgUseAfterConsume(_ x2: borrowing Klass) {
28322832
// expected-error @-1 {{noncopyable 'x2' cannot be consumed when captured by a closure}}
2833-
// expected-error @-2 {{'x2' is borrowed and cannot be consumed by closure capture}}
2833+
// expected-error @-2 {{'x2' cannot be captured by an escaping closure since it is a borrowed parameter}}
28342834
let f = { // expected-note {{closure capturing 'x2' here}}
28352835
borrowVal(x2)
28362836
consumeVal(x2) // expected-note {{consumed here}}
@@ -2897,7 +2897,7 @@ public func closureLetCaptureClassOwnedArgUseAfterConsume4(_ x2: consuming Klass
28972897
/////////////////////////////
28982898

28992899
public func closureVarClassUseAfterConsume1(_ x: borrowing Klass) {
2900-
// expected-error @-1 {{'x' is borrowed and cannot be consumed}}
2900+
// expected-error @-1 {{'x' cannot be captured by an escaping closure since it is a borrowed parameter}}
29012901
// expected-error @-2 {{noncopyable 'x' cannot be consumed when captured by a closure}}
29022902
var f = {}
29032903
f = { // expected-note {{closure capturing 'x' here}}
@@ -3007,7 +3007,7 @@ public func closureVarCaptureClassUseAfterConsumeError(_ x: borrowing Klass) { /
30073007

30083008
public func closureVarCaptureClassArgUseAfterConsume(_ x2: borrowing Klass) {
30093009
// expected-error @-1 {{noncopyable 'x2' cannot be consumed when captured by a closure}}
3010-
// expected-error @-2 {{'x2' is borrowed and cannot be consumed by closure capture}}
3010+
// expected-error @-2 {{'x2' cannot be captured by an escaping closure since it is a borrowed parameter}}
30113011
var f = {}
30123012
f = { // expected-note {{closure capturing 'x2' here}}
30133013
borrowVal(x2)
@@ -3206,7 +3206,7 @@ public func closureLetAndDeferCaptureClassUseAfterConsume3(_ x: borrowing Klass)
32063206

32073207
public func closureLetAndDeferCaptureClassArgUseAfterConsume(_ x2: borrowing Klass) {
32083208
// expected-error @-1 {{noncopyable 'x2' cannot be consumed when captured by a closure}}
3209-
// expected-error @-2 {{'x2' is borrowed and cannot be consumed by closure capture}}
3209+
// expected-error @-2 {{'x2' cannot be captured by an escaping closure since it is a borrowed parameter}}
32103210
let f = { // expected-note {{closure capturing 'x2' here}}
32113211
defer {
32123212
borrowVal(x2)
@@ -3343,8 +3343,8 @@ public func closureLetAndClosureCaptureClassUseAfterConsume3(_ x: borrowing Klas
33433343

33443344
public func closureLetAndClosureCaptureClassArgUseAfterConsume(_ x2: borrowing Klass) {
33453345
// expected-error @-1 {{noncopyable 'x2' cannot be consumed when captured by a closure}}
3346-
// expected-error @-2 {{'x2' is borrowed and cannot be consumed by closure capture}}
3347-
// expected-error @-3 {{'x2' is borrowed and cannot be consumed by closure capture}}
3346+
// expected-error @-2 {{'x2' cannot be captured by an escaping closure since it is a borrowed parameter}}
3347+
// expected-error @-3 {{'x2' cannot be captured by an escaping closure since it is a borrowed parameter}}
33483348
let f = { // expected-note {{closure capturing 'x2' here}}
33493349
let g = { // expected-note {{closure capturing 'x2' here}}
33503350
borrowVal(x2)
@@ -3490,7 +3490,7 @@ public func closureVarAndDeferCaptureClassUseAfterConsume3(_ x: borrowing Klass)
34903490

34913491
public func closureVarAndDeferCaptureClassArgUseAfterConsume(_ x2: borrowing Klass) {
34923492
// expected-error @-1 {{noncopyable 'x2' cannot be consumed when captured by a closure}}
3493-
// expected-error @-2 {{'x2' is borrowed and cannot be consumed by closure capture}}
3493+
// expected-error @-2 {{'x2' cannot be captured by an escaping closure since it is a borrowed parameter}}
34943494
var f = {}
34953495
f = {// expected-note {{closure capturing 'x2' here}}
34963496
defer {
@@ -3630,8 +3630,8 @@ public func closureVarAndClosureCaptureClassUseAfterConsume3(_ x: borrowing Klas
36303630

36313631
public func closureVarAndClosureCaptureClassArgUseAfterConsume(_ x2: borrowing Klass) {
36323632
// expected-error @-1 {{noncopyable 'x2' cannot be consumed when captured by a closure}}
3633-
// expected-error @-2 {{'x2' is borrowed and cannot be consumed by closure capture}}
3634-
// expected-error @-3 {{'x2' is borrowed and cannot be consumed by closure capture}}
3633+
// expected-error @-2 {{'x2' cannot be captured by an escaping closure since it is a borrowed parameter}}
3634+
// expected-error @-3 {{'x2' cannot be captured by an escaping closure since it is a borrowed parameter}}
36353635
var f = {}
36363636
f = {// expected-note {{closure capturing 'x2' here}}
36373637
var g = {}
@@ -3764,8 +3764,8 @@ public func closureVarAndClosureLetCaptureClassUseAfterConsume3(_ x: borrowing K
37643764

37653765
public func closureVarAndClosureLetCaptureClassArgUseAfterConsume(_ x2: borrowing Klass) {
37663766
// expected-error @-1 {{noncopyable 'x2' cannot be consumed when captured by a closure}}
3767-
// expected-error @-2 {{'x2' is borrowed and cannot be consumed by closure capture}}
3768-
// expected-error @-3 {{'x2' is borrowed and cannot be consumed by closure capture}}
3767+
// expected-error @-2 {{'x2' cannot be captured by an escaping closure since it is a borrowed parameter}}
3768+
// expected-error @-3 {{'x2' cannot be captured by an escaping closure since it is a borrowed parameter}}
37693769
var f = {}
37703770
f = {// expected-note {{closure capturing 'x2' here}}
37713771
let g = {// expected-note {{closure capturing 'x2' here}}
@@ -3893,8 +3893,8 @@ public func closureLetAndClosureVarCaptureClassUseAfterConsume3(_ x: borrowing K
38933893

38943894
public func closureLetAndClosureVarCaptureClassArgUseAfterConsume(_ x2: borrowing Klass) {
38953895
// expected-error @-1 {{noncopyable 'x2' cannot be consumed when captured by a closure}}
3896-
// expected-error @-2 {{'x2' is borrowed and cannot be consumed by closure capture}}
3897-
// expected-error @-3 {{'x2' is borrowed and cannot be consumed by closure capture}}
3896+
// expected-error @-2 {{'x2' cannot be captured by an escaping closure since it is a borrowed parameter}}
3897+
// expected-error @-3 {{'x2' cannot be captured by an escaping closure since it is a borrowed parameter}}
38983898
let f = {// expected-note {{closure capturing 'x2' here}}
38993899
var g = {}
39003900
g = {// expected-note {{closure capturing 'x2' here}}

test/SILOptimizer/moveonly_trivial_objectchecker_diagnostics.swift

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1728,7 +1728,7 @@ public func enumPatternMatchSwitch2WhereClause2OwnedArg2(_ x2: consuming EnumTy)
17281728

17291729
public func closureClassUseAfterConsume1(_ x: borrowing NonTrivialStruct) {
17301730
// expected-error @-1 {{noncopyable 'x' cannot be consumed when captured by a closure}}
1731-
// expected-error @-2 {{'x' is borrowed and cannot be consumed by closure capture}}
1731+
// expected-error @-2 {{'x' cannot be captured by an escaping closure since it is a borrowed parameter}}
17321732
let f = { // expected-note {{closure capturing 'x' here}}
17331733
let x2 = x // expected-error {{'x2' consumed more than once}}
17341734
// expected-note @-1 {{consumed here}}
@@ -1789,7 +1789,7 @@ public func closureCaptureClassUseAfterConsumeError(_ x: borrowing NonTrivialStr
17891789

17901790
public func closureCaptureClassArgUseAfterConsume(_ x2: borrowing NonTrivialStruct) {
17911791
// expected-error @-1 {{noncopyable 'x2' cannot be consumed when captured by a closure}}
1792-
// expected-error @-2 {{'x2' is borrowed and cannot be consumed by closure capture}}
1792+
// expected-error @-2 {{'x2' cannot be captured by an escaping closure since it is a borrowed parameter}}
17931793
let f = { // expected-note {{closure capturing 'x2' here}}
17941794
borrowVal(x2)
17951795
consumeVal(x2) // expected-note {{consumed here}}
@@ -1981,8 +1981,9 @@ public func closureAndDeferCaptureClassUseAfterConsume3(_ x: borrowing NonTrivia
19811981
consumeVal(x2)
19821982
}
19831983

1984-
public func closureAndDeferCaptureClassArgUseAfterConsume(_ x2: borrowing NonTrivialStruct) { // expected-error {{'x2' is borrowed and cannot be consumed}}
1985-
// expected-error @-1 {{noncopyable 'x2' cannot be consumed when captured by a closure}}
1984+
public func closureAndDeferCaptureClassArgUseAfterConsume(_ x2: borrowing NonTrivialStruct) {
1985+
// expected-error @-1 {{'x2' cannot be captured by an escaping closure since it is a borrowed parameter}}
1986+
// expected-error @-2 {{noncopyable 'x2' cannot be consumed when captured by a closure}}
19861987
let f = { // expected-note {{closure capturing 'x2' here}}
19871988
defer {
19881989
borrowVal(x2)
@@ -2086,8 +2087,8 @@ public func closureAndClosureCaptureClassUseAfterConsume2(_ x: borrowing NonTriv
20862087

20872088
public func closureAndClosureCaptureClassArgUseAfterConsume(_ x2: borrowing NonTrivialStruct) {
20882089
// expected-error @-1 {{noncopyable 'x2' cannot be consumed when captured by a closure}}
2089-
// expected-error @-2 {{'x2' is borrowed and cannot be consumed by closure capture}}
2090-
// expected-error @-3 {{'x2' is borrowed and cannot be consumed by closure capture}}
2090+
// expected-error @-2 {{'x2' cannot be captured by an escaping closure since it is a borrowed parameter}}
2091+
// expected-error @-3 {{'x2' cannot be captured by an escaping closure since it is a borrowed parameter}}
20912092
let f = { // expected-note {{closure capturing 'x2' here}}
20922093
let g = { // expected-note {{closure capturing 'x2' here}}
20932094
borrowVal(x2)

0 commit comments

Comments
 (0)