ci: fail linting on truncated and wrapping casts #5233
Closed
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.
Description
Fails linting on possible truncated or wrapping casts. Various updates to address failures.
Closes #5478.
Motivation and Context
It was observed in another PR that truncated casts are not picked up by the linter. The
clippy::cast_possible_truncation
lint will catch this, but was disabled. Some of these casts may be risky, so it seems prudent to fail on them unless specifically allowed and documented.This PR enables the lint as a
deny
, as well as a related lint for wrapping. For each lint failure, it either uses anallow
(if the truncation is impossible or safe) or makes an update to fix it.Note that after PR 5237 is merged, it can be assumed that the target
usize
is not 32 bits.How Has This Been Tested?
It hasn't. This behavior occurs in multiple places (around a couple dozen) within the codebase; in each case, it needs to be decided if the cast is safe (in which case the lint can be selectively disabled) or risky (in which case it should be replaced). This should happen before the PR is merged.