Wrap SE-0481 into an upcoming feature until source incompatibilities are resolved

This commit is contained in:
Mykola Pokhylets
2025-07-02 07:26:39 +02:00
parent 09a751f698
commit ae48446716
28 changed files with 353 additions and 132 deletions

View File

@@ -515,9 +515,11 @@ void LabeledConditionalStmt::setCond(StmtCondition e) {
/// - If `requiresCaptureListRef` is `true`, additionally requires that the
/// RHS of the self condition references a var defined in a capture list.
bool LabeledConditionalStmt::rebindsSelf(ASTContext &Ctx,
bool requiresCaptureListRef) const {
return llvm::any_of(getCond(), [&Ctx, requiresCaptureListRef](const auto &cond) {
return cond.rebindsSelf(Ctx, requiresCaptureListRef);
bool requiresCaptureListRef,
bool requireLoadExpr) const {
return llvm::any_of(getCond(), [&Ctx, requiresCaptureListRef,
requireLoadExpr](const auto &cond) {
return cond.rebindsSelf(Ctx, requiresCaptureListRef, requireLoadExpr);
});
}
@@ -526,7 +528,8 @@ bool LabeledConditionalStmt::rebindsSelf(ASTContext &Ctx,
/// - If `requiresCaptureListRef` is `true`, additionally requires that the
/// RHS of the self condition references a var defined in a capture list.
bool StmtConditionElement::rebindsSelf(ASTContext &Ctx,
bool requiresCaptureListRef) const {
bool requiresCaptureListRef,
bool requireLoadExpr) const {
auto pattern = getPatternOrNull();
if (!pattern) {
return false;
@@ -554,6 +557,10 @@ bool StmtConditionElement::rebindsSelf(ASTContext &Ctx,
return false;
}
if (requireLoadExpr && !isa<LoadExpr>(exprToCheckForDRE)) {
return false;
}
if (auto *load = dyn_cast<LoadExpr>(exprToCheckForDRE)) {
exprToCheckForDRE = load->getSubExpr();
}