Skip to content

Commit 3eb28dc

Browse files
committed
Remove the note that suggests using @unchecked
`@unchecked Sendble` is dangerous, and almost always the wrong thing to use. Don't have the compiler suggest it. (cherry picked from commit a922e8e)
1 parent 6f43724 commit 3eb28dc

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
@@ -2771,9 +2771,6 @@ WARNING(remove_package_import,none,
27712771
WARNING(public_decl_needs_sendable,none,
27722772
"public %kind0 does not specify whether it is 'Sendable' or not",
27732773
(const ValueDecl *))
2774-
NOTE(explicit_unchecked_sendable,none,
2775-
"add '@unchecked Sendable' conformance to %kind0 if this type manually implements concurrency safety",
2776-
(const ValueDecl *))
27772774
NOTE(explicit_disable_sendable,none,
27782775
"make %kind0 explicitly non-Sendable to suppress this warning",
27792776
(const ValueDecl *))

lib/Sema/TypeCheckConcurrency.cpp

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

1389-
auto note = nominal->diagnose(
1390-
isUnchecked ? diag::explicit_unchecked_sendable
1391-
: diag::add_nominal_sendable_conformance,
1392-
nominal);
1393-
if (canMakeSendable && !requirements.empty()) {
1394-
// Produce a Fix-It containing a conditional conformance to Sendable,
1395-
// based on the requirements harvested from instance storage.
1396-
1397-
// Form the where clause containing all of the requirements.
1398-
SmallString<64> whereClause;
1399-
{
1400-
llvm::raw_svector_ostream out(whereClause);
1401-
llvm::interleaveComma(
1402-
requirements, out,
1403-
[&](const Requirement &req) {
1404-
out << req.getFirstType().getString() << ": "
1405-
<< req.getSecondType().getString();
1406-
});
1407-
}
1408-
1409-
// Add a Fix-It containing the conditional extension text itself.
1410-
auto insertionLoc = nominal->getBraces().End;
1411-
note.fixItInsertAfter(
1412-
insertionLoc,
1413-
("\n\nextension " + nominal->getName().str() + ": "
1414-
+ (isUnchecked? "@unchecked " : "") + "Sendable where " +
1415-
whereClause + " { }\n").str());
1416-
} else {
1417-
addSendableFixIt(nominal, note, isUnchecked);
1389+
// If we can only make the type Sendable via @unchecked, don't provide a Fix-It.
1390+
if (!isUnchecked) {
1391+
auto note = nominal->diagnose(diag::add_nominal_sendable_conformance, nominal);
1392+
if (canMakeSendable && !requirements.empty()) {
1393+
// Produce a Fix-It containing a conditional conformance to Sendable,
1394+
// based on the requirements harvested from instance storage.
1395+
1396+
// Form the where clause containing all of the requirements.
1397+
SmallString<64> whereClause;
1398+
{
1399+
llvm::raw_svector_ostream out(whereClause);
1400+
llvm::interleaveComma(
1401+
requirements, out,
1402+
[&](const Requirement &req) {
1403+
out << req.getFirstType().getString() << ": "
1404+
<< req.getSecondType().getString();
1405+
});
1406+
}
1407+
1408+
// Add a Fix-It containing the conditional extension text itself.
1409+
auto insertionLoc = nominal->getBraces().End;
1410+
note.fixItInsertAfter(
1411+
insertionLoc,
1412+
("\n\nextension " + nominal->getName().str() + ": "
1413+
+ "Sendable where " + whereClause + " { }\n").str());
1414+
} else {
1415+
addSendableFixIt(nominal, note, isUnchecked);
1416+
}
14181417
}
14191418
}
14201419

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)