Skip to content

Commit 9a98784

Browse files
Merge pull request #80593 from AnthonyLatsis/collybia-nuda
AST: Quote attributes more consistently in diagnostics
2 parents 8c84ee2 + ada632c commit 9a98784

File tree

183 files changed

+1145
-1105
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

183 files changed

+1145
-1105
lines changed

docs/Diagnostics.md

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,23 @@ Clang also has a kind of diagnostic called a "remark", which represents informat
3838

3939
- When applicable, phrase diagnostics as rules rather than reporting that the compiler failed to do something. Example:
4040

41-
- Normal: "cannot call 'super.init' outside of an initializer"
42-
- Better: "'super.init' cannot be called outside of an initializer"
41+
- Normal: `cannot call 'super.init' outside of an initializer`
42+
- Better: `'super.init' cannot be called outside of an initializer`
43+
44+
- Use `'` to quote attributes, symbol names, and any other text that is
45+
referred to as code or a token.
46+
Some idiomatic Swift tokens, such as `protocol`, by themselves are or appear
47+
in Swift terms of art.
48+
Terms of art are written in plain text and must not be quoted.
49+
If you are not certain whether a Swift token has an associated term of art,
50+
consult the [book].
51+
For example:
52+
- `'mutating' is only valid on methods`, but
53+
`cannot call mutating method on immutable value`.
54+
- `'@autoclosure' only applies to function types`.
55+
- `subscript access can throw but is not marked with 'try'`.
56+
- `expected '{' after 'defer'`.
57+
- `type 'S' does not conform to protocol 'Sequence'`.
4358

4459
- When referring to attributes by name, use *either* `attribute 'foo'` or
4560
`'@foo'`, rather than `attribute '@foo'`.
@@ -54,6 +69,8 @@ Clang also has a kind of diagnostic called a "remark", which represents informat
5469

5570
- If possible, it is best to include the name of the type or function that has the error, e.g. "non-actor type 'Nope' cannot ..." is better than "non-actor type cannot ...". It helps developers relate the error message to the specific type the error is about, even if the error would highlight the appropriate line / function in other ways.
5671

72+
[book]: https://docs.swift.org/swift-book/documentation/the-swift-programming-language
73+
5774
### Locations and Highlights ###
5875

5976
- Diagnostics are always emitted at a particular line and column. Try to be specific.

include/swift/AST/DiagnosticsCommon.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ ERROR(require_literal_initializer_for_literal,none,
9292
"_const let should be initialized with a literal value", ())
9393

9494
ERROR(require_const_initializer_for_const,none,
95-
"@const value should be initialized with a compile-time value", ())
95+
"'@const' value should be initialized with a compile-time value", ())
9696

9797
ERROR(require_const_arg_for_parameter,none,
9898
"expected a compile-time value argument for a '@const' parameter", ())

include/swift/AST/DiagnosticsIRGen.def

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,12 @@ ERROR(no_input_files_for_mt,none,
4242
"no swift input files for multi-threaded compilation", ())
4343

4444
ERROR(alignment_dynamic_type_layout_unsupported,none,
45-
"@_alignment is not supported on types with dynamic layout", ())
45+
"'@_alignment' is not supported on types with dynamic layout", ())
4646
ERROR(alignment_less_than_natural,none,
47-
"@_alignment cannot decrease alignment below natural alignment of %0",
47+
"'@_alignment' cannot decrease alignment below natural alignment of %0",
4848
(unsigned))
4949
ERROR(alignment_more_than_maximum,none,
50-
"@_alignment cannot increase alignment above maximum alignment of %0",
50+
"'@_alignment' cannot increase alignment above maximum alignment of %0",
5151
(unsigned))
5252

