Substitute trivial fallible conversions with infallible function calls (#10846)

Clippy for rust 1.75 will introduce the
[`unnecessary_fallible_conversions`][1] lint. This PR solves the trivial
ones.

[1]:
https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_fallible_conversions
This commit is contained in:
Federico Rinaldi 2024-09-17 00:46:54 +02:00 committed by GitHub
parent 5a0c09d38f
commit 262b068bc3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -553,12 +553,14 @@ impl Entities {
// Use one atomic subtract to grab a range of new IDs. The range might be // Use one atomic subtract to grab a range of new IDs. The range might be
// entirely nonnegative, meaning all IDs come from the freelist, or entirely // entirely nonnegative, meaning all IDs come from the freelist, or entirely
// negative, meaning they are all new IDs to allocate, or a mix of both. // negative, meaning they are all new IDs to allocate, or a mix of both.
let range_end = self let range_end = self.free_cursor.fetch_sub(
.free_cursor IdCursor::try_from(count)
// Unwrap: these conversions can only fail on platforms that don't support 64-bit atomics .expect("64-bit atomic operations are not supported on this platform."),
// and use AtomicIsize instead (see note on `IdCursor`). Ordering::Relaxed,
.fetch_sub(IdCursor::try_from(count).unwrap(), Ordering::Relaxed); );
let range_start = range_end - IdCursor::try_from(count).unwrap(); let range_start = range_end
- IdCursor::try_from(count)
.expect("64-bit atomic operations are not supported on this platform.");
let freelist_range = range_start.max(0) as usize..range_end.max(0) as usize; let freelist_range = range_start.max(0) as usize..range_end.max(0) as usize;
@ -745,9 +747,9 @@ impl Entities {
self.verify_flushed(); self.verify_flushed();
let freelist_size = *self.free_cursor.get_mut(); let freelist_size = *self.free_cursor.get_mut();
// Unwrap: these conversions can only fail on platforms that don't support 64-bit atomics let shortfall = IdCursor::try_from(additional)
// and use AtomicIsize instead (see note on `IdCursor`). .expect("64-bit atomic operations are not supported on this platform.")
let shortfall = IdCursor::try_from(additional).unwrap() - freelist_size; - freelist_size;
if shortfall > 0 { if shortfall > 0 {
self.meta.reserve(shortfall as usize); self.meta.reserve(shortfall as usize);
} }