---
title: Variable never mutated (VariableNeverMutated)
framework: Swift Compiler
role: article
role_heading: Article
path: swift-compiler/documentation/diagnostics/variable-never-mutated
---

# Variable never mutated (VariableNeverMutated)

Warnings that identify local var bindings which are never mutated after initialization and could instead be declared with let.

## Overview

Overview When a variable is introduced with var but never reassigned or otherwise mutated, it can be declared with let instead to explicitly indicate that the variable is constant. Example func swap(_ a: inout Int, _ b: inout Int) {   var temp = a // warning: variable 'temp' was never mutated; consider changing to 'let' constant   a = b   b = temp } The fix is to change var to let: func swap(_ a: inout Int, _ b: inout Int) {   let temp = a   a = b   b = temp } Sub-groups The VariableNeverMutated group contains the following sub-group, which can also be enabled or controlled independently: doc:weak-mutability: Warns when a weak var binding is never mutated and could be a weak let instead.

## See Also

- [@dynamicCallable implementation requirements (DynamicCallable)](swift-compiler/documentation/diagnostics/dynamic-callable-requirements.md)
- [Actors can’t conform to global actor protocols (ActorConformanceToGlobalActorProtocol)](swift-compiler/documentation/diagnostics/actors-cannot-conform-to-global-actor-protocols.md)
- [Add @preconcurrency import (AddPreconcurrencyImport)](swift-compiler/documentation/diagnostics/add-preconcurrency-import.md)
- [Always enabled availability domains (AlwaysAvailableDomain)](swift-compiler/documentation/diagnostics/always-available-domain.md)
- [Argument matching for trailing closures (TrailingClosureMatching)](swift-compiler/documentation/diagnostics/trailing-closure-matching.md)
- [Calling a mutating async actor-isolated method (ActorIsolatedMutatingAsync)](swift-compiler/documentation/diagnostics/actor-isolated-mutating-async.md)
- [Calling an actor-isolated method from a synchronous nonisolated context (ActorIsolatedCall)](swift-compiler/documentation/diagnostics/actor-isolated-call.md)
- [Captures in a `@Sendable` closure (SendableClosureCaptures)](swift-compiler/documentation/diagnostics/sendable-closure-captures.md)
- [Compilation caching (CompilationCaching)](swift-compiler/documentation/diagnostics/compilation-caching.md)
- [Conforming to `StringInterpolationProtocol` (StringInterpolationConformance)](swift-compiler/documentation/diagnostics/string-interpolation-conformance.md)
- [Conversion from `@isolated(any)` function type to synchronous function type (ConversionFromIsolatedAnyToSynchronous)](swift-compiler/documentation/diagnostics/conversion-from-isolated-any-to-synchronous.md)
- [Cross-isolation data race (RegionIsolationCrossIsolationDataRace)](swift-compiler/documentation/diagnostics/region-isolation-cross-isolation-data-race.md)
- [Deprecated declaration warnings (DeprecatedDeclaration)](swift-compiler/documentation/diagnostics/deprecated-declaration.md)
- [Deprecated implementation-only imports (ImplementationOnlyDeprecated)](swift-compiler/documentation/diagnostics/implementation-only-deprecated.md)
- [Dynamic exclusivity (DynamicExclusivity)](swift-compiler/documentation/diagnostics/dynamic-exclusivity.md)
