File tree Expand file tree Collapse file tree 2 files changed +24
-1
lines changed Expand file tree Collapse file tree 2 files changed +24
-1
lines changed Original file line number Diff line number Diff line change @@ -4309,7 +4309,8 @@ class CheckEffectsCoverage : public EffectsHandlingWalker<CheckEffectsCoverage>
43094309 Ctx.Diags .diagnose (S->getForLoc (), diag::for_unsafe_without_unsafe)
43104310 .fixItInsert (insertionLoc, " unsafe " );
43114311 }
4312- } else if (S->getUnsafeLoc ().isValid ()) {
4312+ } else if (S->getUnsafeLoc ().isValid () &&
4313+ Ctx.LangOpts .hasFeature (Feature::StrictMemorySafety)) {
43134314 // Extraneous "unsafe" on the sequence.
43144315 Ctx.Diags .diagnose (S->getUnsafeLoc (), diag::no_unsafe_in_unsafe_for)
43154316 .fixItRemove (S->getUnsafeLoc ());
@@ -4343,6 +4344,9 @@ class CheckEffectsCoverage : public EffectsHandlingWalker<CheckEffectsCoverage>
43434344 }
43444345
43454346 void diagnoseRedundantUnsafe (UnsafeExpr *E) const {
4347+ if (!Ctx.LangOpts .hasFeature (Feature::StrictMemorySafety))
4348+ return ;
4349+
43464350 if (auto *SVE = SingleValueStmtExpr::tryDigOutSingleValueStmtExpr (E)) {
43474351 // For an if/switch expression, produce a tailored warning.
43484352 Ctx.Diags .diagnose (E->getUnsafeLoc (),
@@ -4351,6 +4355,7 @@ class CheckEffectsCoverage : public EffectsHandlingWalker<CheckEffectsCoverage>
43514355 .highlight (E->getUnsafeLoc ());
43524356 return ;
43534357 }
4358+
43544359 Ctx.Diags .diagnose (E->getUnsafeLoc (), diag::no_unsafe_in_unsafe);
43554360 }
43564361
Original file line number Diff line number Diff line change 1+ // RUN: %target-typecheck-verify-swift -print-diagnostic-groups
2+
3+ @unsafe func unsafeFunc( ) { }
4+
5+ @unsafe
6+ struct UnsafeType { }
7+
8+ protocol P { }
9+
10+ struct X : @unsafe P { }
11+
12+ func acceptP< T: P > ( _: T ) { }
13+
14+ func testItAll( ut: UnsafeType , x: X , i: Int ) {
15+ _ = unsafe ut
16+ unsafe acceptP( x)
17+ _ = unsafe i
18+ }
You can’t perform that action at this time.
0 commit comments