5353
ERROR(temporary_allocation_size_negative,none,

include/swift/AST/DiagnosticsModuleDiffer.def

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ ERROR(optional_req_changed,APIDigesterBreakage,"%0 is %select{now|no longer}1 an
6666

6767
ERROR(no_longer_open,APIDigesterBreakage,"%0 is no longer open for subclassing", (StringRef))
6868

69-
ERROR(func_type_escaping_changed,APIDigesterBreakage,"%0 has %select{removed|added}2 @escaping in %1", (StringRef, StringRef, bool))
69+
ERROR(func_type_escaping_changed,APIDigesterBreakage,"%0 has %select{removed|added}2 '@escaping' in %1", (StringRef, StringRef, bool))
7070

7171
ERROR(func_self_access_change,APIDigesterBreakage,"%0 has self access kind changing from %1 to %2", (StringRef, StringRef, StringRef))
7272

@@ -78,7 +78,7 @@ ERROR(decl_new_witness_table_entry,APIDigesterBreakage,"%0 now requires%select{|
7878

7979
ERROR(class_member_moved_to_extension,APIDigesterBreakage,"Non-final class member %0 is moved to extension", (StringRef))
8080

81-
WARNING(new_decl_without_intro,APIDigesterBreakage,"%0 is a new API without @available attribute", (StringRef))
81+
WARNING(new_decl_without_intro,APIDigesterBreakage,"%0 is a new API without '@available'", (StringRef))
8282

8383
ERROR(objc_name_change,APIDigesterBreakage,"%0 has ObjC name change from %1 to %2", (StringRef, StringRef, StringRef))
8484

include/swift/AST/DiagnosticsParse.def

Lines changed: 35 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@ ERROR(expected_precedencegroup_relation,none,
497497
ERROR(expected_sil_keyword,none,
498498
"expected SIL keyword", ())
499499
ERROR(inout_not_attribute, none,
500-
"@inout is no longer an attribute", ())
500+
"'inout' is no longer an attribute", ())
501501
ERROR(only_allowed_in_sil,none,
502502
"'%0' only allowed in SIL modules", (StringRef))
503503
ERROR(expected_sil_type,none,
@@ -520,7 +520,7 @@ ERROR(silfunc_and_silarg_have_incompatible_sil_value_ownership,none,
520520
"Function type specifies: '@%0'. SIL argument specifies: '@%1'.",
521521
(StringRef, StringRef))
522522
ERROR(sil_arg_both_lexical_and_eagerMove,none,
523-
"Function argument is annotated both @_eagerMove and @_noEagerMove, "
523+
"Function argument is annotated both '@_eagerMove' and '@_noEagerMove', "
524524
"but these are incompatible alternatives", ())
525525
ERROR(expected_sil_colon,none,
526526
"expected ':' before %0", (StringRef))
@@ -1632,14 +1632,14 @@ ERROR(attr_availability_duplicate,none,
16321632

16331633
// originallyDefinedIn
16341634
ERROR(originally_defined_in_missing_rparen,none,
1635-
"expected ')' in @_originallyDefinedIn argument list", ())
1635+
"expected ')' in '@_originallyDefinedIn' argument list", ())
16361636

16371637
ERROR(originally_defined_in_need_original_module_name,none,
16381638
"expected 'module: \"original\"' in the first argument to "
1639-
"@_originallyDefinedIn", ())
1639+
"'@_originallyDefinedIn'", ())
16401640

16411641
ERROR(originally_defined_in_need_nonempty_module_name,none,
1642-
"original module name cannot be empty in @_originallyDefinedIn", ())
1642+
"original module name cannot be empty in '@_originallyDefinedIn'", ())
16431643

16441644
// backDeploy
16451645
ERROR(attr_back_deploy_expected_before_label,none,
@@ -1670,25 +1670,25 @@ ERROR(convention_attribute_witness_method_expected_protocol,none,
16701670

16711671
// objc
16721672
ERROR(attr_objc_missing_colon,none,
1673-
"missing ':' after selector piece in @objc attribute", ())
1673+
"missing ':' after selector piece in '@objc'", ())
16741674
ERROR(attr_objc_expected_rparen,none,
1675-
"expected ')' after name for @objc", ())
1675+
"expected ')' after name for '@objc'", ())
16761676
ERROR(attr_objc_empty_name,none,
1677-
"expected name within parentheses of @objc attribute", ())
1677+
"expected name within parentheses of '@objc'", ())
16781678

16791679
ERROR(attr_dynamic_replacement_expected_rparen,none,
1680-
"expected ')' after function name for @_dynamicReplacement", ())
1680+
"expected ')' after function name for '@_dynamicReplacement'", ())
16811681
ERROR(attr_dynamic_replacement_expected_function,none,
1682-
"expected a function name in @_dynamicReplacement(for:)", ())
1682+
"expected a function name in '@_dynamicReplacement(for:)'", ())
16831683
ERROR(attr_dynamic_replacement_expected_for,none,
16841684
"expected 'for' in '_dynamicReplacement' attribute", ())
16851685
ERROR(attr_dynamic_replacement_expected_colon,none,
1686-
"expected ':' after @_dynamicReplacement(for", ())
1686+
"expected ':' after '@_dynamicReplacement(for'", ())
16871687

