diff --git a/all-is-cubes-base/src/lib.rs b/all-is-cubes-base/src/lib.rs index fa8ec9367..ce581d9c3 100644 --- a/all-is-cubes-base/src/lib.rs +++ b/all-is-cubes-base/src/lib.rs @@ -2,6 +2,7 @@ #![move_size_limit = "256"] #![feature(let_chains)] #![feature(never_type)] +#![feature(try_blocks)] //! This library is an internal component of [`all-is-cubes`], //! which defines some core mathematical types and functions. diff --git a/all-is-cubes-base/src/math/grid_aab.rs b/all-is-cubes-base/src/math/grid_aab.rs index 9110ec9fc..f5acb7aef 100644 --- a/all-is-cubes-base/src/math/grid_aab.rs +++ b/all-is-cubes-base/src/math/grid_aab.rs @@ -170,18 +170,19 @@ impl GridAab { ) -> Result { #[inline] fn inner(lower_bounds: GridPoint, size: GridSize) -> Result { - let upper_bounds = (|| { - Some(GridPoint::new( + match try { + GridPoint::new( lower_bounds.x.checked_add_unsigned(size.width)?, lower_bounds.y.checked_add_unsigned(size.height)?, lower_bounds.z.checked_add_unsigned(size.depth)?, - )) - })() - .ok_or(GridOverflowError(OverflowKind::OverflowedSize { - lower_bounds, - size, - }))?; - GridAab::checked_from_lower_upper(lower_bounds, upper_bounds) + ) + } { + Some(upper_bounds) => GridAab::checked_from_lower_upper(lower_bounds, upper_bounds), + None => Err(GridOverflowError(OverflowKind::OverflowedSize { + lower_bounds, + size, + })), + } } inner(lower_bounds.into(), size.into()) diff --git a/all-is-cubes/src/block/eval/control.rs b/all-is-cubes/src/block/eval/control.rs index 775857df2..b52660a26 100644 --- a/all-is-cubes/src/block/eval/control.rs +++ b/all-is-cubes/src/block/eval/control.rs @@ -194,8 +194,8 @@ impl Cost { /// Compute a cost from change in budget. pub(crate) fn from_difference(original_budget: Budget, final_budget: Budget) -> Self { - let Some(new_self) = (|| { - Some(Self { + let Some(new_self) = (try { + Self { components: original_budget .components .checked_sub(final_budget.components)?, @@ -203,8 +203,8 @@ impl Cost { recursion: original_budget .recursion_used .checked_sub(final_budget.recursion_used)?, - }) - })() else { + } + }) else { panic!("overflow computing budget difference: {final_budget:#?} - {original_budget:#?}") }; new_self diff --git a/all-is-cubes/src/lib.rs b/all-is-cubes/src/lib.rs index 3823d0bfb..15f04e7db 100644 --- a/all-is-cubes/src/lib.rs +++ b/all-is-cubes/src/lib.rs @@ -5,6 +5,7 @@ #![feature(let_chains)] #![feature(never_type)] #![feature(trait_upcasting)] +#![feature(try_blocks)] //! All is Cubes is a game/engine for worlds made of cubical blocks, where the blocks //! are themselves made of “smaller” blocks (voxels) that define their appearance and