From 262b068bc3695c666f8378be271039402427520f Mon Sep 17 00:00:00 2001 From: Federico Rinaldi Date: Tue, 17 Sep 2024 00:46:54 +0200 Subject: [PATCH] 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 --- crates/bevy_ecs/src/entity/mod.rs | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/crates/bevy_ecs/src/entity/mod.rs b/crates/bevy_ecs/src/entity/mod.rs index 93b1e78ffa..9182e6476b 100644 --- a/crates/bevy_ecs/src/entity/mod.rs +++ b/crates/bevy_ecs/src/entity/mod.rs @@ -553,12 +553,14 @@ impl Entities { // 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 // negative, meaning they are all new IDs to allocate, or a mix of both. - let range_end = self - .free_cursor - // Unwrap: these conversions can only fail on platforms that don't support 64-bit atomics - // and use AtomicIsize instead (see note on `IdCursor`). - .fetch_sub(IdCursor::try_from(count).unwrap(), Ordering::Relaxed); - let range_start = range_end - IdCursor::try_from(count).unwrap(); + let range_end = self.free_cursor.fetch_sub( + IdCursor::try_from(count) + .expect("64-bit atomic operations are not supported on this platform."), + Ordering::Relaxed, + ); + 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; @@ -745,9 +747,9 @@ impl Entities { self.verify_flushed(); let freelist_size = *self.free_cursor.get_mut(); - // Unwrap: these conversions can only fail on platforms that don't support 64-bit atomics - // and use AtomicIsize instead (see note on `IdCursor`). - let shortfall = IdCursor::try_from(additional).unwrap() - freelist_size; + let shortfall = IdCursor::try_from(additional) + .expect("64-bit atomic operations are not supported on this platform.") + - freelist_size; if shortfall > 0 { self.meta.reserve(shortfall as usize); }