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

Commit 7407e5c

Browse files
authored
Merge branch 'main' into fungible-asset-faq
2 parents ecc1427 + 0953a69 commit 7407e5c

File tree

2 files changed

+52
-1
lines changed

2 files changed

+52
-1
lines changed

apps/nextra/pages/en/build/smart-contracts/book/functions.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -773,7 +773,7 @@ struct S has key {
773773

774774
### Operations on Functions
775775

776-
A function value is evaluated by providing the corresponding number of parameters, similar as when calling a named function. During evaluation, the function value is *consumed*. Hence if the value needs to be evaluated multiple times, it's type must have the `copy` ability:
776+
A function value is evaluated by providing the corresponding number of parameters, similar as when calling a named function. During evaluation, the function value is *consumed*. Hence if the value needs to be evaluated multiple times, its type must have the `copy` ability:
777777

778778
```move
779779
let f: |u64|bool has copy = |x| x > 0;

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

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,31 @@ If you find any issues, please submit [bugs and feedback](https://github.com/apt
1212

1313

1414
## Lint Checks
15+
16+
### `aborting_overflow_checks`
17+
18+
Checks for patterns that look like overflow checks done in a C style:
19+
```move
20+
// Overflow check
21+
if (x > x + y) {
22+
abort 1;
23+
};
24+
25+
// Underflow check
26+
if (x < x - y) {
27+
abort 1;
28+
};
29+
```
30+
This pattern in Move does not make sense, as it either aborts immediately or is always true/false.
31+
1532
### `almost_swapped`
1633
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:
1734
- `a = b; b = a;` which can be correctly swapped with `(a, b) = (b, a);`
1835
- `a.x = b.x; b.x = a.x;` which can be correctly swapped with `(a.x, b.x) = (b.x, a.x);`
1936

37+
### `assert_const`
38+
Checks for trivial assertions, i.e. `assert!(false)` and `assert!(true)`. The latter is equivalent to a no-op, so can be removed entirely, while the former can be replaced by an abort.
39+
2040
### `avoid_copy_on_identity_comparison`
2141

2242
Checks for identity comparisons (`==` or `!=`) between copied values of type `vector` or `struct` (i.e., types for which copy can be expensive). It instead suggests to use reference-based identity comparison instead (i.e., use `&x == &y` instead of `x == y`, when the above mentioned conditions meet).
@@ -39,6 +59,16 @@ It is a common Move pattern to provide inline specifications in conditions, espe
3959

4060
Note that an `assert!` is translated to a conditional abort, so blocks in `assert!` condition also are reported by this lint.
4161

62+
### `known_to_abort`
63+
64+
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.
65+
66+
The following cases are detected:
67+
68+
- **Bit shifts with excessive shift amounts**: `x << n` or `x >> n` where `n` is a constant that is greater than or equal to the bit width of `x`'s type. For example, `value << 64` when `value` is of type `u64` will always abort.
69+
- **Division or modulo by zero**: `x / 0` or `x % 0` operations will always abort at runtime.
70+
- **Out-of-range type casting**: `constant as type` where the `constant` value is outside the representable range of the target `type`. For example, `300 as u8` will abort since `u8` can only represent values 0-255.
71+
4272
### `needless_bool`
4373

4474
Checks for patterns of the form (where `x` is any arbitrary boolean expression):
@@ -101,6 +131,27 @@ Checks for patterns where a variable or a field of a struct is assigned to itsel
101131
- `x = x;`
102132
- `a.x = a.x;`
103133

134+
### `simpler_bool_expression`
135+
136+
Checks for boolean patterns that can be simplified through different boolean algebra laws. Examples include:
137+
- Absorption law:
138+
- `a && b || a` can be simplified to `a`
139+
- `a || a && b` can be simplified to `a`
140+
- Idempotence:
141+
- `a && a` can be simplified to `a`
142+
- `a || a` can be simplified to `a`
143+
- Contradiction
144+
- `a && !a` can be simplified to `false`
145+
- `!a && a` can be simplified to `false`
146+
- Tautology:
147+
- `a || !a` can be simplified to `true`
148+
- `!a || a` can be simplified to `true`
149+
- Distributive law:
150+
- `(a && b) || (a && c)` can be simplified to `a && (b || c)`
151+
- `(a || b) && (a || c)` can be simplified to `a || (b && c)`
152+
153+
Where `a`, `b` and `c` can either be simple or composed expressions.
154+
104155
### `simpler_numeric_expression`
105156

106157
Checks for various patterns where a simpler numeric expression can be used instead. In all these cases, the code must already type check, and `x` can be any numeric expression.

0 commit comments

Comments
 (0)