Skip to content

Commit 76d7c6f

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 8ccc2c2 commit 76d7c6f

19 files changed

+253
-255
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 45 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -6909,30 +6909,6 @@ ERROR(wrap_invalid_attr_added_by_access_note, none,
69096909

69106910
#undef WHICH_ACCESS_NOTE
69116911

6912-
// Move Only diagnostics
6913-
6914-
ERROR(experimental_moveonly_feature_can_only_be_used_when_enabled,
6915-
none, "Can not use feature when experimental move only is disabled! Pass"
6916-
" the frontend flag -enable-experimental-move-only to swift to enable "
6917-
"the usage of this language feature", ())
6918-
ERROR(noimplicitcopy_attr_valid_only_on_local_let_params,
6919-
none, "'@_noImplicitCopy' attribute can only be applied to local lets and params", ())
6920-
ERROR(noimplicitcopy_attr_invalid_in_generic_context,
6921-
none, "'@_noImplicitCopy' attribute cannot be applied to entities in generic contexts", ())
6922-
ERROR(moveonly_generics, none, "move-only type %0 cannot be used with generics yet", (Type))
6923-
ERROR(moveonly_effectful_getter,none,
6924-
"%0 of move-only type cannot be 'async' or 'throws'", (DescriptiveDeclKind))
6925-
ERROR(noimplicitcopy_attr_not_allowed_on_moveonlytype,none,
6926-
"'@_noImplicitCopy' has no effect when applied to a move only type", ())
6927-
ERROR(moveonly_enums_do_not_support_indirect,none,
6928-
"move-only enum %0 cannot be marked indirect or have indirect cases yet", (Identifier))
6929-
ERROR(moveonly_cast,none,
6930-
"move-only types cannot be conditionally cast", ())
6931-
ERROR(moveonly_failable_init,none,
6932-
"move-only types cannot have failable initializers yet", ())
6933-
ERROR(moveonly_objc_enum_banned, none,
6934-
"@objc enums cannot be marked as move-only", ())
6935-
69366912
//------------------------------------------------------------------------------
69376913
// MARK: Type inference from default expressions
69386914
//------------------------------------------------------------------------------
@@ -6990,17 +6966,6 @@ ERROR(concurrency_task_to_thread_model_global_actor_annotation,none,
69906966
"annotating a type with a global actor %0 is not permitted within %1",
69916967
(TypeRepr*, StringRef))
69926968

6993-
ERROR(moveOnly_not_allowed_here,none,
6994-
"'moveOnly' only applies to structs or enums", ())
6995-
ERROR(move_expression_not_passed_lvalue,none,
6996-
"'consume' can only be applied to lvalues", ())
6997-
ERROR(borrow_expression_not_passed_lvalue,none,
6998-
"'borrow' can only be applied to lvalues", ())
6999-
7000-
ERROR(moveOnly_requires_lexical_lifetimes,none,
7001-
"noncopyable types require lexical borrow scopes "
7002-
"(add -enable-lexical-borrow-scopes=true)", ())
7003-
70046969
//------------------------------------------------------------------------------
70056970
// MARK: #_hasSymbol
70066971
//------------------------------------------------------------------------------
@@ -7133,31 +7098,64 @@ NOTE(macro_expand_circular_reference_unnamed_through, none,
71337098
"circular reference expanding %0 macros", (StringRef))
71347099

71357100
//------------------------------------------------------------------------------
7136-
// MARK: Move Only Errors
7101+
// MARK: Noncopyable Types Diagnostics
71377102
//------------------------------------------------------------------------------
71387103

7139-
ERROR(moveonly_copyable_type_that_contains_moveonly_type, none,
7140-
"%0 %1 cannot contain a move-only type without also being move-only",
7104+
ERROR(noncopyable_within_copyable, none,
7105+
"%0 %1 cannot contain a noncopyable type without also being noncopyable",
71417106
(DescriptiveDeclKind, DeclName))
7142-
NOTE(moveonly_copyable_type_that_contains_moveonly_type_location, none,
7143-
"contained move-only %0 '%1.%2'",
7107+
NOTE(noncopyable_within_copyable_location, none,
7108+
"contained noncopyable %0 '%1.%2'",
71447109
(DescriptiveDeclKind, StringRef, StringRef))
7145-
ERROR(moveonly_cannot_conform_to_type, none,
7146-
"move-only %0 %1 cannot conform to %2",
7110+
ERROR(noncopyable_cannot_conform_to_type, none,
7111+
"noncopyable %0 %1 cannot conform to %2",
71477112
(DescriptiveDeclKind, DeclName, Type))
7148-
ERROR(moveonly_parameter_missing_ownership, none,
7113+
ERROR(noncopyable_parameter_requires_ownership, none,
71497114
"noncopyable parameter must specify its ownership", ())
7150-
ERROR(moveonly_parameter_subscript_unsupported, none,
7115+
ERROR(noncopyable_parameter_subscript_unsupported, none,
71517116
"subscripts cannot have noncopyable parameters yet", ())
7152-
NOTE(moveonly_parameter_ownership_suggestion, none,
7117+
NOTE(noncopyable_parameter_ownership_suggestion, none,
71537118
"add '%0' %1", (StringRef, StringRef))
71547119
ERROR(ownership_specifier_copyable,none,
7155-
"Copyable types cannot be 'consuming' or 'borrowing' yet", ())
7120+
"copyable types cannot be 'consuming' or 'borrowing' yet", ())
71567121
ERROR(self_ownership_specifier_copyable,none,
7157-
"%0 is not yet valid on %1s in a Copyable type",
7122+
"%0 is not yet valid on %1s of a copyable type",
71587123
(SelfAccessKind, DescriptiveDeclKind))
71597124
ERROR(ownership_specifier_nonescaping_closure,none,
71607125
"'%0' cannot be applied to nonescaping closure", (StringRef))
7126+
ERROR(noncopyable_generics, none, "noncopyable type %0 cannot be used with generics yet", (Type))
7127+
ERROR(noncopyable_effectful_getter,none,
7128+
"%0 of noncopyable type cannot be 'async' or 'throws'", (DescriptiveDeclKind))
7129+
ERROR(noncopyable_enums_do_not_support_indirect,none,
7130+
"noncopyable enum %0 cannot be marked indirect or have indirect cases yet", (Identifier))
7131+
ERROR(noncopyable_cast,none,
7132+
"noncopyable types cannot be conditionally cast", ())
7133+
ERROR(noncopyable_failable_init,none,
7134+
"noncopyable types cannot have failable initializers yet", ())
7135+
ERROR(noncopyable_objc_enum, none,
7136+
"noncopyable enums cannot be marked '@objc'", ())
7137+
ERROR(moveOnly_not_allowed_here,none,
7138+
"'@_moveOnly' attribute is only valid on structs or enums", ())
7139+
ERROR(consume_expression_not_passed_lvalue,none,
7140+
"'consume' can only be applied to lvalues", ())
7141+
ERROR(borrow_expression_not_passed_lvalue,none,
7142+
"'borrow' can only be applied to lvalues", ())
7143+
7144+
ERROR(moveOnly_requires_lexical_lifetimes,none,
7145+
"noncopyable types require lexical borrow scopes "
7146+
"(add -enable-lexical-borrow-scopes=true)", ())
7147+
7148+
// Experimental noncopyable feature diagnostics:
7149+
ERROR(experimental_moveonly_feature_can_only_be_used_when_enabled,
7150+
none, "Can not use feature when experimental move only is disabled! Pass"
7151+
" the frontend flag -enable-experimental-move-only to swift to enable "
7152+
"the usage of this language feature", ())
7153+
ERROR(noimplicitcopy_attr_valid_only_on_local_let_params,
7154+
none, "'@_noImplicitCopy' attribute can only be applied to local lets and params", ())
7155+
ERROR(noimplicitcopy_attr_invalid_in_generic_context,
7156+
none, "'@_noImplicitCopy' attribute cannot be applied to entities in generic contexts", ())
7157+
ERROR(noimplicitcopy_attr_not_allowed_on_moveonlytype,none,
7158+
"'@_noImplicitCopy' has no effect when applied to a noncopyable type", ())
71617159

71627160
//------------------------------------------------------------------------------
71637161
// MARK: Runtime discoverable attributes (@runtimeMetadata)

lib/Sema/CSDiagnostics.cpp

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

60826082
bool NotCopyableFailure::diagnoseAsError() {
6083-
emitDiagnostic(diag::moveonly_generics, noncopyableTy);
6083+
emitDiagnostic(diag::noncopyable_generics, noncopyableTy);
60846084
return true;
60856085
}
60866086

lib/Sema/MiscDiagnostics.cpp

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

383383
if (castType->isPureMoveOnly()) {
384384
// can't cast anything to move-only; there should be no valid ones.
385-
Ctx.Diags.diagnose(cast->getLoc(), diag::moveonly_cast);
385+
Ctx.Diags.diagnose(cast->getLoc(), diag::noncopyable_cast);
386386
return;
387387
}
388388

@@ -392,7 +392,7 @@ static void diagSyntacticUseRestrictions(const Expr *E, const DeclContext *DC,
392392
if (auto fromType = cast->getSubExpr()->getType()) {
393393
if (fromType->isPureMoveOnly()) {
394394
// can't cast move-only to anything.
395-
Ctx.Diags.diagnose(cast->getLoc(), diag::moveonly_cast);
395+
Ctx.Diags.diagnose(cast->getLoc(), diag::noncopyable_cast);
396396
return;
397397
}
398398
}
@@ -418,7 +418,7 @@ static void diagSyntacticUseRestrictions(const Expr *E, const DeclContext *DC,
418418
void checkMoveExpr(MoveExpr *moveExpr) {
419419
if (!isa<DeclRefExpr>(moveExpr->getSubExpr())) {
420420
Ctx.Diags.diagnose(moveExpr->getLoc(),
421-
diag::move_expression_not_passed_lvalue);
421+
diag::consume_expression_not_passed_lvalue);
422422
}
423423
}
424424

@@ -6179,13 +6179,13 @@ void swift::diagnoseCopyableTypeContainingMoveOnlyType(
61796179
if (auto *eltDecl = topFieldToError.dyn_cast<EnumElementDecl *>()) {
61806180
DE.diagnoseWithNotes(
61816181
copyableNominalType->diagnose(
6182-
diag::moveonly_copyable_type_that_contains_moveonly_type,
6182+
diag::noncopyable_within_copyable,
61836183
copyableNominalType->getDescriptiveKind(),
61846184
copyableNominalType->getBaseName()),
61856185
[&]() {
61866186
eltDecl->diagnose(
61876187
diag::
6188-
moveonly_copyable_type_that_contains_moveonly_type_location,
6188+
noncopyable_within_copyable_location,
61896189
fieldKind, parentName.userFacingName(),
61906190
fieldName.userFacingName());
61916191
});
@@ -6195,12 +6195,12 @@ void swift::diagnoseCopyableTypeContainingMoveOnlyType(
61956195
auto *varDecl = topFieldToError.get<VarDecl *>();
61966196
DE.diagnoseWithNotes(
61976197
copyableNominalType->diagnose(
6198-
diag::moveonly_copyable_type_that_contains_moveonly_type,
6198+
diag::noncopyable_within_copyable,
61996199
copyableNominalType->getDescriptiveKind(),
62006200
copyableNominalType->getBaseName()),
62016201
[&]() {
62026202
varDecl->diagnose(
6203-
diag::moveonly_copyable_type_that_contains_moveonly_type_location,
6203+
diag::noncopyable_within_copyable_location,
62046204
fieldKind, parentName.userFacingName(),
62056205
fieldName.userFacingName());
62066206
});

lib/Sema/TypeCheckDeclPrimary.cpp

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

26192619
if (ED->isObjC() && ED->isMoveOnly()) {
2620-
ED->diagnose(diag::moveonly_objc_enum_banned);
2620+
ED->diagnose(diag::noncopyable_objc_enum);
26212621
}
26222622
// FIXME(kavon): see if these can be integrated into other parts of Sema
26232623
diagnoseCopyableTypeContainingMoveOnlyType(ED);
@@ -2633,11 +2633,11 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
26332633
// indirect cases.
26342634
if (ED->getAttrs().hasAttribute<MoveOnlyAttr>()) {
26352635
if (ED->isIndirect())
2636-
ED->diagnose(diag::moveonly_enums_do_not_support_indirect,
2636+
ED->diagnose(diag::noncopyable_enums_do_not_support_indirect,
26372637
ED->getBaseIdentifier());
26382638
for (auto *elt : ED->getAllElements()) {
26392639
if (elt->isIndirect()) {
2640-
elt->diagnose(diag::moveonly_enums_do_not_support_indirect,
2640+
elt->diagnose(diag::noncopyable_enums_do_not_support_indirect,
26412641
ED->getBaseIdentifier());
26422642
}
26432643
}
@@ -2805,7 +2805,7 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
28052805

28062806
auto &ctx = moveonlyType->getASTContext();
28072807
ctx.Diags.diagnose(loc,
2808-
diag::moveonly_cannot_conform_to_type,
2808+
diag::noncopyable_cannot_conform_to_type,
28092809
moveonlyType->getDescriptiveKind(),
28102810
moveonlyType->getBaseName(),
28112811
type);
@@ -3654,7 +3654,7 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
36543654
if (CD->isFailable()) {
36553655
if (auto *nom = CD->getDeclContext()->getSelfNominalTypeDecl()) {
36563656
if (nom->isMoveOnly()) {
3657-
CD->diagnose(diag::moveonly_failable_init);
3657+
CD->diagnose(diag::noncopyable_failable_init);
36583658
}
36593659
}
36603660
}

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)