Skip to content

Commit d3cead6

Browse files
Merge pull request #81038 from AnthonyLatsis/collybia-nuda-6.2
[6.2] AST: Quote attributes more consistently in diagnostics
2 parents 07b6ddc + f7ca793 commit d3cead6

File tree

180 files changed

+1135
-1095
lines changed

Some content is hidden

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

180 files changed

+1135
-1095
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* "the 'foo' attribute" or "'@foo'", rather than "the '@foo' attribute".
4560

@@ -53,6 +68,8 @@ Clang also has a kind of diagnostic called a "remark", which represents informat
5368

5469
- 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.
5570

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

5875
- 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
@@ -87,7 +87,7 @@ ERROR(require_literal_initializer_for_literal,none,
8787
"_const let should be initialized with a literal value", ())
8888

8989
ERROR(require_const_initializer_for_const,none,
90-
"@const value should be initialized with a compile-time value", ())
90+
"'@const' value should be initialized with a compile-time value", ())
9191

9292
ERROR(require_const_arg_for_parameter,none,
9393
"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))
@@ -1624,14 +1624,14 @@ ERROR(attr_availability_duplicate,none,
16241624

16251625
// originallyDefinedIn
16261626
ERROR(originally_defined_in_missing_rparen,none,
1627-
"expected ')' in @_originallyDefinedIn argument list", ())
1627+
"expected ')' in '@_originallyDefinedIn' argument list", ())
16281628

16291629
ERROR(originally_defined_in_need_original_module_name,none,
16301630
"expected 'module: \"original\"' in the first argument to "
1631-
"@_originallyDefinedIn", ())
1631+
"'@_originallyDefinedIn'", ())
16321632

16331633
ERROR(originally_defined_in_need_nonempty_module_name,none,
1634-
"original module name cannot be empty in @_originallyDefinedIn", ())
1634+
"original module name cannot be empty in '@_originallyDefinedIn'", ())
16351635

16361636
// backDeploy
16371637
ERROR(attr_back_deploy_expected_before_label,none,
@@ -1662,25 +1662,25 @@ ERROR(convention_attribute_witness_method_expected_protocol,none,
16621662

16631663
// objc
16641664
ERROR(attr_objc_missing_colon,none,
1665-
"missing ':' after selector piece in @objc attribute", ())
1665+
"missing ':' after selector piece in '@objc'", ())
16661666
ERROR(attr_objc_expected_rparen,none,
1667-
"expected ')' after name for @objc", ())
1667+
"expected ')' after name for '@objc'", ())
16681668
ERROR(attr_objc_empty_name,none,
1669-
"expected name within parentheses of @objc attribute", ())
1669+
"expected name within parentheses of '@objc'", ())
16701670

16711671
ERROR(attr_dynamic_replacement_expected_rparen,none,
1672-
"expected ')' after function name for @_dynamicReplacement", ())
1672+
"expected ')' after function name for '@_dynamicReplacement'", ())
16731673
ERROR(attr_dynamic_replacement_expected_function,none,
1674-
"expected a function name in @_dynamicReplacement(for:)", ())
1674+
"expected a function name in '@_dynamicReplacement(for:)'", ())
16751675
ERROR(attr_dynamic_replacement_expected_for,none,
16761676
"expected 'for' in '_dynamicReplacement' attribute", ())
16771677
ERROR(attr_dynamic_replacement_expected_colon,none,
1678-
"expected ':' after @_dynamicReplacement(for", ())
1678+
"expected ':' after '@_dynamicReplacement(for'", ())
16791679

16801680
ERROR(attr_type_eraser_expected_type_name,none,
1681-
"expected a type name in @_typeEraser()", ())
1681+
"expected a type name in '@_typeEraser()'", ())
16821682
ERROR(attr_type_eraser_expected_rparen,none,
1683-
"expected ')' after type name for @_typeEraser", ())
1683+
"expected ')' after type name for '@_typeEraser'", ())
16841684

16851685
ERROR(expected_thrown_error_type,none,
16861686
"expected thrown error type after 'throws('", ())
@@ -1698,13 +1698,13 @@ ERROR(attr_isolated_expected_kind,none,
16981698
"expected 'any' as the isolation kind", ())
16991699

17001700
ERROR(attr_private_import_expected_rparen,none,
1701-
"expected ')' after function name for @_private", ())
1701+
"expected ')' after function name for '@_private'", ())
17021702
ERROR(attr_private_import_expected_sourcefile, none,
17031703
"expected 'sourceFile' in '_private' attribute", ())
17041704
ERROR(attr_private_import_expected_sourcefile_name,none,
1705-
"expected a source file name in @_private(sourceFile:)", ())
1705+
"expected a source file name in '@_private(sourceFile:)'", ())
17061706
ERROR(attr_private_import_expected_colon,none,
1707-
"expected ':' after @_private(sourceFile", ())
1707+
"expected ':' after '@_private(sourceFile'", ())
17081708

