Skip to content

Commit c705a62

Browse files
Merge pull request swiftlang#72159 from nate-chandler/partial-consumption/20240307/1
[NoncopyablePartialConsumption] Sharpen diagnosis.
2 parents cfc1df6 + 74ab0f6 commit c705a62

File tree

2 files changed

+9
-10
lines changed

2 files changed

+9
-10
lines changed

lib/Sema/MiscDiagnostics.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -422,14 +422,13 @@ static void diagSyntacticUseRestrictions(const Expr *E, const DeclContext *DC,
422422
void checkConsumeExpr(ConsumeExpr *consumeExpr) {
423423
auto partialConsumptionEnabled =
424424
Ctx.LangOpts.hasFeature(Feature::MoveOnlyPartialConsumption);
425+
auto *subExpr = consumeExpr->getSubExpr();
426+
bool noncopyable =
427+
subExpr->getType()->getCanonicalType()->isNoncopyable();
425428

426-
bool noncopyable = false;
427429
bool partial = false;
428-
Expr *current = consumeExpr->getSubExpr();
430+
Expr *current = subExpr;
429431
while (current) {
430-
if (current->getType()->getCanonicalType()->isNoncopyable()) {
431-
noncopyable = true;
432-
}
433432
if (auto *dre = dyn_cast<DeclRefExpr>(current)) {
434433
if (partial & !noncopyable) {
435434
Ctx.Diags.diagnose(consumeExpr->getLoc(),

test/Sema/move_expr_moveonly_partial_consumption.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ extension Quad_NC {
1818
consuming func explicitEveryLeaf() {
1919
_ = consume p1.u1
2020
_ = consume p1.u2
21-
_ = consume p1.c
21+
_ = consume p1.c // expected-error{{'consume' can only be used to partially consume storage of a noncopyable type}}
2222
_ = consume p2.u1
2323
_ = consume p2.u2
24-
_ = consume p2.c
24+
_ = consume p2.c // expected-error{{'consume' can only be used to partially consume storage of a noncopyable type}}
2525
}
2626

2727
consuming func explicitSomeNonStorage() {
@@ -112,18 +112,18 @@ func decompose(_ c: consuming Container_NC) {
112112
// ====================== NONCOPYABLE GENERIC (BEGIN) ========================{{
113113
// =============================================================================
114114

115-
extension Quad_NCG {
115+
extension Quad_NCG where T : ~Copyable {
116116
consuming func explicitEveryLeaf() {
117117
_ = consume p1.u1
118118
_ = consume p1.u1.t
119119
_ = consume p1.u2
120120
_ = consume p1.u2.t
121-
_ = consume p1.c
121+
_ = consume p1.c // expected-error{{'consume' can only be used to partially consume storage of a noncopyable type}}
122122
_ = consume p2.u1
123123
_ = consume p2.u1.t
124124
_ = consume p2.u2
125125
_ = consume p2.u2.t
126-
_ = consume p2.c
126+
_ = consume p2.c // expected-error{{'consume' can only be used to partially consume storage of a noncopyable type}}
127127
}
128128

129129
consuming func explicitSomeNonStorage() {

0 commit comments

Comments
 (0)