Skip to content

[NoncopyablePartialConsumption] Sharpen diagnosis. #72159

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions lib/Sema/MiscDiagnostics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -422,14 +422,13 @@ static void diagSyntacticUseRestrictions(const Expr *E, const DeclContext *DC,
void checkConsumeExpr(ConsumeExpr *consumeExpr) {
auto partialConsumptionEnabled =
Ctx.LangOpts.hasFeature(Feature::MoveOnlyPartialConsumption);
auto *subExpr = consumeExpr->getSubExpr();
bool noncopyable =
subExpr->getType()->getCanonicalType()->isNoncopyable();

bool noncopyable = false;
bool partial = false;
Expr *current = consumeExpr->getSubExpr();
Expr *current = subExpr;
while (current) {
if (current->getType()->getCanonicalType()->isNoncopyable()) {
noncopyable = true;
}
if (auto *dre = dyn_cast<DeclRefExpr>(current)) {
if (partial & !noncopyable) {
Ctx.Diags.diagnose(consumeExpr->getLoc(),
Expand Down
10 changes: 5 additions & 5 deletions test/Sema/move_expr_moveonly_partial_consumption.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ extension Quad_NC {
consuming func explicitEveryLeaf() {
_ = consume p1.u1
_ = consume p1.u2
_ = consume p1.c
_ = consume p1.c // expected-error{{'consume' can only be used to partially consume storage of a noncopyable type}}
_ = consume p2.u1
_ = consume p2.u2
_ = consume p2.c
_ = consume p2.c // expected-error{{'consume' can only be used to partially consume storage of a noncopyable type}}
}

consuming func explicitSomeNonStorage() {
Expand Down Expand Up @@ -112,18 +112,18 @@ func decompose(_ c: consuming Container_NC) {
// ====================== NONCOPYABLE GENERIC (BEGIN) ========================{{
// =============================================================================

extension Quad_NCG {
extension Quad_NCG where T : ~Copyable {
consuming func explicitEveryLeaf() {
_ = consume p1.u1
_ = consume p1.u1.t
_ = consume p1.u2
_ = consume p1.u2.t
_ = consume p1.c
_ = consume p1.c // expected-error{{'consume' can only be used to partially consume storage of a noncopyable type}}
_ = consume p2.u1
_ = consume p2.u1.t
_ = consume p2.u2
_ = consume p2.u2.t
_ = consume p2.c
_ = consume p2.c // expected-error{{'consume' can only be used to partially consume storage of a noncopyable type}}
}

consuming func explicitSomeNonStorage() {
Expand Down