Skip to content
This repository was archived by the owner on Jul 30, 2025. It is now read-only.

Commit 08f6046

Browse files
authored
Add find_unnecessary_casts documentation (#1022)
1 parent a3a7a7f commit 08f6046

File tree

1 file changed

+19
-3
lines changed
  • apps/nextra/pages/en/build/smart-contracts

1 file changed

+19
-3
lines changed

apps/nextra/pages/en/build/smart-contracts/linter.mdx

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,16 @@ If you find any issues, please submit [bugs and feedback](https://github.com/apt
1818
Checks for patterns that look like overflow checks done in a C style:
1919
```move
2020
// Overflow check
21-
if (x > x + y) {
21+
if (x > x + y) {
2222
abort 1;
2323
};
2424
2525
// Underflow check
26-
if (x < x - y) {
26+
if (x < x - y) {
2727
abort 1;
2828
};
2929
```
30-
This pattern in Move does not make sense, as it either aborts immediately or is always true/false.
30+
This pattern in Move does not make sense, as it either aborts immediately or is always true/false.
3131

3232
### `almost_swapped`
3333
Checks for expression patterns that look like a failed swap attempt and notifies the user. These patterns are likely erroneous code. This currently only detects simple access patterns such as assignments to a variable or a field of a struct. Examples include:
@@ -65,6 +65,22 @@ Checks for binary operations where both operands are the same, which is likely a
6565

6666
This lint does not catch cases where the operands are vector access.
6767

68+
### `find_unnecessary_casts`
69+
70+
Checks for unnecessary type casts where the source expression already has the same type as the target type. These casts are redundant and can be removed to improve code readability.
71+
72+
For example:
73+
```move
74+
let x: u64 = 42;
75+
let y = x as u64; // unnecessary cast, x is already u64
76+
```
77+
78+
The above can be simplified to:
79+
```move
80+
let x: u64 = 42;
81+
let y = x; // cast removed
82+
```
83+
6884
### `known_to_abort`
6985

7086
Checks for expressions that will always abort at runtime due to known constant values that violate runtime constraints. This lint helps identify code that will deterministically fail before it reaches production.

0 commit comments

Comments
 (0)