Skip to content

Commit 2471323

Browse files
committed
Revert "temporarily prevent Copyable types from using consuming and borrowing"
This reverts commit 8899d3b. (cherry picked from commit 95cdf2a)
1 parent d836766 commit 2471323

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
@@ -466,7 +466,7 @@ void AttributeChecker::visitMutationAttr(DeclAttribute *attr) {
466466
}
467467

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

lib/Sema/TypeCheckType.cpp

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

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

43294293
NeverNullType

0 commit comments

Comments
 (0)