# prefer-exclusive-range

Prefer exclusive ranges over inclusive ranges offset by one

An inclusive range ending one below its upper bound expresses exclusion through extra arithmetic.
Instead, you SHOULD write the upper bound directly with `..`.

The rewritten range has type `Range<T>` rather than `RangeInclusive<T>`.
The rewritten range does not preserve an overflow trap when the upper bound is the minimum integer.

- Category: style
- Level: warning
- Fix: suggestion
- Scope: module

## Reported

```ds title="main.ds"
declare const start: int32;
declare const end: int32;

const before = start..=end - 1;
```

## Accepted

```ds title="main.ds"
declare const start: int32;
declare const end: int32;

const before = start..end;
```

## Prior art

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

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