16881688
ERROR(attr_type_eraser_expected_type_name,none,
1689-
"expected a type name in @_typeEraser()", ())
1689+
"expected a type name in '@_typeEraser()'", ())
16901690
ERROR(attr_type_eraser_expected_rparen,none,
1691-
"expected ')' after type name for @_typeEraser", ())
1691+
"expected ')' after type name for '@_typeEraser'", ())
16921692

16931693
ERROR(expected_thrown_error_type,none,
16941694
"expected thrown error type after 'throws('", ())
@@ -1706,13 +1706,13 @@ ERROR(attr_isolated_expected_kind,none,
17061706
"expected 'any' as the isolation kind", ())
17071707

17081708
ERROR(attr_private_import_expected_rparen,none,
1709-
"expected ')' after function name for @_private", ())
1709+
"expected ')' after function name for '@_private'", ())
17101710
ERROR(attr_private_import_expected_sourcefile, none,
17111711
"expected 'sourceFile' in '_private' attribute", ())
17121712
ERROR(attr_private_import_expected_sourcefile_name,none,
1713-
"expected a source file name in @_private(sourceFile:)", ())
1713+
"expected a source file name in '@_private(sourceFile:)'", ())
17141714
ERROR(attr_private_import_expected_colon,none,
1715-
"expected ':' after @_private(sourceFile", ())
1715+
"expected ':' after '@_private(sourceFile'", ())
17161716

17171717
// opened
17181718
ERROR(opened_attribute_expected_lparen,none,
@@ -1833,45 +1833,45 @@ ERROR(sil_inst_autodiff_expected_differentiability_witness_kind,PointsToFirstBad
18331833
"'[vjp]', or '[transpose]'", ())
18341834

18351835
WARNING(warn_attr_unsafe_removed,none,
1836-
"'%0' attribute has been removed in favor of @preconcurrency",
1836+
"'%0' attribute has been removed in favor of '@preconcurrency'",
18371837
(StringRef))
18381838

18391839
// _documentation
18401840
ERROR(documentation_attr_expected_argument,none,
1841-
"@_documentation attribute expected 'visibility' or 'metadata' argument",
1841+
"'_documentation' attribute expected 'visibility' or 'metadata' argument",
18421842
())
18431843
ERROR(documentation_attr_unknown_argument,none,
18441844
"unknown argument '%0', expected 'visibility' or 'metadata'",
18451845
(StringRef))
18461846
ERROR(documentation_attr_expected_access_level,none,
1847-
"@_documentation attribute's 'visibility' argument expected an access level",
1847+
"'_documentation' attribute's 'visibility' argument expected an access level",
18481848
())
18491849
ERROR(documentation_attr_unknown_access_level,none,
18501850
"unknown visibility '%0', expected an access level keyword",
18511851
(StringRef))
18521852
ERROR(documentation_attr_duplicate_visibility,none,
18531853
"cannot give more than one visibility to the same item", ())
18541854
ERROR(documentation_attr_metadata_expected_text,none,
1855-
"@_documentation attribute's 'metadata' argument expected an identifier or "
1855+
"'_documentation' attribute's 'metadata' argument expected an identifier or "
18561856
"quoted string",
18571857
())
18581858
ERROR(documentation_attr_duplicate_metadata,none,
18591859
"cannot give more than one metadata argument to the same item", ())
18601860

18611861
ERROR(attr_rawlayout_expected_label,none,
1862-
"expected %0 argument to @_rawLayout attribute", (StringRef))
1862+
"expected %0 argument to '@_rawLayout'", (StringRef))
18631863
ERROR(attr_rawlayout_expected_integer_size,none,
1864-
"expected integer literal size in @_rawLayout attribute", ())
1864+
"expected integer literal size in '@_rawLayout'", ())
18651865
ERROR(attr_rawlayout_expected_integer_alignment,none,
1866-
"expected integer literal alignment in @_rawLayout attribute", ())
1866+
"expected integer literal alignment in '@_rawLayout'", ())
18671867
ERROR(attr_rawlayout_expected_params,none,
1868-
"expected %1 argument after %0 argument in @_rawLayout attribute", (StringRef, StringRef))
1868+
"expected %1 argument after %0 argument in '@_rawLayout'", (StringRef, StringRef))
18691869

