Skip to content

Commit 9570e1e

Browse files
committed
[SE-0458] Add fix-it for removing unnecessary "unsafe" keywords
1 parent 4742d2c commit 9570e1e

File tree

3 files changed

+5
-4
lines changed

3 files changed

+5
-4
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8242,9 +8242,9 @@ GROUPED_WARNING(unsafe_without_unsafe,StrictMemorySafety,none,
82428242
"expression uses unsafe constructs but is not marked with 'unsafe'", ())
82438243
GROUPED_WARNING(for_unsafe_without_unsafe,StrictMemorySafety,none,
82448244
"for-in loop uses unsafe constructs but is not marked with 'unsafe'", ())
8245-
WARNING(no_unsafe_in_unsafe,none,
8245+
GROUPED_WARNING(no_unsafe_in_unsafe,StrictMemorySafety,none,
82468246
"no unsafe operations occur within 'unsafe' expression", ())
8247-
WARNING(no_unsafe_in_unsafe_for,none,
8247+
GROUPED_WARNING(no_unsafe_in_unsafe_for,StrictMemorySafety,none,
82488248
"no unsafe operations occur within 'unsafe' for-in loop", ())
82498249
NOTE(make_subclass_unsafe,none,
82508250
"make class %0 @unsafe to allow unsafe overrides of safe superclass methods",

lib/Sema/TypeCheckEffects.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4420,7 +4420,8 @@ class CheckEffectsCoverage : public EffectsHandlingWalker<CheckEffectsCoverage>
44204420
return;
44214421
}
44224422

4423-
Ctx.Diags.diagnose(E->getUnsafeLoc(), diag::no_unsafe_in_unsafe);
4423+
Ctx.Diags.diagnose(E->getUnsafeLoc(), diag::no_unsafe_in_unsafe)
4424+
.fixItRemove(E->getUnsafeLoc());
44244425
}
44254426

44264427
std::pair<SourceLoc, std::string>

test/Unsafe/safe.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ func unsafeFun() {
195195
acceptBoolsUnsafeLabel(unsafe: unsafe, unsafe)
196196

197197
let color: Color
198-
// expected-warning@+1{{no unsafe operations occur within 'unsafe' expression}}
198+
// expected-warning@+1{{no unsafe operations occur within 'unsafe' expression}}{{11-18=}}
199199
color = unsafe .red
200200
_ = color
201201

0 commit comments

Comments
 (0)