Skip to content

Commit 2d179ce

Browse files
authored
Merge pull request swiftlang#39954 from gottesmm/pr-2c18478a1d9b0c30c530be2c6890f7f5fea35fc5
[moveOnly] Move @_noImplicitCopy behind the flag -enable-experimental-move-only
2 parents 1b3fa26 + 6056172 commit 2d179ce

File tree

4 files changed

+27
-1
lines changed

4 files changed

+27
-1
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6036,6 +6036,10 @@ ERROR(wrap_invalid_attr_added_by_access_note, none,
60366036

60376037
// Move Only diagnostics
60386038

6039+
ERROR(experimental_moveonly_feature_can_only_be_used_when_enabled,
6040+
none, "Can not use feature when experimental move only is disabled! Pass"
6041+
" the frontend flag -enable-experimental-move-only to swift to enable "
6042+
"the usage of this language feature", ())
60396043
ERROR(noimplicitcopy_attr_valid_only_on_local_let,
60406044
none, "'@_noImplicitCopy' attribute can only be applied to local lets", ())
60416045
ERROR(noimplicitcopy_attr_invalid_in_generic_context,

lib/Sema/TypeCheckAttr.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "swift/AST/ClangModuleLoader.h"
2525
#include "swift/AST/Decl.h"
2626
#include "swift/AST/DiagnosticsParse.h"
27+
#include "swift/AST/DiagnosticsSema.h"
2728
#include "swift/AST/Effects.h"
2829
#include "swift/AST/GenericEnvironment.h"
2930
#include "swift/AST/ImportCache.h"
@@ -270,6 +271,15 @@ class AttributeChecker : public AttributeVisitor<AttributeChecker> {
270271
} // end anonymous namespace
271272

272273
void AttributeChecker::visitNoImplicitCopyAttr(NoImplicitCopyAttr *attr) {
274+
// Only allow for this attribute to be used when experimental move only is
275+
// enabled.
276+
if (!D->getASTContext().LangOpts.EnableExperimentalMoveOnly) {
277+
auto error =
278+
diag::experimental_moveonly_feature_can_only_be_used_when_enabled;
279+
diagnoseAndRemoveAttr(attr, error);
280+
return;
281+
}
282+
273283
auto *dc = D->getDeclContext();
274284
auto *vd = dyn_cast<VarDecl>(D);
275285
if (!vd) {

test/Sema/noimplicitcopy_attr.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-typecheck-verify-swift -parse-stdlib -disable-availability-checking -verify-syntax-tree
1+
// RUN: %target-typecheck-verify-swift -enable-experimental-move-only -parse-stdlib -disable-availability-checking -verify-syntax-tree
22

33
import Swift
44

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// RUN: %target-typecheck-verify-swift -parse-stdlib -disable-availability-checking -verify-syntax-tree
2+
3+
class Klass {}
4+
5+
func useKlass(_ k: Klass) {}
6+
7+
// Make sure that we properly error when someone uses no implicit copy without
8+
// setting -enable-experimental-move-only.
9+
func letDecls(_ x: Klass) -> () {
10+
@_noImplicitCopy let y: Klass = x // expected-error {{Can not use feature when experimental move only is disabled! Pass the frontend flag -enable-experimental-move-only to swift to enable the usage of this language feature}}
11+
useKlass(y)
12+
}

0 commit comments

Comments
 (0)