18701870
ERROR(attr_extern_expected_label,none,
1871-
"expected %0 argument to @_extern attribute", (StringRef))
1871+
"expected %0 argument to '@_extern'", (StringRef))
18721872

18731873
ERROR(attr_expected_feature_name,none,
1874-
"expected feature name in @%0 attribute", (StringRef))
1874+
"expected feature name in '@%0'", (StringRef))
18751875

18761876
//------------------------------------------------------------------------------
18771877
// MARK: Generics parsing diagnostics
@@ -2064,13 +2064,13 @@ ERROR(macro_role_syntax_mismatch,PointsToFirstBadToken,
20642064
"%select{a freestanding|an attached}0 macro cannot have the %1 role",
20652065
(bool, Identifier))
20662066
ERROR(macro_attribute_unknown_label,PointsToFirstBadToken,
2067-
"@%select{freestanding|attached}0 has no argument with label %1",
2067+
"'@%select{freestanding|attached}0' has no argument with label %1",
20682068
(bool, Identifier))
20692069
ERROR(macro_attribute_duplicate_label,PointsToFirstBadToken,
2070-
"@%select{freestanding|attached}0 already has an argument with "
2070+
"'@%select{freestanding|attached}0' already has an argument with "
20712071
"label %1", (bool, StringRef))
20722072
ERROR(macro_attribute_missing_label,none,
2073-
"@%select{freestanding|attached}0 argument is missing label '%1'",
2073+
"'@%select{freestanding|attached}0' argument is missing label '%1'",
20742074
(bool, StringRef))
20752075
ERROR(macro_attribute_unknown_name_kind,PointsToFirstBadToken,
20762076
"unknown introduced name kind %0", (Identifier))
@@ -2081,7 +2081,8 @@ ERROR(macro_attribute_introduced_name_requires_argument,PointsToFirstBadToken,
20812081
ERROR(macro_attribute_introduced_name_requires_no_argument,PointsToFirstBadToken,
20822082
"introduced name kind %0 must not have an argument", (Identifier))
20832083
WARNING(macro_expression_attribute_removed,PointsToFirstBadToken,
2084-
"@expression has been removed in favor of @freestanding(expression)", ())
2084+
"'@expression' has been removed in favor of '@freestanding(expression)'",
2085+
())
20852086

20862087
ERROR(unexpected_attribute_expansion,PointsToFirstBadToken,
20872088
"unexpected token '%0' in expanded attribute list",
@@ -2117,16 +2118,16 @@ ERROR(init_accessor_is_not_in_the_primary_declaration,none,
21172118
())
21182119

21192120
ERROR(missing_storage_restrictions_attr_label,none,
2120-
"missing label in @storageRestrictions attribute", ())
2121+
"missing label in '@storageRestrictions'", ())
21212122

21222123
ERROR(invalid_storage_restrictions_attr_label,none,
2123-
"unexpected label %0 in @storageRestrictions attribute", (Identifier))
2124+
"unexpected label %0 in '@storageRestrictions'", (Identifier))
21242125

