# no-mutated-range-bound

Disallow mutating range bounds during iteration over that range

A range captures its bounds before iteration, so mutating their source storage cannot change the active traversal.
Instead, you SHOULD leave captured bounds unchanged or use a conditional loop when each iteration must observe an updated bound.

- Category: suspicious
- Level: warning
- Fix: none
- Scope: module

## Reported

```ds title="main.ds"
function visit(limit: int32): void {
    let end = limit;
    for (const value of 0..end) {
        end -= 1;
        value;
    }
}
```

## Accepted

```ds title="main.ds"
function visit(limit: int32): void {
    let end = limit;
    for (const value of 0..end) {
        value;
    }
}
```

## Prior art

- [Clippy · mut_range_bound](https://rust-lang.github.io/rust-clippy/master/index.html#mut_range_bound)

[language/linter/src/rules/suspicious/no_mutated_range_bound.rs:8](https://github.com/destack-sh/destack/blob/main/language/linter/src/rules/suspicious/no_mutated_range_bound.rs#L8)
