Skip to content

Commit 29d904f

Browse files
committed
[SE-0458] Don't warn about unsafe conformances outside of strict safety mode
1 parent 068fd14 commit 29d904f

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

lib/Sema/TypeCheckUnsafe.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,13 @@ bool swift::enumerateUnsafeUses(ArrayRef<ProtocolConformanceRef> conformances,
296296
SourceLoc loc,
297297
llvm::function_ref<bool(UnsafeUse)> fn) {
298298
for (auto conformance : conformances) {
299+
if (conformance.isInvalid())
300+
continue;
301+
302+
ASTContext &ctx = conformance.getRequirement()->getASTContext();
303+
if (!ctx.LangOpts.hasFeature(Feature::WarnUnsafe))
304+
return false;
305+
299306
if (!conformance.hasEffect(EffectKind::Unsafe))
300307
continue;
301308

test/Unsafe/unsafe_in_unsafe.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// RUN: %target-typecheck-verify-swift -enable-experimental-feature AllowUnsafeAttribute -print-diagnostic-groups
2+
3+
// REQUIRES: swift_feature_AllowUnsafeAttribute
4+
5+
6+
protocol P { }
7+
8+
struct X: @unsafe P { }
9+
10+
func returnMe(x: X) -> any P {
11+
x
12+
}

0 commit comments

Comments
 (0)