Skip to content

Commit 95cdf2a

Browse files
committed
Revert "temporarily prevent Copyable types from using consuming and borrowing"
This reverts commit 8899d3b.
1 parent 9c98ee8 commit 95cdf2a

File tree

2 files changed

+2
-59
lines changed

2 files changed

+2
-59
lines changed

lib/Sema/TypeCheckAttr.cpp

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@ void AttributeChecker::visitMutationAttr(DeclAttribute *attr) {
468468
}
469469

470470
auto DC = FD->getDeclContext();
471-
// self-ownership attributes may only appear in type context.
471+
// mutation attributes may only appear in type context.
472472
if (auto contextTy = DC->getDeclaredInterfaceType()) {
473473
// 'mutating' and 'nonmutating' are not valid on types
474474
// with reference semantics.
@@ -489,27 +489,6 @@ void AttributeChecker::visitMutationAttr(DeclAttribute *attr) {
489489
break;
490490
}
491491
}
492-
493-
// Unless we have the experimental no-implicit-copy feature enabled, Copyable
494-
// types can't use 'consuming' or 'borrowing' ownership specifiers.
495-
if (!Ctx.LangOpts.hasFeature(Feature::NoImplicitCopy)) {
496-
if (!contextTy->isPureMoveOnly()) {
497-
switch (attrModifier) { // check the modifier for the Copyable type.
498-
case SelfAccessKind::NonMutating:
499-
case SelfAccessKind::Mutating:
500-
case SelfAccessKind::LegacyConsuming:
501-
// already checked
502-
break;
503-
504-
case SelfAccessKind::Consuming:
505-
case SelfAccessKind::Borrowing:
506-
diagnoseAndRemoveAttr(attr, diag::self_ownership_specifier_copyable,
507-
attrModifier, FD->getDescriptiveKind());
508-
break;
509-
}
510-
}
511-
}
512-
513492
} else {
514493
diagnoseAndRemoveAttr(attr, diag::mutating_invalid_global_scope,
515494
attrModifier);

lib/Sema/TypeCheckType.cpp

Lines changed: 1 addition & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -4288,43 +4288,7 @@ TypeResolver::resolveOwnershipTypeRepr(OwnershipTypeRepr *repr,
42884288
// Remember that we've seen an ownership specifier for this base type.
42894289
options |= TypeResolutionFlags::HasOwnership;
42904290

4291-
auto result = resolveType(repr->getBase(), options);
4292-
if (result->hasError())
4293-
return result;
4294-
4295-
// Check for illegal combinations of ownership specifiers and types.
4296-
switch (ownershipRepr->getSpecifier()) {
4297-
case ParamSpecifier::Default:
4298-
case ParamSpecifier::InOut:
4299-
case ParamSpecifier::LegacyShared:
4300-
case ParamSpecifier::LegacyOwned:
4301-
break;
4302-
4303-
case ParamSpecifier::Consuming:
4304-
if (auto *fnTy = result->getAs<FunctionType>()) {
4305-
if (fnTy->isNoEscape()) {
4306-
diagnoseInvalid(ownershipRepr,
4307-
ownershipRepr->getLoc(),
4308-
diag::ownership_specifier_nonescaping_closure,
4309-
ownershipRepr->getSpecifierSpelling());
4310-
return ErrorType::get(getASTContext());
4311-
}
4312-
}
4313-
SWIFT_FALLTHROUGH;
4314-
case ParamSpecifier::Borrowing:
4315-
// Unless we have the experimental no-implicit-copy feature enabled, Copyable
4316-
// types can't use 'consuming' or 'borrowing' ownership specifiers.
4317-
if (!getASTContext().LangOpts.hasFeature(Feature::NoImplicitCopy)) {
4318-
if (!result->isPureMoveOnly()) {
4319-
diagnoseInvalid(ownershipRepr,
4320-
ownershipRepr->getLoc(),
4321-
diag::ownership_specifier_copyable);
4322-
return ErrorType::get(getASTContext());
4323-
}
4324-
}
4325-
}
4326-
4327-
return result;
4291+
return resolveType(repr->getBase(), options);
43284292
}
43294293

43304294
NeverNullType

0 commit comments

Comments
 (0)