From bb61d2fb53eb60c28fe859e6a2a8f91f587b6627 Mon Sep 17 00:00:00 2001 From: Thomas Churchman Date: Thu, 15 Jan 2026 14:53:31 +0100 Subject: [PATCH] Add `clippy::cast_possible_wrap` to the lint set `clippy::cast_possible_wrap` checks for casting an unsigned integer to a signed integer of the same size. If the value is too large to fit in the signed integer, it will wrap around to negative numbers. Such casts will usually be used when doing some math, so scrutiny of the cast is probably welcome. It's similar to the already-enabled `clippy::cast_possible_truncation`. See https://github.com/linebender/vello/pull/1364 for an example where the lint is useful. The similar lint `clippy::cast_sign_loss` more or less does the opposite, triggering for casts from signed to unsigned numeric types. Floats are included in this lint, as they do a saturating cast, making it more likely to have false positives: it triggers 65 times on `vello_common` currently. Perhaps this one should not be added to the canonical lint set. --- content/wiki/canonical_lints.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/content/wiki/canonical_lints.md b/content/wiki/canonical_lints.md index 9b7165d1..12e48952 100644 --- a/content/wiki/canonical_lints.md +++ b/content/wiki/canonical_lints.md @@ -11,7 +11,7 @@ All Linebender projects should include the following set of lints: # This one may vary depending on the project. rust.unsafe_code = "forbid" -# LINEBENDER LINT SET - Cargo.toml - v7 +# LINEBENDER LINT SET - Cargo.toml - v8 # See https://linebender.org/wiki/canonical-lints/ rust.keyword_idents_2024 = "forbid" rust.non_ascii_idents = "forbid" @@ -33,6 +33,7 @@ clippy.too_many_arguments = "allow" clippy.allow_attributes_without_reason = "warn" clippy.cast_possible_truncation = "warn" +clippy.cast_possible_wrap = "warn" clippy.collection_is_never_read = "warn" clippy.default_trait_access = "warn" clippy.dbg_macro = "warn"