From 1bbce5850751e1301643d294ccee94fe1f2dd322 Mon Sep 17 00:00:00 2001 From: Uwe Klotz Date: Fri, 4 Feb 2022 14:46:59 +0100 Subject: [PATCH] Prevent unintended truncation on numerical casts --- src/codec/mod.rs | 2 ++ src/lib.rs | 1 + 2 files changed, 3 insertions(+) diff --git a/src/codec/mod.rs b/src/codec/mod.rs index 0837fba1..a05ee6f2 100644 --- a/src/codec/mod.rs +++ b/src/codec/mod.rs @@ -12,6 +12,7 @@ use bytes::{BufMut, Bytes, BytesMut}; use std::convert::TryFrom; use std::io::{self, Cursor, Error, ErrorKind}; +#[allow(clippy::cast_possible_truncation)] fn u16_len(len: usize) -> u16 { // This type conversion should always be safe, because either // the caller is responsible to pass a valid usize or the @@ -20,6 +21,7 @@ fn u16_len(len: usize) -> u16 { len as u16 } +#[allow(clippy::cast_possible_truncation)] fn u8_len(len: usize) -> u8 { // This type conversion should always be safe, because either // the caller is responsible to pass a valid usize or the diff --git a/src/lib.rs b/src/lib.rs index c0636fc1..3232e530 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -155,6 +155,7 @@ //#![deny(clippy::must_use_candidate)] #![cfg_attr(not(test), warn(unsafe_code))] #![cfg_attr(not(test), deny(clippy::panic_in_result_fn))] +#![cfg_attr(not(test), deny(clippy::cast_possible_truncation))] #![cfg_attr(not(debug_assertions), deny(warnings))] #![cfg_attr(not(debug_assertions), deny(clippy::used_underscore_binding))]