more clippy fixes and/or whitelists
Some checks failed
Rust / build (pull_request) Failing after 1m6s
Some checks failed
Rust / build (pull_request) Failing after 1m6s
This commit is contained in:
parent
5ba01ec4cc
commit
9f239ec71d
6 changed files with 47 additions and 13 deletions
10
Cargo.toml
10
Cargo.toml
|
|
@ -65,18 +65,26 @@ refining_impl_trait_reachable = "warn"
|
|||
rust-2024-compatibility = "warn"
|
||||
|
||||
[lints.clippy]
|
||||
## Categories
|
||||
complexity = {level = "warn", priority = -1 }
|
||||
perf = {level = "warn", priority = -1 }
|
||||
style = {level = "warn", priority = -1 }
|
||||
pedantic = {level = "warn", priority = -1 }
|
||||
|
||||
## Blacklist
|
||||
unwrap_used = "warn"
|
||||
expect_used = "warn"
|
||||
panic = "warn"
|
||||
incompatible_msrv = "forbid"
|
||||
allow_attributes_without_reason = "warn"
|
||||
|
||||
# too many false positives as often the module only contains the one struct
|
||||
## Whitelist
|
||||
# Too many false positives as often a module only contains one struct that is re-exported at top-level
|
||||
module_name_repetitions = "allow"
|
||||
# The pretty detailed exception types should be enough for now
|
||||
missing_errors_doc = "allow"
|
||||
# The few places where a panic is triggered in code are inspected and should never panic
|
||||
missing_panics_doc = "allow"
|
||||
|
||||
[lints.rustdoc]
|
||||
private_doc_tests = "warn"
|
||||
|
|
|
|||
|
|
@ -115,10 +115,10 @@ fn check_command_code(
|
|||
actual: u16,
|
||||
expected: CommandCode,
|
||||
) -> Result<(), TryFromPacketError> {
|
||||
if actual != u16::from(expected) {
|
||||
Err(TryFromPacketError::InvalidCommand(actual))
|
||||
} else {
|
||||
if actual == u16::from(expected) {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(TryFromPacketError::InvalidCommand(actual))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -33,6 +33,8 @@ impl Bitmap {
|
|||
/// - `height`: size in pixels in y-direction
|
||||
#[must_use]
|
||||
pub fn new(width: usize, height: usize) -> Option<Self> {
|
||||
assert!(width < isize::MAX as usize);
|
||||
assert!(height < isize::MAX as usize);
|
||||
if width % 8 != 0 {
|
||||
return None;
|
||||
}
|
||||
|
|
@ -73,6 +75,8 @@ impl Bitmap {
|
|||
height: usize,
|
||||
data: &[u8],
|
||||
) -> Result<Self, LoadBitmapError> {
|
||||
assert!(width < isize::MAX as usize);
|
||||
assert!(height < isize::MAX as usize);
|
||||
if width % 8 != 0 {
|
||||
return Err(LoadBitmapError::InvalidWidth);
|
||||
}
|
||||
|
|
@ -103,6 +107,8 @@ impl Bitmap {
|
|||
}
|
||||
let len = bit_vec.len();
|
||||
let height = len / width;
|
||||
assert!(width < isize::MAX as usize);
|
||||
assert!(height < isize::MAX as usize);
|
||||
if len % width != 0 {
|
||||
return Err(LoadBitmapError::InvalidDataSize);
|
||||
}
|
||||
|
|
@ -154,6 +160,7 @@ impl Bitmap {
|
|||
/// }
|
||||
/// ```
|
||||
#[must_use]
|
||||
#[allow(clippy::iter_without_into_iter)]
|
||||
pub fn iter_mut(&mut self) -> IterMut<u8, Msb0> {
|
||||
self.bit_vec.iter_mut()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -231,7 +231,7 @@ impl From<&CharGrid> for Vec<u8> {
|
|||
/// let grid = CharGrid::load_utf8(width, height, grid.into());
|
||||
/// ```
|
||||
fn from(value: &CharGrid) -> Self {
|
||||
String::from_iter(value.iter()).into_bytes()
|
||||
value.iter().collect::<String>().into_bytes()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -31,6 +31,10 @@ pub trait Grid<T> {
|
|||
/// returns: Value at position or None
|
||||
fn get_optional(&self, x: isize, y: isize) -> Option<T> {
|
||||
if self.is_in_bounds(x, y) {
|
||||
#[expect(
|
||||
clippy::cast_sign_loss,
|
||||
reason = "is_in_bounds already checks this"
|
||||
)]
|
||||
Some(self.get(x as usize, y as usize))
|
||||
} else {
|
||||
None
|
||||
|
|
@ -46,6 +50,10 @@ pub trait Grid<T> {
|
|||
/// returns: the old value or None
|
||||
fn set_optional(&mut self, x: isize, y: isize, value: T) -> bool {
|
||||
if self.is_in_bounds(x, y) {
|
||||
#[expect(
|
||||
clippy::cast_sign_loss,
|
||||
reason = "is_in_bounds already checks this"
|
||||
)]
|
||||
self.set(x as usize, y as usize, value);
|
||||
true
|
||||
} else {
|
||||
|
|
@ -63,6 +71,10 @@ pub trait Grid<T> {
|
|||
fn height(&self) -> usize;
|
||||
|
||||
/// Checks whether the specified signed position is in grid bounds
|
||||
#[expect(
|
||||
clippy::cast_possible_wrap,
|
||||
reason = "implementing types only allow 0..isize::MAX"
|
||||
)]
|
||||
fn is_in_bounds(&self, x: isize, y: isize) -> bool {
|
||||
x >= 0
|
||||
&& x < self.width() as isize
|
||||
|
|
|
|||
|
|
@ -52,6 +52,8 @@ impl<T: Value> ValueGrid<T> {
|
|||
/// returns: [`ValueGrid`] initialized to default value.
|
||||
#[must_use]
|
||||
pub fn new(width: usize, height: usize) -> Self {
|
||||
assert!(width < isize::MAX as usize);
|
||||
assert!(height < isize::MAX as usize);
|
||||
Self {
|
||||
data: vec![Default::default(); width * height],
|
||||
width,
|
||||
|
|
@ -65,6 +67,8 @@ impl<T: Value> ValueGrid<T> {
|
|||
/// or None if the dimensions do not match the data size.
|
||||
#[must_use]
|
||||
pub fn load(width: usize, height: usize, data: &[T]) -> Option<Self> {
|
||||
assert!(width < isize::MAX as usize);
|
||||
assert!(height < isize::MAX as usize);
|
||||
if width * height != data.len() {
|
||||
return None;
|
||||
}
|
||||
|
|
@ -92,6 +96,8 @@ impl<T: Value> ValueGrid<T> {
|
|||
pub fn from_vec(width: usize, data: Vec<T>) -> Option<Self> {
|
||||
let len = data.len();
|
||||
let height = len / width;
|
||||
assert!(width < isize::MAX as usize);
|
||||
assert!(height < isize::MAX as usize);
|
||||
if len % width != 0 {
|
||||
return None;
|
||||
}
|
||||
|
|
@ -171,6 +177,10 @@ impl<T: Value> ValueGrid<T> {
|
|||
y: isize,
|
||||
) -> Option<&mut T> {
|
||||
if self.is_in_bounds(x, y) {
|
||||
#[expect(
|
||||
clippy::cast_sign_loss,
|
||||
reason = "is_in_bounds already checks this"
|
||||
)]
|
||||
Some(&mut self.data[x as usize + y as usize * self.width])
|
||||
} else {
|
||||
None
|
||||
|
|
@ -283,14 +293,11 @@ impl<T: Value> ValueGrid<T> {
|
|||
});
|
||||
}
|
||||
|
||||
let chunk = match self.data.chunks_exact_mut(width).nth(y) {
|
||||
Some(row) => row,
|
||||
None => {
|
||||
return Err(SetValueSeriesError::OutOfBounds {
|
||||
size: self.height(),
|
||||
index: y,
|
||||
})
|
||||
}
|
||||
let Some(chunk) = self.data.chunks_exact_mut(width).nth(y) else {
|
||||
return Err(SetValueSeriesError::OutOfBounds {
|
||||
size: self.height(),
|
||||
index: y,
|
||||
});
|
||||
};
|
||||
|
||||
chunk.copy_from_slice(row);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue