File tree Expand file tree Collapse file tree 2 files changed +35
-3
lines changed Expand file tree Collapse file tree 2 files changed +35
-3
lines changed Original file line number Diff line number Diff line change @@ -2695,10 +2695,28 @@ checkIndividualConformance(NormalProtocolConformance *conformance) {
2695
2695
}
2696
2696
2697
2697
if (!unsafeUses.empty ()) {
2698
- Context.Diags .diagnose (
2698
+ // Primary diagnostic along with a Fix-It to add @unsafe in the appropriate
2699
+ // place.
2700
+ {
2701
+ auto diag = Context.Diags .diagnose (
2699
2702
conformance->getLoc (), diag::conformance_involves_unsafe,
2700
- conformance->getType (), Proto)
2701
- .fixItInsert (conformance->getProtocolNameLoc (), " @unsafe " );
2703
+ conformance->getType (), Proto);
2704
+
2705
+ // Find the original explicit conformance, where we can add the Fix-It.
2706
+ auto explicitConformance = conformance;
2707
+ while (explicitConformance->getSourceKind () ==
2708
+ ConformanceEntryKind::Implied) {
2709
+ explicitConformance =
2710
+ explicitConformance->ProtocolConformance ::getImplyingConformance ();
2711
+ }
2712
+
2713
+ if (explicitConformance->getSourceKind () ==
2714
+ ConformanceEntryKind::Explicit) {
2715
+ diag.fixItInsert (explicitConformance->getProtocolNameLoc (),
2716
+ " @unsafe " );
2717
+ }
2718
+ }
2719
+
2702
2720
for (const auto & unsafeUse : unsafeUses)
2703
2721
diagnoseUnsafeUse (unsafeUse);
2704
2722
}
Original file line number Diff line number Diff line change @@ -352,3 +352,17 @@ func testSwitch(se: SomeEnum) {
352
352
default : break
353
353
}
354
354
}
355
+
356
+ @unsafe class SomeClass { }
357
+ @unsafe class SomeClassWrapper { }
358
+
359
+ protocol Associated {
360
+ associatedtype Associated
361
+ }
362
+
363
+ protocol CustomAssociated : Associated { }
364
+
365
+ // expected-warning@+1{{conformance of 'SomeClass' to protocol 'Associated' involves unsafe code}}{{22-22=@unsafe }}
366
+ extension SomeClass : CustomAssociated {
367
+ typealias Associated = SomeClassWrapper // expected-note{{unsafe type 'SomeClass.Associated' (aka 'SomeClassWrapper') cannot satisfy safe associated type 'Associated'}}
368
+ }
You can’t perform that action at this time.
0 commit comments