Skip to content

Commit f0ce3ea

Browse files
committed
polish noncopyable types diagnostic wordings
- replaces "move-only" terminology with "noncopyable" - replaces compiler jargon like "guaranteed parameters" and "lvalue" with corresponding language-level notions
1 parent ee9563f commit f0ce3ea

33 files changed

+822
-824
lines changed

docs/SIL.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2805,7 +2805,7 @@ canonical SIL that the value was never copied and thus is a "move only value"
28052805
even though the actual underlying wrapped type is copyable. As an example of
28062806
this, consider the following Swift::
28072807

2808-
func doSomething(@_noImplicitCopy _ x: Klass) -> () { // expected-error {{'x' has guaranteed ownership but was consumed}}
2808+
func doSomething(@_noImplicitCopy _ x: Klass) -> () { // expected-error {{'x' is borrowed and cannot be consumed}}
28092809
x.doSomething()
28102810
let x2 = x // expected-note {{consuming use}}
28112811
x2.doSomething()

include/swift/AST/DiagnosticsSIL.def

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -753,9 +753,9 @@ ERROR(sil_moveonlychecker_owned_value_consumed_and_used_at_same_time, none,
753753
ERROR(sil_moveonlychecker_value_used_after_consume, none,
754754
"'%0' used after consume", (StringRef))
755755
ERROR(sil_moveonlychecker_guaranteed_value_consumed, none,
756-
"'%0' has guaranteed ownership but was consumed", (StringRef))
756+
"'%0' is borrowed and cannot be consumed", (StringRef))
757757
ERROR(sil_moveonlychecker_guaranteed_value_captured_by_closure, none,
758-
"'%0' has guaranteed ownership but was consumed due to being captured by a closure", (StringRef))
758+
"'%0' is borrowed and cannot be consumed by closure capture", (StringRef))
759759
ERROR(sil_moveonlychecker_let_value_consumed_in_closure, none,
760760
"'%0' consumed in closure. This is illegal since if the closure is invoked more than once the binding will be uninitialized on later invocations", (StringRef))
761761
ERROR(sil_moveonlychecker_inout_not_reinitialized_before_end_of_function, none,

include/swift/AST/DiagnosticsSema.def

Lines changed: 49 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -6930,30 +6930,6 @@ ERROR(wrap_invalid_attr_added_by_access_note, none,
69306930

69316931
#undef WHICH_ACCESS_NOTE
69326932

6933-
// Move Only diagnostics
6934-
6935-
ERROR(experimental_moveonly_feature_can_only_be_used_when_enabled,
6936-
none, "Can not use feature when experimental move only is disabled! Pass"
6937-
" the frontend flag -enable-experimental-move-only to swift to enable "
6938-
"the usage of this language feature", ())
6939-
ERROR(noimplicitcopy_attr_valid_only_on_local_let_params,
6940-
none, "'@_noImplicitCopy' attribute can only be applied to local lets and params", ())
6941-
ERROR(noimplicitcopy_attr_invalid_in_generic_context,
6942-
none, "'@_noImplicitCopy' attribute cannot be applied to entities in generic contexts", ())
6943-
ERROR(moveonly_generics, none, "move-only type %0 cannot be used with generics yet", (Type))
6944-
ERROR(moveonly_effectful_getter,none,
6945-
"%0 of move-only type cannot be 'async' or 'throws'", (DescriptiveDeclKind))
6946-
ERROR(noimplicitcopy_attr_not_allowed_on_moveonlytype,none,
6947-
"'@_noImplicitCopy' has no effect when applied to a move only type", ())
6948-
ERROR(moveonly_enums_do_not_support_indirect,none,
6949-
"move-only enum %0 cannot be marked indirect or have indirect cases yet", (Identifier))
6950-
ERROR(moveonly_cast,none,
6951-
"move-only types cannot be conditionally cast", ())
6952-
ERROR(moveonly_failable_init,none,
6953-
"move-only types cannot have failable initializers yet", ())
6954-
ERROR(moveonly_objc_enum_banned, none,
6955-
"@objc enums cannot be marked as move-only", ())
6956-
69576933
//------------------------------------------------------------------------------
69586934
// MARK: Type inference from default expressions
69596935
//------------------------------------------------------------------------------
@@ -7011,21 +6987,6 @@ ERROR(concurrency_task_to_thread_model_global_actor_annotation,none,
70116987
"annotating a type with a global actor %0 is not permitted within %1",
70126988
(TypeRepr*, StringRef))
70136989

7014-
ERROR(moveOnly_not_allowed_here,none,
7015-
"'moveOnly' only applies to structs or enums", ())
7016-
ERROR(consume_expression_not_passed_lvalue,none,
7017-
"'consume' can only be applied to lvalues", ())
7018-
ERROR(borrow_expression_not_passed_lvalue,none,
7019-
"'borrow' can only be applied to lvalues", ())
7020-
ERROR(copy_expression_not_passed_lvalue,none,
7021-
"'copy' can only be applied to lvalues", ())
7022-
ERROR(copy_expression_cannot_be_used_with_noncopyable_types,none,
7023-
"'copy' cannot be applied to noncopyable types", ())
7024-
7025-
ERROR(moveOnly_requires_lexical_lifetimes,none,
7026-
"noncopyable types require lexical borrow scopes "
7027-
"(add -enable-lexical-borrow-scopes=true)", ())
7028-
70296990
//------------------------------------------------------------------------------
70306991
// MARK: #_hasSymbol
70316992
//------------------------------------------------------------------------------
@@ -7158,31 +7119,68 @@ NOTE(macro_expand_circular_reference_unnamed_through, none,
71587119
"circular reference expanding %0 macros", (StringRef))
71597120

71607121
//------------------------------------------------------------------------------
7161-
// MARK: Move Only Errors
7122+
// MARK: Noncopyable Types Diagnostics
71627123
//------------------------------------------------------------------------------
71637124

7164-
ERROR(moveonly_copyable_type_that_contains_moveonly_type, none,
7165-
"%0 %1 cannot contain a move-only type without also being move-only",
7125+
ERROR(noncopyable_within_copyable, none,
7126+
"%0 %1 cannot contain a noncopyable type without also being noncopyable",
71667127
(DescriptiveDeclKind, DeclName))
7167-
NOTE(moveonly_copyable_type_that_contains_moveonly_type_location, none,
7168-
"contained move-only %0 '%1.%2'",
7128+
NOTE(noncopyable_within_copyable_location, none,
7129+
"contained noncopyable %0 '%1.%2'",
71697130
(DescriptiveDeclKind, StringRef, StringRef))
7170-
ERROR(moveonly_cannot_conform_to_type, none,
7171-
"move-only %0 %1 cannot conform to %2",
7131+
ERROR(noncopyable_cannot_conform_to_type, none,
7132+
"noncopyable %0 %1 cannot conform to %2",
71727133
(DescriptiveDeclKind, DeclName, Type))
7173-
ERROR(moveonly_parameter_missing_ownership, none,
7134+
ERROR(noncopyable_parameter_requires_ownership, none,
71747135
"noncopyable parameter must specify its ownership", ())
7175-
ERROR(moveonly_parameter_subscript_unsupported, none,
7136+
ERROR(noncopyable_parameter_subscript_unsupported, none,
71767137
"subscripts cannot have noncopyable parameters yet", ())
7177-
NOTE(moveonly_parameter_ownership_suggestion, none,
7138+
NOTE(noncopyable_parameter_ownership_suggestion, none,
71787139
"add '%0' %1", (StringRef, StringRef))
71797140
ERROR(ownership_specifier_copyable,none,
7180-
"Copyable types cannot be 'consuming' or 'borrowing' yet", ())
7141+
"copyable types cannot be 'consuming' or 'borrowing' yet", ())
71817142
ERROR(self_ownership_specifier_copyable,none,
7182-
"%0 is not yet valid on %1s in a Copyable type",
7143+
"%0 is not yet valid on %1s of a copyable type",
71837144
(SelfAccessKind, DescriptiveDeclKind))
71847145
ERROR(ownership_specifier_nonescaping_closure,none,
71857146
"'%0' cannot be applied to nonescaping closure", (StringRef))
7147+
ERROR(noncopyable_generics, none, "noncopyable type %0 cannot be used with generics yet", (Type))
7148+
ERROR(noncopyable_effectful_getter,none,
7149+
"%0 of noncopyable type cannot be 'async' or 'throws'", (DescriptiveDeclKind))
7150+
ERROR(noncopyable_enums_do_not_support_indirect,none,
7151+
"noncopyable enum %0 cannot be marked indirect or have indirect cases yet", (Identifier))
7152+
ERROR(noncopyable_cast,none,
7153+
"noncopyable types cannot be conditionally cast", ())
7154+
ERROR(noncopyable_failable_init,none,
7155+
"noncopyable types cannot have failable initializers yet", ())
7156+
ERROR(noncopyable_objc_enum, none,
7157+
"noncopyable enums cannot be marked '@objc'", ())
7158+
ERROR(moveOnly_not_allowed_here,none,
7159+
"'@_moveOnly' attribute is only valid on structs or enums", ())
7160+
ERROR(consume_expression_not_passed_lvalue,none,
7161+
"'consume' can only be applied to a local binding ('let', 'var', or parameter)", ())
7162+
ERROR(borrow_expression_not_passed_lvalue,none,
7163+
"'borrow' can only be applied to a local binding ('let', 'var', or parameter)", ())
7164+
ERROR(copy_expression_not_passed_lvalue,none,
7165+
"'copy' can only be applied to a local binding ('let', 'var', or parameter)", ())
7166+
ERROR(copy_expression_cannot_be_used_with_noncopyable_types,none,
7167+
"'copy' cannot be applied to noncopyable types", ())
7168+
7169+
ERROR(moveOnly_requires_lexical_lifetimes,none,
7170+
"noncopyable types require lexical borrow scopes "
7171+
"(add -enable-lexical-borrow-scopes=true)", ())
7172+
7173+
// Experimental noncopyable feature diagnostics:
7174+
ERROR(experimental_moveonly_feature_can_only_be_used_when_enabled,
7175+
none, "Can not use feature when experimental move only is disabled! Pass"
7176+
" the frontend flag -enable-experimental-move-only to swift to enable "
7177+
"the usage of this language feature", ())
7178+
ERROR(noimplicitcopy_attr_valid_only_on_local_let_params,
7179+
none, "'@_noImplicitCopy' attribute can only be applied to local lets and params", ())
7180+
ERROR(noimplicitcopy_attr_invalid_in_generic_context,
7181+
none, "'@_noImplicitCopy' attribute cannot be applied to entities in generic contexts", ())
7182+
ERROR(noimplicitcopy_attr_not_allowed_on_moveonlytype,none,
7183+
"'@_noImplicitCopy' has no effect when applied to a noncopyable type", ())
71867184

71877185
//------------------------------------------------------------------------------
71887186
// MARK: Runtime discoverable attributes (@runtimeMetadata)

lib/Sema/CSDiagnostics.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6129,7 +6129,7 @@ bool NotCompileTimeConstFailure::diagnoseAsError() {
61296129
}
61306130

61316131
bool NotCopyableFailure::diagnoseAsError() {
6132-
emitDiagnostic(diag::moveonly_generics, noncopyableTy);
6132+
emitDiagnostic(diag::noncopyable_generics, noncopyableTy);
61336133
return true;
61346134
}
61356135

lib/Sema/MiscDiagnostics.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ static void diagSyntacticUseRestrictions(const Expr *E, const DeclContext *DC,
388388

389389
if (castType->isPureMoveOnly()) {
390390
// can't cast anything to move-only; there should be no valid ones.
391-
Ctx.Diags.diagnose(cast->getLoc(), diag::moveonly_cast);
391+
Ctx.Diags.diagnose(cast->getLoc(), diag::noncopyable_cast);
392392
return;
393393
}
394394

@@ -398,7 +398,7 @@ static void diagSyntacticUseRestrictions(const Expr *E, const DeclContext *DC,
398398
if (auto fromType = cast->getSubExpr()->getType()) {
399399
if (fromType->isPureMoveOnly()) {
400400
// can't cast move-only to anything.
401-
Ctx.Diags.diagnose(cast->getLoc(), diag::moveonly_cast);
401+
Ctx.Diags.diagnose(cast->getLoc(), diag::noncopyable_cast);
402402
return;
403403
}
404404
}
@@ -6208,13 +6208,13 @@ void swift::diagnoseCopyableTypeContainingMoveOnlyType(
62086208
if (auto *eltDecl = topFieldToError.dyn_cast<EnumElementDecl *>()) {
62096209
DE.diagnoseWithNotes(
62106210
copyableNominalType->diagnose(
6211-
diag::moveonly_copyable_type_that_contains_moveonly_type,
6211+
diag::noncopyable_within_copyable,
62126212
copyableNominalType->getDescriptiveKind(),
62136213
copyableNominalType->getBaseName()),
62146214
[&]() {
62156215
eltDecl->diagnose(
62166216
diag::
6217-
moveonly_copyable_type_that_contains_moveonly_type_location,
6217+
noncopyable_within_copyable_location,
62186218
fieldKind, parentName.userFacingName(),
62196219
fieldName.userFacingName());
62206220
});
@@ -6224,12 +6224,12 @@ void swift::diagnoseCopyableTypeContainingMoveOnlyType(
62246224
auto *varDecl = topFieldToError.get<VarDecl *>();
62256225
DE.diagnoseWithNotes(
62266226
copyableNominalType->diagnose(
6227-
diag::moveonly_copyable_type_that_contains_moveonly_type,
6227+
diag::noncopyable_within_copyable,
62286228
copyableNominalType->getDescriptiveKind(),
62296229
copyableNominalType->getBaseName()),
62306230
[&]() {
62316231
varDecl->diagnose(
6232-
diag::moveonly_copyable_type_that_contains_moveonly_type_location,
6232+
diag::noncopyable_within_copyable_location,
62336233
fieldKind, parentName.userFacingName(),
62346234
fieldName.userFacingName());
62356235
});

lib/Sema/TypeCheckDeclPrimary.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2609,7 +2609,7 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
26092609
//
26102610

26112611
if (ED->isObjC() && ED->isMoveOnly()) {
2612-
ED->diagnose(diag::moveonly_objc_enum_banned);
2612+
ED->diagnose(diag::noncopyable_objc_enum);
26132613
}
26142614
// FIXME(kavon): see if these can be integrated into other parts of Sema
26152615
diagnoseCopyableTypeContainingMoveOnlyType(ED);
@@ -2625,11 +2625,11 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
26252625
// indirect cases.
26262626
if (ED->getAttrs().hasAttribute<MoveOnlyAttr>()) {
26272627
if (ED->isIndirect())
2628-
ED->diagnose(diag::moveonly_enums_do_not_support_indirect,
2628+
ED->diagnose(diag::noncopyable_enums_do_not_support_indirect,
26292629
ED->getBaseIdentifier());
26302630
for (auto *elt : ED->getAllElements()) {
26312631
if (elt->isIndirect()) {
2632-
elt->diagnose(diag::moveonly_enums_do_not_support_indirect,
2632+
elt->diagnose(diag::noncopyable_enums_do_not_support_indirect,
26332633
ED->getBaseIdentifier());
26342634
}
26352635
}
@@ -2797,7 +2797,7 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
27972797

27982798
auto &ctx = moveonlyType->getASTContext();
27992799
ctx.Diags.diagnose(loc,
2800-
diag::moveonly_cannot_conform_to_type,
2800+
diag::noncopyable_cannot_conform_to_type,
28012801
moveonlyType->getDescriptiveKind(),
28022802
moveonlyType->getBaseName(),
28032803
type);
@@ -3646,7 +3646,7 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
36463646
if (CD->isFailable()) {
36473647
if (auto *nom = CD->getDeclContext()->getSelfNominalTypeDecl()) {
36483648
if (nom->isMoveOnly()) {
3649-
CD->diagnose(diag::moveonly_failable_init);
3649+
CD->diagnose(diag::noncopyable_failable_init);
36503650
}
36513651
}
36523652
}

lib/Sema/TypeCheckStorage.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,7 @@ OpaqueReadOwnershipRequest::evaluate(Evaluator &evaluator,
629629
if (auto *getter = storage->getEffectfulGetAccessor()) {
630630
switch (kind) {
631631
case DiagKind::NoncopyableType:
632-
getter->diagnose(diag::moveonly_effectful_getter,
632+
getter->diagnose(diag::noncopyable_effectful_getter,
633633
getter->getDescriptiveKind());
634634
break;
635635
case DiagKind::BorrowedAttr:

lib/Sema/TypeCheckType.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1006,7 +1006,7 @@ static bool didDiagnoseMoveOnlyGenericArgs(ASTContext &ctx,
10061006
if (!t->isPureMoveOnly())
10071007
continue;
10081008

1009-
ctx.Diags.diagnose(loc, diag::moveonly_generics, t);
1009+
ctx.Diags.diagnose(loc, diag::noncopyable_generics, t);
10101010
didEmitDiag = true;
10111011
}
10121012

@@ -2278,7 +2278,7 @@ bool TypeResolver::diagnoseInvalidPlaceHolder(OpaqueReturnTypeRepr *repr) {
22782278
/// returns true if an error diagnostic was emitted
22792279
bool TypeResolver::diagnoseMoveOnly(TypeRepr *repr, Type genericArgTy) {
22802280
if (genericArgTy->isPureMoveOnly()) {
2281-
diagnoseInvalid(repr, repr->getLoc(), diag::moveonly_generics,
2281+
diagnoseInvalid(repr, repr->getLoc(), diag::noncopyable_generics,
22822282
genericArgTy);
22832283
return true;
22842284
}
@@ -2319,21 +2319,21 @@ bool TypeResolver::diagnoseMoveOnlyMissingOwnership(
23192319
// decls, give a tailored error message saying you simply can't use a
23202320
// noncopyable type here.
23212321
if (options.hasBase(TypeResolverContext::SubscriptDecl)) {
2322-
diagnose(repr->getLoc(), diag::moveonly_parameter_subscript_unsupported);
2322+
diagnose(repr->getLoc(), diag::noncopyable_parameter_subscript_unsupported);
23232323
} else {
23242324
// general error diagnostic
23252325
diagnose(repr->getLoc(),
2326-
diag::moveonly_parameter_missing_ownership);
2326+
diag::noncopyable_parameter_requires_ownership);
23272327

2328-
diagnose(repr->getLoc(), diag::moveonly_parameter_ownership_suggestion,
2328+
diagnose(repr->getLoc(), diag::noncopyable_parameter_ownership_suggestion,
23292329
"borrowing", "for an immutable reference")
23302330
.fixItInsert(repr->getStartLoc(), "borrowing ");
23312331

2332-
diagnose(repr->getLoc(), diag::moveonly_parameter_ownership_suggestion,
2332+
diagnose(repr->getLoc(), diag::noncopyable_parameter_ownership_suggestion,
23332333
"inout", "for a mutable reference")
23342334
.fixItInsert(repr->getStartLoc(), "inout ");
23352335

2336-
diagnose(repr->getLoc(), diag::moveonly_parameter_ownership_suggestion,
2336+
diagnose(repr->getLoc(), diag::noncopyable_parameter_ownership_suggestion,
23372337
"consuming", "to take the value from the caller")
23382338
.fixItInsert(repr->getStartLoc(), "consuming ");
23392339
}

0 commit comments

Comments
 (0)