Skip to content

Commit 43f6fea

Browse files
authored
Merge pull request swiftlang#81738 from DougGregor/no-unchecked
Remove the note that suggests using `@unchecked`
2 parents 9ed8b66 + a922e8e commit 43f6fea

File tree

4 files changed

+30
-39
lines changed

4 files changed

+30
-39
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2807,9 +2807,6 @@ WARNING(remove_package_import,none,
28072807
WARNING(public_decl_needs_sendable,none,
28082808
"public %kind0 does not specify whether it is 'Sendable' or not",
28092809
(const ValueDecl *))
2810-
NOTE(explicit_unchecked_sendable,none,
2811-
"add '@unchecked Sendable' conformance to %kind0 if this type manually implements concurrency safety",
2812-
(const ValueDecl *))
28132810
NOTE(explicit_disable_sendable,none,
28142811
"make %kind0 explicitly non-Sendable to suppress this warning",
28152812
(const ValueDecl *))

lib/Sema/TypeCheckConcurrency.cpp

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1370,35 +1370,34 @@ void swift::diagnoseMissingExplicitSendable(NominalTypeDecl *nominal) {
13701370
isUnchecked = true;
13711371
}
13721372

1373-
auto note = nominal->diagnose(
1374-
isUnchecked ? diag::explicit_unchecked_sendable
1375-
: diag::add_nominal_sendable_conformance,
1376-
nominal);
1377-
if (canMakeSendable && !requirements.empty()) {
1378-
// Produce a Fix-It containing a conditional conformance to Sendable,
1379-
// based on the requirements harvested from instance storage.
1380-
1381-
// Form the where clause containing all of the requirements.
1382-
SmallString<64> whereClause;
1383-
{
1384-
llvm::raw_svector_ostream out(whereClause);
1385-
llvm::interleaveComma(
1386-
requirements, out,
1387-
[&](const Requirement &req) {
1388-
out << req.getFirstType().getString() << ": "
1389-
<< req.getSecondType().getString();
1390-
});
1391-
}
1392-
1393-
// Add a Fix-It containing the conditional extension text itself.
1394-
auto insertionLoc = nominal->getBraces().End;
1395-
note.fixItInsertAfter(
1396-
insertionLoc,
1397-
("\n\nextension " + nominal->getName().str() + ": "
1398-
+ (isUnchecked? "@unchecked " : "") + "Sendable where " +
1399-
whereClause + " { }\n").str());
1400-
} else {
1401-
addSendableFixIt(nominal, note, isUnchecked);
1373+
// If we can only make the type Sendable via @unchecked, don't provide a Fix-It.
1374+
if (!isUnchecked) {
1375+
auto note = nominal->diagnose(diag::add_nominal_sendable_conformance, nominal);
1376+
if (canMakeSendable && !requirements.empty()) {
1377+
// Produce a Fix-It containing a conditional conformance to Sendable,
1378+
// based on the requirements harvested from instance storage.
1379+
1380+
// Form the where clause containing all of the requirements.
1381+
SmallString<64> whereClause;
1382+
{
1383+
llvm::raw_svector_ostream out(whereClause);
1384+
llvm::interleaveComma(
1385+
requirements, out,
1386+
[&](const Requirement &req) {
1387+
out << req.getFirstType().getString() << ": "
1388+
<< req.getSecondType().getString();
1389+
});
1390+
}
1391+
1392+
// Add a Fix-It containing the conditional extension text itself.
1393+
auto insertionLoc = nominal->getBraces().End;
1394+
note.fixItInsertAfter(
1395+
insertionLoc,
1396+
("\n\nextension " + nominal->getName().str() + ": "
1397+
+ "Sendable where " + whereClause + " { }\n").str());
1398+
} else {
1399+
addSendableFixIt(nominal, note, isUnchecked);
1400+
}
14021401
}
14031402
}
14041403

test/Concurrency/objc_require_explicit_sendable.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,4 @@ open class Y: X { }
1515

1616

1717
open class Z: NSObject { } // expected-warning{{public class 'Z' does not specify whether it is 'Sendable' or not}}
18-
// expected-note@-1{{add '@unchecked Sendable' conformance to class 'Z' if this type manually implements concurrency safety}}
19-
// expected-note@-2{{make class 'Z' explicitly non-Sendable to suppress this warning}}
18+
// expected-note@-1{{make class 'Z' explicitly non-Sendable to suppress this warning}}

test/Concurrency/require-explicit-sendable.swift

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ public struct S1 { // expected-warning{{public struct 'S1' does not specify whet
1313

1414
class C { }
1515

16-
// expected-note@+2{{add '@unchecked Sendable' conformance to struct 'S2' if this type manually implements concurrency safety}}{{18-18=: @unchecked Sendable}}
1716
// expected-note@+1{{make struct 'S2' explicitly non-Sendable to suppress this warning}}{{+2:2-2=\n\n@available(*, unavailable)\nextension S2: Sendable { \}\n}}
1817
public struct S2 { // expected-warning{{public struct 'S2' does not specify whether it is 'Sendable' or not}}
1918
var c: C
@@ -25,7 +24,6 @@ final public class C1: P { // expected-warning{{public class 'C1' does not speci
2524
let str: String = ""
2625
}
2726

28-
// expected-note@+2{{add '@unchecked Sendable' conformance to class 'C2' if this type manually implements concurrency safety}}{{17-17=: @unchecked Sendable}}
2927
// expected-note@+1{{make class 'C2' explicitly non-Sendable to suppress this warning}}{{+2:2-2=\n\n@available(*, unavailable)\nextension C2: Sendable { \}\n}}
3028
public class C2 { // expected-warning{{public class 'C2' does not specify whether it is 'Sendable' or not}}
3129
var str: String = ""
@@ -37,7 +35,6 @@ public struct S3<T> { // expected-warning{{public generic struct 'S3' does not s
3735
var t: T
3836
}
3937

40-
// expected-note@+2{{add '@unchecked Sendable' conformance to generic struct 'S4' if this type manually implements concurrency safety}}{{+3:2-2=\n\nextension S4: @unchecked Sendable where T: Sendable { \}\n}}
4138
// expected-note@+1{{make generic struct 'S4' explicitly non-Sendable to suppress this warning}}{{+3:2-2=\n\n@available(*, unavailable)\nextension S4: Sendable { \}\n}}
4239
public struct S4<T> { // expected-warning{{public generic struct 'S4' does not specify whether it is 'Sendable' or not}}
4340
var t: T
@@ -92,8 +89,7 @@ public struct S9<T: P2 & Hashable> {
9289
}
9390

9491
public struct S10 { // expected-warning{{public struct 'S10' does not specify whether it is 'Sendable' or not}}
95-
// expected-note@-1{{add '@unchecked Sendable' conformance to struct 'S10' if this type manually implements concurrency safety}}
96-
// expected-note@-2{{make struct 'S10' explicitly non-Sendable to suppress this warning}}
92+
// expected-note@-1{{make struct 'S10' explicitly non-Sendable to suppress this warning}}
9793
var s7: S7
9894
}
9995

0 commit comments

Comments
 (0)