mirror of
https://github.com/apple/swift.git
synced 2026-06-20 15:42:51 +02:00
cf5ed12f62
When an `if` or `guard` statement is diagnosed as always succeeding, emit a
fix-it that removes the redundant statement. For `if`, the then-branch body
replaces the entire statement, dedented to match the surrounding indentation
level, like this:
```
// Before
if case let _ = x {
doSomething()
} else {
// ...
}
// After
doSomething()
```
For `guard`, the entire statement is removed (its body is unreachable). For an
`else if` branch, the inner `if` is replaced with just its body braces, turning
`else if X { body } [else ...]` into `else { body }` and discarding any
now-unreachable trailing branches.
No fix-it is offered for `while`, since removing the always-true condition
would produce an unconditional infinite loop.
Resolves rdar://178194980.