@@ -2072,9 +2072,8 @@ static void diagnoseImplicitSelfUseInClosure(const Expr *E,
2072
2072
2073
2073
// If the closure's type was inferred to be noescape, then it doesn't
2074
2074
// need qualification.
2075
- if (auto funcTy = CE->getType ()->getAs <FunctionType>()) {
2076
- if (funcTy->isNoEscape ())
2077
- return false ;
2075
+ if (isNonEscaping (CE)) {
2076
+ return false ;
2078
2077
}
2079
2078
2080
2079
if (auto autoclosure = dyn_cast<AutoClosureExpr>(CE)) {
@@ -2092,6 +2091,14 @@ static void diagnoseImplicitSelfUseInClosure(const Expr *E,
2092
2091
return true ;
2093
2092
}
2094
2093
2094
+ static bool isNonEscaping (const AbstractClosureExpr *ACE) {
2095
+ if (auto funcTy = ACE->getType ()->getAs <FunctionType>()) {
2096
+ return funcTy->isNoEscape ();
2097
+ }
2098
+
2099
+ return false ;
2100
+ }
2101
+
2095
2102
// / The closure that is a parent of this closure, if present
2096
2103
static const ClosureExpr *
2097
2104
parentClosure (const AbstractClosureExpr *closure) {
@@ -2411,8 +2418,7 @@ static void diagnoseImplicitSelfUseInClosure(const Expr *E,
2411
2418
2412
2419
// Implicit self was permitted for weak self captures in
2413
2420
// non-escaping closures in Swift 5.7, so we must only warn.
2414
- if (AnyFunctionRef (const_cast <AbstractClosureExpr *>(ACE))
2415
- .isKnownNoEscape ()) {
2421
+ if (isNonEscaping (ACE)) {
2416
2422
return true ;
2417
2423
}
2418
2424
@@ -2474,8 +2480,7 @@ static void diagnoseImplicitSelfUseInClosure(const Expr *E,
2474
2480
// }
2475
2481
//
2476
2482
bool isEscapingClosureWithExplicitSelfCapture = false ;
2477
- if (!AnyFunctionRef (const_cast <AbstractClosureExpr *>(ACE))
2478
- .isKnownNoEscape ()) {
2483
+ if (!isNonEscaping (ACE)) {
2479
2484
if (auto closureExpr = dyn_cast<ClosureExpr>(ACE)) {
2480
2485
if (closureExpr->getCapturedSelfDecl ()) {
2481
2486
isEscapingClosureWithExplicitSelfCapture = true ;
0 commit comments