17091709
// opened
17101710
ERROR(opened_attribute_expected_lparen,none,
@@ -1825,45 +1825,45 @@ ERROR(sil_inst_autodiff_expected_differentiability_witness_kind,PointsToFirstBad
18251825
"'[vjp]', or '[transpose]'", ())
18261826

18271827
WARNING(warn_attr_unsafe_removed,none,
1828-
"'%0' attribute has been removed in favor of @preconcurrency",
1828+
"'%0' attribute has been removed in favor of '@preconcurrency'",
18291829
(StringRef))
18301830

18311831
// _documentation
18321832
ERROR(documentation_attr_expected_argument,none,
1833-
"@_documentation attribute expected 'visibility' or 'metadata' argument",
1833+
"'_documentation' attribute expected 'visibility' or 'metadata' argument",
18341834
())
18351835
ERROR(documentation_attr_unknown_argument,none,
18361836
"unknown argument '%0', expected 'visibility' or 'metadata'",
18371837
(StringRef))
18381838
ERROR(documentation_attr_expected_access_level,none,
1839-
"@_documentation attribute's 'visibility' argument expected an access level",
1839+
"'_documentation' attribute's 'visibility' argument expected an access level",
18401840
())
18411841
ERROR(documentation_attr_unknown_access_level,none,
18421842
"unknown visibility '%0', expected an access level keyword",
18431843
(StringRef))
18441844
ERROR(documentation_attr_duplicate_visibility,none,
18451845
"cannot give more than one visibility to the same item", ())
18461846
ERROR(documentation_attr_metadata_expected_text,none,
1847-
"@_documentation attribute's 'metadata' argument expected an identifier or "
1847+
"'_documentation' attribute's 'metadata' argument expected an identifier or "
18481848
"quoted string",
18491849
())
18501850
ERROR(documentation_attr_duplicate_metadata,none,
18511851
"cannot give more than one metadata argument to the same item", ())
18521852

18531853
ERROR(attr_rawlayout_expected_label,none,
1854-
"expected %0 argument to @_rawLayout attribute", (StringRef))
1854+
"expected %0 argument to '@_rawLayout'", (StringRef))
18551855
ERROR(attr_rawlayout_expected_integer_size,none,
1856-
"expected integer literal size in @_rawLayout attribute", ())
1856+
"expected integer literal size in '@_rawLayout'", ())
18571857
ERROR(attr_rawlayout_expected_integer_alignment,none,
1858-
"expected integer literal alignment in @_rawLayout attribute", ())
1858+
"expected integer literal alignment in '@_rawLayout'", ())
18591859
ERROR(attr_rawlayout_expected_params,none,
1860-
"expected %1 argument after %0 argument in @_rawLayout attribute", (StringRef, StringRef))
1860+
"expected %1 argument after %0 argument in '@_rawLayout'", (StringRef, StringRef))
18611861

18621862
ERROR(attr_extern_expected_label,none,
1863-
"expected %0 argument to @_extern attribute", (StringRef))
1863+
"expected %0 argument to '@_extern'", (StringRef))
18641864

18651865
ERROR(attr_expected_feature_name,none,
1866-
"expected feature name in @%0 attribute", (StringRef))
1866+
"expected feature name in '@%0'", (StringRef))
18671867

18681868
//------------------------------------------------------------------------------
18691869
// MARK: Generics parsing diagnostics
@@ -2056,13 +2056,13 @@ ERROR(macro_role_syntax_mismatch,PointsToFirstBadToken,
20562056
"%select{a freestanding|an attached}0 macro cannot have the %1 role",
20572057
(bool, Identifier))
20582058
ERROR(macro_attribute_unknown_label,PointsToFirstBadToken,
2059-
"@%select{freestanding|attached}0 has no argument with label %1",
2059+
"'@%select{freestanding|attached}0' has no argument with label %1",
20602060
(bool, Identifier))
20612061
ERROR(macro_attribute_duplicate_label,PointsToFirstBadToken,
2062-
"@%select{freestanding|attached}0 already has an argument with "
2062+
"'@%select{freestanding|attached}0' already has an argument with "
20632063
"label %1", (bool, StringRef))
20642064
ERROR(macro_attribute_missing_label,none,
2065-
"@%select{freestanding|attached}0 argument is missing label '%1'",
2065+
"'@%select{freestanding|attached}0' argument is missing label '%1'",
20662066
(bool, StringRef))
20672067
ERROR(macro_attribute_unknown_name_kind,PointsToFirstBadToken,
20682068
"unknown introduced name kind %0", (Identifier))
@@ -2073,7 +2073,8 @@ ERROR(macro_attribute_introduced_name_requires_argument,PointsToFirstBadToken,
20732073
ERROR(macro_attribute_introduced_name_requires_no_argument,PointsToFirstBadToken,
20742074
"introduced name kind %0 must not have an argument", (Identifier))
20752075
WARNING(macro_expression_attribute_removed,PointsToFirstBadToken,
2076-
"@expression has been removed in favor of @freestanding(expression)", ())
2076+
"'@expression' has been removed in favor of '@freestanding(expression)'",
2077+
())
20772078