21252126
ERROR(duplicate_storage_restrictions_attr_label,none,
2126-
"duplicate label %0 in @storageRestrictions attribute", (Identifier))
2127+
"duplicate label %0 in '@storageRestrictions'", (Identifier))
21272128

21282129
ERROR(storage_restrictions_attr_expected_name,none,
2129-
"expected property name in @storageRestrictions list", ())
2130+
"expected property name in '@storageRestrictions' list", ())
21302131

21312132
ERROR(requires_experimental_feature, none,
21322133
"'%0' %select{attribute|parameter specifier}1 is only valid when experimental feature "

include/swift/AST/DiagnosticsSIL.def

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ ERROR(deserialize_function_type_mismatch,Fatal,
143143
(StringRef, Type, Type))
144144

145145
ERROR(without_actually_escaping_on_isolated_any,none,
146-
"withoutActuallyEscaping is currently unimplemented for @isolated(any) "
146+
"withoutActuallyEscaping is currently unimplemented for '@isolated(any)' "
147147
"function values", ())
148148

149149
// Capture before declaration diagnostics.
@@ -391,9 +391,9 @@ ERROR(embedded_swift_existential_protocol,none,
391391
ERROR(embedded_swift_existential,none,
392392
"cannot use a value of protocol type in embedded Swift", ())
393393
ERROR(perf_diag_existential_type,none,
394-
"cannot use a value of protocol type %0 in @_noExistential function", (Type))
394+
"cannot use a value of protocol type %0 in '@_noExistential' function", (Type))
395395
ERROR(perf_diag_existential,none,
396-
"cannot use a value of protocol type in @_noExistential function", ())
396+
"cannot use a value of protocol type in '@_noExistential' function", ())
397397
ERROR(embedded_swift_value_deinit,none,
398398
"cannot de-virtualize deinit of type %0", (Type))
399399
ERROR(embedded_swift_metatype_type,none,
@@ -824,7 +824,7 @@ NOTE(capturepromotion_variable_defined_here,none,
824824

825825
// noimplicitcopy on generic or existential binding
826826
ERROR(noimplicitcopy_used_on_generic_or_existential, none,
827-
"@_noImplicitCopy can not be used on a generic or existential typed "
827+
"'@_noImplicitCopy' can not be used on a generic or existential typed "
828828
"binding or a nominal type containing such typed things", ())
829829

830830
// discard statement
@@ -879,7 +879,8 @@ ERROR(sil_movechecking_cannot_destructure_imported_nonfrozen, none,
879879
"cannot partially consume '%0' of non-frozen type %1 imported from %2",
880880
(StringRef, Type, const ModuleDecl*))
881881
ERROR(sil_movechecking_cannot_destructure_exported_usableFromInline_alwaysEmitIntoClient, none,
882-
"cannot partially consume '%0' of non-frozen usableFromInline type %1 within a function annotated @_alwaysEmitIntoClient",
882+
"cannot partially consume '%0' of non-frozen usableFromInline type %1 "
883+
"within a function annotated '@_alwaysEmitIntoClient'",
883884
(StringRef, Type))
884885
ERROR(sil_movechecking_cannot_destructure, none,
885886
"cannot partially consume '%0'",
@@ -891,7 +892,8 @@ ERROR(sil_movechecking_cannot_partially_reinit_nonfrozen, none,
891892
"cannot partially reinitialize '%0' of non-frozen type %1 imported from %2; only full reinitialization is allowed",
892893
(StringRef, Type, const ModuleDecl*))
893894
ERROR(sil_movechecking_cannot_partially_reinit_exported_usableFromInline_alwaysEmitIntoClient, none,
894-
"cannot partially reinitialize '%0' of non-frozen usableFromInline type %1 within a function annotated @_alwaysEmitIntoClient",
895+
"cannot partially reinitialize '%0' of non-frozen usableFromInline type "
896+
"%1 within a function annotated '@_alwaysEmitIntoClient'",
895897
(StringRef, Type))
896898
ERROR(sil_movechecking_cannot_partially_reinit, none,
897899
"cannot partially reinitialize '%0' after it has been consumed; only full reinitialization is allowed",

0 commit comments

Comments
 (0)