Unnecessary effect markers (UnnecessaryEffectMarker)
Overview
These warnings are emitted when an effect marker — try, await, or unsafe — appears on an expression that contains no operation requiring it. The marker may have been added preemptively, the operation it was needed for may have been removed, or the resolved expression may not contain the operation that was expected to carry the effect.
The UnnecessaryEffectMarker group covers:
tryon an expression that calls no throwing functionsawaiton an expression that performs noasyncoperationsunsafeon an expression that contains no unsafe operationsunsafeon afor-inloop whoseSequencehas a safe conformance
Example
func greet(_ name: String) {
print("Hello, \(name)") // not throwing, not async, not unsafe
}
func caller() async throws {
try greet("Ada") // warning: no calls to throwing functions occur within 'try' expression
await greet("Ada") // warning: no 'async' operations occur within 'await' expression
unsafe greet("Ada") // warning: no unsafe operations occur within 'unsafe' expression
}How to fix
Remove the marker:
func caller() async throws {
greet("Ada")
}See Also
Related Documentation
@dynamicCallable implementation requirements (DynamicCallable)Add @preconcurrency import (AddPreconcurrencyImport)Always enabled availability domains (AlwaysAvailableDomain)Argument matching for trailing closures (TrailingClosureMatching)Calling a mutating async actor-isolated method (ActorIsolatedMutatingAsync)Calling an actor-isolated method from a synchronous nonisolated context (ActorIsolatedCall)Captures in a `@Sendable` closure (SendableClosureCaptures)Compilation caching (CompilationCaching)Conforming to `StringInterpolationProtocol` (StringInterpolationConformance)Conversion from `@isolated(any)` function type to synchronous function type (ConversionFromIsolatedAnyToSynchronous)Cross-isolation data race (RegionIsolationCrossIsolationDataRace)Deprecated declaration warnings (DeprecatedDeclaration)Deprecated implementation-only imports (ImplementationOnlyDeprecated)Dynamic exclusivity (DynamicExclusivity)Embedded Swift language restrictions (EmbeddedRestrictions)