20782079
ERROR(unexpected_attribute_expansion,PointsToFirstBadToken,
20792080
"unexpected token '%0' in expanded attribute list",
@@ -2109,16 +2110,16 @@ ERROR(init_accessor_is_not_in_the_primary_declaration,none,
21092110
())
21102111

21112112
ERROR(missing_storage_restrictions_attr_label,none,
2112-
"missing label in @storageRestrictions attribute", ())
2113+
"missing label in '@storageRestrictions'", ())
21132114

21142115
ERROR(invalid_storage_restrictions_attr_label,none,
2115-
"unexpected label %0 in @storageRestrictions attribute", (Identifier))
2116+
"unexpected label %0 in '@storageRestrictions'", (Identifier))
21162117

21172118
ERROR(duplicate_storage_restrictions_attr_label,none,
2118-
"duplicate label %0 in @storageRestrictions attribute", (Identifier))
2119+
"duplicate label %0 in '@storageRestrictions'", (Identifier))
21192120

21202121
ERROR(storage_restrictions_attr_expected_name,none,
2121-
"expected property name in @storageRestrictions list", ())
2122+
"expected property name in '@storageRestrictions' list", ())
21222123

21232124
ERROR(requires_experimental_feature, none,
21242125
"'%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.
@@ -389,9 +389,9 @@ ERROR(embedded_swift_existential_type,none,
389389
ERROR(embedded_swift_existential,none,
390390
"cannot use a value of protocol type in embedded Swift", ())
391391
ERROR(perf_diag_existential_type,none,
392-
"cannot use a value of protocol type %0 in @_noExistential function", (Type))
392+
"cannot use a value of protocol type %0 in '@_noExistential' function", (Type))
393393
ERROR(perf_diag_existential,none,
394-
"cannot use a value of protocol type in @_noExistential function", ())
394+
"cannot use a value of protocol type in '@_noExistential' function", ())
395395
ERROR(embedded_swift_value_deinit,none,
396396
"cannot de-virtualize deinit of type %0", (Type))
397397
ERROR(embedded_swift_metatype_type,none,
@@ -809,7 +809,7 @@ NOTE(capturepromotion_variable_defined_here,none,
809809

810810
// noimplicitcopy on generic or existential binding
811811
ERROR(noimplicitcopy_used_on_generic_or_existential, none,
812-
"@_noImplicitCopy can not be used on a generic or existential typed "
812+
"'@_noImplicitCopy' can not be used on a generic or existential typed "
813813
"binding or a nominal type containing such typed things", ())
814814

815815
// discard statement
@@ -864,7 +864,8 @@ ERROR(sil_movechecking_cannot_destructure_imported_nonfrozen, none,
864864
"cannot partially consume '%0' of non-frozen type %1 imported from %2",
865865
(StringRef, Type, const ModuleDecl*))
866866
ERROR(sil_movechecking_cannot_destructure_exported_usableFromInline_alwaysEmitIntoClient, none,
867-
"cannot partially consume '%0' of non-frozen usableFromInline type %1 within a function annotated @_alwaysEmitIntoClient",
867+
"cannot partially consume '%0' of non-frozen usableFromInline type %1 "
868+
"within a function annotated '@_alwaysEmitIntoClient'",
868869
(StringRef, Type))
869870
ERROR(sil_movechecking_cannot_destructure, none,
870871
"cannot partially consume '%0'",
@@ -876,7 +877,8 @@ ERROR(sil_movechecking_cannot_partially_reinit_nonfrozen, none,
876877
"cannot partially reinitialize '%0' of non-frozen type %1 imported from %2; only full reinitialization is allowed",
877878
(StringRef, Type, const ModuleDecl*))
878879
ERROR(sil_movechecking_cannot_partially_reinit_exported_usableFromInline_alwaysEmitIntoClient, none,
879-
"cannot partially reinitialize '%0' of non-frozen usableFromInline type %1 within a function annotated @_alwaysEmitIntoClient",
880+
"cannot partially reinitialize '%0' of non-frozen usableFromInline type "
881+
"%1 within a function annotated '@_alwaysEmitIntoClient'",
880882
(StringRef, Type))
881883
ERROR(sil_movechecking_cannot_partially_reinit, none,
882884
"cannot partially reinitialize '%0' after it has been consumed; only full reinitialization is allowed",

0 commit comments

Comments
 (0)