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 @@ -2691,10 +2691,28 @@ checkIndividualConformance(NormalProtocolConformance *conformance) {
2691
2691
}
2692
2692
2693
2693
if (!unsafeUses.empty ()) {
2694
- Context.Diags .diagnose (
2694
+ // Primary diagnostic along with a Fix-It to add @unsafe in the appropriate
2695
+ // place.
2696
+ {
2697
+ auto diag = Context.Diags .diagnose (
2695
2698
conformance->getLoc (), diag::conformance_involves_unsafe,
2696
- conformance->getType (), Proto)
2697
- .fixItInsert (conformance->getProtocolNameLoc (), " @unsafe " );
2699
+ conformance->getType (), Proto);
2700
+
2701
+ // Find the original explicit conformance, where we can add the Fix-It.
2702
+ auto explicitConformance = conformance;
2703
+ while (explicitConformance->getSourceKind () ==
2704
+ ConformanceEntryKind::Implied) {
2705
+ explicitConformance =
2706
+ explicitConformance->ProtocolConformance ::getImplyingConformance ();
2707
+ }
2708
+
2709
+ if (explicitConformance->getSourceKind () ==
2710
+ ConformanceEntryKind::Explicit) {
2711
+ diag.fixItInsert (explicitConformance->getProtocolNameLoc (),
2712
+ " @unsafe " );
2713
+ }
2714
+ }
2715
+
2698
2716
for (const auto & unsafeUse : unsafeUses)
2699
2717
diagnoseUnsafeUse (unsafeUse);
2700
2718
}
Original file line number Diff line number Diff line change @@ -359,3 +359,17 @@ func testSwitch(se: SomeEnum) {
359
359
360
360
if case unsafe someEnumValue = unsafe se { }
361
361
}
362
+
363
+ @unsafe class SomeClass { }
364
+ @unsafe class SomeClassWrapper { }
365
+
366
+ protocol Associated {
367
+ associatedtype Associated
368
+ }
369
+
370
+ protocol CustomAssociated : Associated { }
371
+
372
+ // expected-warning@+1{{conformance of 'SomeClass' to protocol 'Associated' involves unsafe code}}{{22-22=@unsafe }}
373
+ extension SomeClass : CustomAssociated {
374
+ typealias Associated = SomeClassWrapper // expected-note{{unsafe type 'SomeClass.Associated' (aka 'SomeClassWrapper') cannot satisfy safe associated type 'Associated'}}
375
+ }
You can’t perform that action at this time.
0 commit comments