@@ -2072,9 +2072,8 @@ static void diagnoseImplicitSelfUseInClosure(const Expr *E,
20722072
20732073 // If the closure's type was inferred to be noescape, then it doesn't
20742074 // need qualification.
2075- if (auto funcTy = CE->getType ()->getAs <FunctionType>()) {
2076- if (funcTy->isNoEscape ())
2077- return false ;
2075+ if (isNonEscaping (CE)) {
2076+ return false ;
20782077 }
20792078
20802079 if (auto autoclosure = dyn_cast<AutoClosureExpr>(CE)) {
@@ -2092,6 +2091,14 @@ static void diagnoseImplicitSelfUseInClosure(const Expr *E,
20922091 return true ;
20932092 }
20942093
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+
20952102 // / The closure that is a parent of this closure, if present
20962103 static const ClosureExpr *
20972104 parentClosure (const AbstractClosureExpr *closure) {
@@ -2411,8 +2418,7 @@ static void diagnoseImplicitSelfUseInClosure(const Expr *E,
24112418
24122419 // Implicit self was permitted for weak self captures in
24132420 // 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)) {
24162422 return true ;
24172423 }
24182424
@@ -2474,8 +2480,7 @@ static void diagnoseImplicitSelfUseInClosure(const Expr *E,
24742480 // }
24752481 //
24762482 bool isEscapingClosureWithExplicitSelfCapture = false ;
2477- if (!AnyFunctionRef (const_cast <AbstractClosureExpr *>(ACE))
2478- .isKnownNoEscape ()) {
2483+ if (!isNonEscaping (ACE)) {
24792484 if (auto closureExpr = dyn_cast<ClosureExpr>(ACE)) {
24802485 if (closureExpr->getCapturedSelfDecl ()) {
24812486 isEscapingClosureWithExplicitSelfCapture = true ;
0 commit comments