Deny overflowing (and lossy) integer type cast operations #1895
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Closes #_ (N/A)
ink
orpallet-contracts
?Enables clippy lints for overflowing (and lossy) integer type cast operations (i.e.
as
conversions)Description
#1190 "Disallow[ed] unchecked arithmetic", but from this comment, it looks like the actual intent was to "guarantee that implicit overflows never happen", if that's the case then like the
-C overflow-checks
forrustc
,-Dclippy::arithmetic_side_effects
is actually NOT sufficient.This is because type cast operations (i.e.
as
conversions) can also cause implicit overflows/underflows (as well as other lossy conversions).This PR enables additional clippy lints (see list below) to "guarantee that overflowing/underflowing and lossy integer operations never happen (in the local crate)".
NOTE: We intentionally ignore safe/lossless lints (e.g.
cast_lossless
), and lints where either the source or target type is not an integer type (e.g.cast_precision_loss
,char_lit_as_u8
,as_conversions
e.t.c).References:
https://rust-lang.github.io/rfcs/0560-integer-overflow.html#updates-since-being-accepted
rust-lang/rfcs#1019
https://doc.rust-lang.org/reference/expressions/operator-expr.html#semantics
https://doc.rust-lang.org/reference/expressions/operator-expr.html#overflow
Checklist before requesting a review
CHANGELOG.md