diff --git a/all-is-cubes-base/src/math/grid_aab.rs b/all-is-cubes-base/src/math/grid_aab.rs index cc85cac14..b85b5565f 100644 --- a/all-is-cubes-base/src/math/grid_aab.rs +++ b/all-is-cubes-base/src/math/grid_aab.rs @@ -1013,9 +1013,7 @@ impl fmt::Display for OverflowKind { } } -crate::util::cfg_should_impl_error! { - impl crate::util::ErrorIfStd for GridOverflowError {} -} +impl core::error::Error for GridOverflowError {} /// `Debug`-formatting helper struct RangeWithLength(Range); diff --git a/all-is-cubes-base/src/math/vol.rs b/all-is-cubes-base/src/math/vol.rs index 5f874c446..f76750efe 100644 --- a/all-is-cubes-base/src/math/vol.rs +++ b/all-is-cubes-base/src/math/vol.rs @@ -741,9 +741,7 @@ pub struct VolLengthError { bounds: GridAab, } -crate::util::cfg_should_impl_error! { - impl crate::util::ErrorIfStd for VolLengthError {} -} +impl core::error::Error for VolLengthError {} impl fmt::Display for VolLengthError { #[allow(clippy::missing_inline_in_public_items)] diff --git a/all-is-cubes-base/src/resolution.rs b/all-is-cubes-base/src/resolution.rs index 6130baf32..5e0d84cdd 100644 --- a/all-is-cubes-base/src/resolution.rs +++ b/all-is-cubes-base/src/resolution.rs @@ -193,9 +193,7 @@ impl<'de> serde::Deserialize<'de> for Resolution { #[derive(Debug, Clone, Copy, Eq, Hash, PartialEq)] pub struct IntoResolutionError(N); -crate::util::cfg_should_impl_error! { - impl crate::util::ErrorIfStd for IntoResolutionError {} -} +impl core::error::Error for IntoResolutionError {} impl fmt::Display for IntoResolutionError { #[allow(clippy::missing_inline_in_public_items)] diff --git a/all-is-cubes-base/src/util.rs b/all-is-cubes-base/src/util.rs index a0df5021e..734be3498 100644 --- a/all-is-cubes-base/src/util.rs +++ b/all-is-cubes-base/src/util.rs @@ -117,20 +117,6 @@ mod error_chain { } } -/// TODO: Remove this no-longer-needed alias -#[doc(hidden)] -pub use core::error::Error as ErrorIfStd; - -/// TODO: Remove this no-longer-needed macro -#[macro_export] -#[doc(hidden)] -macro_rules! cfg_should_impl_error { - ($($body:tt)*) => { - $($body)* - } -} -pub(crate) use cfg_should_impl_error; - /// Equivalent of [`Iterator::map`] but applied to an [`Extend`] instead, transforming /// the incoming elements. /// diff --git a/all-is-cubes-content/src/template.rs b/all-is-cubes-content/src/template.rs index a22d620a3..d36ec3701 100644 --- a/all-is-cubes-content/src/template.rs +++ b/all-is-cubes-content/src/template.rs @@ -3,6 +3,7 @@ use alloc::boxed::Box; use alloc::string::{String, ToString as _}; use alloc::sync::Arc; +use core::error::Error; use macro_rules_attribute::macro_rules_derive; use paste::paste; @@ -19,7 +20,7 @@ use all_is_cubes::save::WhenceUniverse; use all_is_cubes::space::{LightPhysics, Space}; use all_is_cubes::transaction::Transaction as _; use all_is_cubes::universe::{Handle, Name, Universe, UniverseTransaction}; -use all_is_cubes::util::{ErrorIfStd, YieldProgress}; +use all_is_cubes::util::YieldProgress; use all_is_cubes::{time, transaction}; use crate::fractal::menger_sponge; @@ -283,7 +284,7 @@ impl WhenceUniverse for TemplateAndParameters { fn load( &self, progress: YieldProgress, - ) -> futures_core::future::BoxFuture<'static, Result>> + ) -> futures_core::future::BoxFuture<'static, Result>> { let ingredients = self.clone(); Box::pin(async move { @@ -304,8 +305,7 @@ impl WhenceUniverse for TemplateAndParameters { &self, universe: &Universe, progress: YieldProgress, - ) -> futures_core::future::BoxFuture<'static, Result<(), Box>> - { + ) -> futures_core::future::BoxFuture<'static, Result<(), Box>> { // Delegate to the same error as () would produce. TODO: Have an error enum instead <() as WhenceUniverse>::save(&(), universe, progress) } diff --git a/all-is-cubes-render/src/lib.rs b/all-is-cubes-render/src/lib.rs index 756b4df62..5903f8f88 100644 --- a/all-is-cubes-render/src/lib.rs +++ b/all-is-cubes-render/src/lib.rs @@ -57,9 +57,8 @@ pub enum RenderError { } #[cfg(feature = "std")] -#[allow(clippy::std_instead_of_core)] -impl std::error::Error for RenderError { - fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { +impl core::error::Error for RenderError { + fn source(&self) -> Option<&(dyn core::error::Error + 'static)> { match self { RenderError::Read(e) => Some(e), } diff --git a/all-is-cubes-ui/src/vui/widget_trait.rs b/all-is-cubes-ui/src/vui/widget_trait.rs index 549f30515..9087ec1bc 100644 --- a/all-is-cubes-ui/src/vui/widget_trait.rs +++ b/all-is-cubes-ui/src/vui/widget_trait.rs @@ -3,7 +3,7 @@ use all_is_cubes::time::Tick; use alloc::sync::Arc; use core::fmt::Debug; -use std::error::Error; +use core::error::Error; use std::sync::Mutex; use all_is_cubes::behavior::{self, Behavior}; diff --git a/all-is-cubes-ui/src/vui/widgets/button.rs b/all-is-cubes-ui/src/vui/widgets/button.rs index d6aafb7f5..bd4058266 100644 --- a/all-is-cubes-ui/src/vui/widgets/button.rs +++ b/all-is-cubes-ui/src/vui/widgets/button.rs @@ -2,7 +2,7 @@ use alloc::sync::Arc; use core::fmt; use core::hash::Hash; use core::sync::atomic::{AtomicU8, Ordering::Relaxed}; -use std::error::Error; +use core::error::Error; use exhaust::Exhaust; diff --git a/all-is-cubes-ui/src/vui/widgets/crosshair.rs b/all-is-cubes-ui/src/vui/widgets/crosshair.rs index 08c82e63b..5792f0925 100644 --- a/all-is-cubes-ui/src/vui/widgets/crosshair.rs +++ b/all-is-cubes-ui/src/vui/widgets/crosshair.rs @@ -1,5 +1,5 @@ use alloc::sync::Arc; -use std::error::Error; +use core::error::Error; use all_is_cubes::block::{Block, AIR}; use all_is_cubes::euclid::size3; diff --git a/all-is-cubes-ui/src/vui/widgets/progress_bar.rs b/all-is-cubes-ui/src/vui/widgets/progress_bar.rs index 2e47cb516..60481ec5a 100644 --- a/all-is-cubes-ui/src/vui/widgets/progress_bar.rs +++ b/all-is-cubes-ui/src/vui/widgets/progress_bar.rs @@ -178,7 +178,7 @@ impl vui::WidgetController for ProgressBarController { fn step( &mut self, _context: &vui::WidgetContext<'_>, - ) -> Result<(vui::WidgetTransaction, vui::Then), Box> { + ) -> Result<(vui::WidgetTransaction, vui::Then), Box> { if !self.todo.get_and_clear() { return Ok((SpaceTransaction::default(), vui::Then::Step)); } diff --git a/all-is-cubes-ui/src/vui/widgets/toolbar.rs b/all-is-cubes-ui/src/vui/widgets/toolbar.rs index 89102ea3b..9a042b673 100644 --- a/all-is-cubes-ui/src/vui/widgets/toolbar.rs +++ b/all-is-cubes-ui/src/vui/widgets/toolbar.rs @@ -1,6 +1,6 @@ use alloc::sync::{Arc, Weak}; -use std::error::Error; -use std::fmt; +use core::error::Error; +use core::fmt; use std::sync::Mutex; use all_is_cubes::arcstr; diff --git a/all-is-cubes-ui/src/vui/widgets/tooltip.rs b/all-is-cubes-ui/src/vui/widgets/tooltip.rs index c8d1163f1..b5b223a85 100644 --- a/all-is-cubes-ui/src/vui/widgets/tooltip.rs +++ b/all-is-cubes-ui/src/vui/widgets/tooltip.rs @@ -1,5 +1,5 @@ use alloc::sync::Arc; -use std::error::Error; +use core::error::Error; use std::sync::Mutex; use all_is_cubes::arcstr::{literal, ArcStr}; diff --git a/all-is-cubes-wasm/src/init.rs b/all-is-cubes-wasm/src/init.rs index 3ada32556..cfa017732 100644 --- a/all-is-cubes-wasm/src/init.rs +++ b/all-is-cubes-wasm/src/init.rs @@ -85,7 +85,7 @@ async fn start_game_with_dom( document: Document, gui_helpers: GuiHelpers, static_dom: &StaticDom, -) -> Result<(), Box> { +) -> Result<(), Box> { let progress = yield_progress::Builder::new() .yield_using(|_| yield_to_event_loop()) .progress_using({ @@ -189,7 +189,7 @@ async fn start_game_with_dom( async fn init_wgpu( canvas: &web_sys::HtmlCanvasElement, backends: wgpu::Backends, -) -> Result<(wgpu::Surface<'static>, wgpu::Adapter), Box> { +) -> Result<(wgpu::Surface<'static>, wgpu::Adapter), Box> { let wgpu_instance = wgpu::Instance::new(wgpu::InstanceDescriptor { backends, ..Default::default() diff --git a/all-is-cubes/src/behavior.rs b/all-is-cubes/src/behavior.rs index 3a22c5ee5..1dad49ab9 100644 --- a/all-is-cubes/src/behavior.rs +++ b/all-is-cubes/src/behavior.rs @@ -790,10 +790,8 @@ pub struct BehaviorTransactionConflict { key: Key, } -crate::util::cfg_should_impl_error! { - impl crate::util::ErrorIfStd for BehaviorTransactionMismatch {} - impl crate::util::ErrorIfStd for BehaviorTransactionConflict {} -} + impl core::error::Error for BehaviorTransactionMismatch {} + impl core::error::Error for BehaviorTransactionConflict {} impl fmt::Display for BehaviorTransactionMismatch { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { diff --git a/all-is-cubes/src/block/block_def.rs b/all-is-cubes/src/block/block_def.rs index 8ba599da0..f8831a10a 100644 --- a/all-is-cubes/src/block/block_def.rs +++ b/all-is-cubes/src/block/block_def.rs @@ -393,10 +393,8 @@ pub struct BlockDefConflict { pub(crate) new: bool, } -crate::util::cfg_should_impl_error! { - impl crate::util::ErrorIfStd for BlockDefMismatch {} - impl crate::util::ErrorIfStd for BlockDefConflict {} -} + impl core::error::Error for BlockDefMismatch {} + impl core::error::Error for BlockDefConflict {} impl fmt::Display for BlockDefConflict { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { diff --git a/all-is-cubes/src/block/eval/control.rs b/all-is-cubes/src/block/eval/control.rs index d03ff5ca7..3e5a1c147 100644 --- a/all-is-cubes/src/block/eval/control.rs +++ b/all-is-cubes/src/block/eval/control.rs @@ -285,9 +285,8 @@ impl fmt::Display for EvalBlockError { } } -crate::util::cfg_should_impl_error! { - impl crate::util::ErrorIfStd for EvalBlockError { - fn source(&self) -> Option<&(dyn crate::util::ErrorIfStd + 'static)> { + impl core::error::Error for EvalBlockError { + fn source(&self) -> Option<&(dyn core::error::Error + 'static)> { match &self.kind { ErrorKind::BudgetExceeded { .. } => None, ErrorKind::PriorBudgetExceeded { .. } => None, @@ -295,7 +294,6 @@ crate::util::cfg_should_impl_error! { } } } -} impl From for InEvalError { fn from(value: HandleError) -> Self { diff --git a/all-is-cubes/src/character.rs b/all-is-cubes/src/character.rs index 18fe51a21..8367caa9c 100644 --- a/all-is-cubes/src/character.rs +++ b/all-is-cubes/src/character.rs @@ -848,9 +848,8 @@ pub enum CharacterTransactionConflict { Behaviors(behavior::BehaviorTransactionConflict), } -crate::util::cfg_should_impl_error! { - impl crate::util::ErrorIfStd for CharacterTransactionMismatch { - fn source(&self) -> Option<&(dyn crate::util::ErrorIfStd + 'static)> { + impl core::error::Error for CharacterTransactionMismatch { + fn source(&self) -> Option<&(dyn core::error::Error + 'static)> { match self { CharacterTransactionMismatch::Body(e) => Some(e), CharacterTransactionMismatch::Inventory(e) => Some(e), @@ -859,8 +858,8 @@ crate::util::cfg_should_impl_error! { } } - impl crate::util::ErrorIfStd for CharacterTransactionConflict { - fn source(&self) -> Option<&(dyn crate::util::ErrorIfStd + 'static)> { + impl core::error::Error for CharacterTransactionConflict { + fn source(&self) -> Option<&(dyn core::error::Error + 'static)> { match self { CharacterTransactionConflict::SetSpace => None, CharacterTransactionConflict::Body(_) => None, @@ -869,7 +868,6 @@ crate::util::cfg_should_impl_error! { } } } -} /// Description of a change to a [`Character`] for use in listeners. #[derive(Clone, Debug, Eq, Hash, PartialEq)] diff --git a/all-is-cubes/src/inv/inventory.rs b/all-is-cubes/src/inv/inventory.rs index 766836e83..3bd900063 100644 --- a/all-is-cubes/src/inv/inventory.rs +++ b/all-is-cubes/src/inv/inventory.rs @@ -493,10 +493,8 @@ pub enum InventoryConflict { ReplaceSameSlot { slot: usize }, } -crate::util::cfg_should_impl_error! { - impl crate::util::ErrorIfStd for InventoryMismatch {} - impl crate::util::ErrorIfStd for InventoryConflict {} -} + impl core::error::Error for InventoryMismatch {} + impl core::error::Error for InventoryConflict {} /// Description of a change to an [`Inventory`] for use in listeners. #[derive(Clone, Debug, Eq, Hash, PartialEq)] diff --git a/all-is-cubes/src/inv/tool.rs b/all-is-cubes/src/inv/tool.rs index ba52917bf..96567796c 100644 --- a/all-is-cubes/src/inv/tool.rs +++ b/all-is-cubes/src/inv/tool.rs @@ -482,9 +482,8 @@ pub enum ToolError { Internal(String), } -crate::util::cfg_should_impl_error! { -impl crate::util::ErrorIfStd for ToolError { - fn source(&self) -> Option<&(dyn crate::util::ErrorIfStd + 'static)> { +impl core::error::Error for ToolError { + fn source(&self) -> Option<&(dyn core::error::Error + 'static)> { match self { ToolError::NoTool => None, ToolError::NotUsable => None, @@ -495,7 +494,6 @@ impl crate::util::ErrorIfStd for ToolError { } } } -} impl ToolError { /// Return [`Fluff`] to accompany this error. diff --git a/all-is-cubes/src/linking.rs b/all-is-cubes/src/linking.rs index 31ebb22ef..3f8d09551 100644 --- a/all-is-cubes/src/linking.rs +++ b/all-is-cubes/src/linking.rs @@ -10,6 +10,7 @@ use alloc::boxed::Box; use alloc::vec::Vec; +use core::error::Error; use core::fmt; use core::hash::Hash; use core::ops::Index; @@ -21,7 +22,7 @@ use crate::block::{Block, BlockDef}; use crate::space::{SetCubeError, SpaceTransaction}; use crate::transaction::ExecuteError; use crate::universe::{Handle, InsertError, Name, Universe, UniverseTransaction}; -use crate::util::{ErrorIfStd, YieldProgress}; +use crate::util::YieldProgress; #[cfg(doc)] use crate::block::Primitive; @@ -307,9 +308,7 @@ pub struct ProviderError { missing: Box<[Name]>, } -crate::util::cfg_should_impl_error! { - impl ErrorIfStd for ProviderError {} -} +impl Error for ProviderError {} /// An error resulting from “world generation”. /// @@ -327,11 +326,9 @@ pub struct GenError { for_object: Option, } -crate::util::cfg_should_impl_error! { - impl ErrorIfStd for GenError { - fn source(&self) -> Option<&(dyn ErrorIfStd + 'static)> { - Some(&self.detail) - } +impl Error for GenError { + fn source(&self) -> Option<&(dyn Error + 'static)> { + Some(&self.detail) } } @@ -397,7 +394,7 @@ impl From> for GenError { #[non_exhaustive] pub enum InGenError { /// Generic error container for unusual situations. - Other(Box), + Other(Box), /// Something else needed to be generated and that failed. Gen(Box), @@ -422,23 +419,21 @@ pub enum InGenError { impl InGenError { /// Convert an arbitrary error to `InGenError`. #[cfg_attr(not(feature = "std"), doc(hidden))] - pub fn other(error: E) -> Self { + pub fn other(error: E) -> Self { Self::Other(Box::new(error)) } } -crate::util::cfg_should_impl_error! { - impl ErrorIfStd for InGenError { - fn source(&self) -> Option<&(dyn ErrorIfStd + 'static)> { - match self { - InGenError::Other(e) => e.source(), - InGenError::Gen(e) => e.source(), - InGenError::Insert(e) => e.source(), - InGenError::Provider(e) => e.source(), - InGenError::SetCube(e) => e.source(), - InGenError::UniverseTransaction(e) => e.source(), - InGenError::SpaceTransaction(e) => e.source(), - } +impl Error for InGenError { + fn source(&self) -> Option<&(dyn Error + 'static)> { + match self { + InGenError::Other(e) => e.source(), + InGenError::Gen(e) => e.source(), + InGenError::Insert(e) => e.source(), + InGenError::Provider(e) => e.source(), + InGenError::SetCube(e) => e.source(), + InGenError::UniverseTransaction(e) => e.source(), + InGenError::SpaceTransaction(e) => e.source(), } } } @@ -591,7 +586,7 @@ mod tests { e.to_string(), "An error occurred while generating object 'x'", ); - let source = ErrorIfStd::source(&e) + let source = Error::source(&e) .expect("has source") .downcast_ref::() .expect("is InGenError"); diff --git a/all-is-cubes/src/op.rs b/all-is-cubes/src/op.rs index 440d41a5f..09cf8d34d 100644 --- a/all-is-cubes/src/op.rs +++ b/all-is-cubes/src/op.rs @@ -288,9 +288,8 @@ pub(crate) enum OperationError { OutOfBounds { operation: GridAab, space: GridAab }, } -crate::util::cfg_should_impl_error! { - impl crate::util::ErrorIfStd for OperationError { - fn source(&self) -> Option<&(dyn crate::util::ErrorIfStd + 'static)> { + impl core::error::Error for OperationError { + fn source(&self) -> Option<&(dyn core::error::Error + 'static)> { match self { Self::InternalConflict(e) => Some(e), Self::Unmatching => None, @@ -298,7 +297,6 @@ crate::util::cfg_should_impl_error! { } } } -} #[cfg(test)] mod tests { diff --git a/all-is-cubes/src/physics/body.rs b/all-is-cubes/src/physics/body.rs index 21b6abcd3..03228b3fa 100644 --- a/all-is-cubes/src/physics/body.rs +++ b/all-is-cubes/src/physics/body.rs @@ -750,14 +750,12 @@ impl transaction::Merge for BodyTransaction { #[non_exhaustive] pub enum BodyMismatch {} -crate::util::cfg_should_impl_error! { - impl crate::util::ErrorIfStd for BodyMismatch { - fn source(&self) -> Option<&(dyn crate::util::ErrorIfStd + 'static)> { + impl core::error::Error for BodyMismatch { + fn source(&self) -> Option<&(dyn core::error::Error + 'static)> { match *self { } } } -} /// Note: Tests which involve both body and collision code are currently in the parent module. #[cfg(test)] diff --git a/all-is-cubes/src/save.rs b/all-is-cubes/src/save.rs index c66a15e4c..2ce18ffc4 100644 --- a/all-is-cubes/src/save.rs +++ b/all-is-cubes/src/save.rs @@ -1,5 +1,6 @@ //! Serialization/persistence/saved games. +use core::error::Error; use core::fmt; use alloc::boxed::Box; @@ -7,7 +8,7 @@ use alloc::string::String; use crate::universe::Universe; use crate::util::maybe_sync::MaybeLocalBoxFuture; -use crate::util::{ErrorIfStd, YieldProgress}; +use crate::util::YieldProgress; #[cfg(feature = "save")] mod compress; @@ -56,7 +57,7 @@ pub trait WhenceUniverse: fmt::Debug + Send + Sync + downcast_rs::Downcast + 'st fn load( &self, progress: YieldProgress, - ) -> MaybeLocalBoxFuture<'static, Result>>; + ) -> MaybeLocalBoxFuture<'static, Result>>; /// Write the current state of the given universe into the storage denoted by `self`. /// @@ -71,7 +72,7 @@ pub trait WhenceUniverse: fmt::Debug + Send + Sync + downcast_rs::Downcast + 'st &self, universe: &Universe, progress: YieldProgress, - ) -> MaybeLocalBoxFuture<'static, Result<(), Box>>; + ) -> MaybeLocalBoxFuture<'static, Result<(), Box>>; } downcast_rs::impl_downcast!(WhenceUniverse); @@ -95,7 +96,7 @@ impl WhenceUniverse for () { fn load( &self, _: YieldProgress, - ) -> MaybeLocalBoxFuture<'static, Result>> { + ) -> MaybeLocalBoxFuture<'static, Result>> { Box::pin(core::future::ready(Err( "this universe cannot be reloaded because it has no source".into(), ))) @@ -105,7 +106,7 @@ impl WhenceUniverse for () { &self, _universe: &Universe, _progress: YieldProgress, - ) -> MaybeLocalBoxFuture<'static, Result<(), Box>> { + ) -> MaybeLocalBoxFuture<'static, Result<(), Box>> { Box::pin(core::future::ready(Err( "this universe cannot be saved because a destination has not been specified".into(), ))) diff --git a/all-is-cubes/src/space.rs b/all-is-cubes/src/space.rs index 9aad2ed8e..6d35bfbfc 100644 --- a/all-is-cubes/src/space.rs +++ b/all-is-cubes/src/space.rs @@ -1179,9 +1179,7 @@ pub enum SetCubeError { TooManyBlocks(), } -crate::util::cfg_should_impl_error! { - impl crate::util::ErrorIfStd for SetCubeError {} -} + impl core::error::Error for SetCubeError {} impl fmt::Display for SetCubeError { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { diff --git a/all-is-cubes/src/space/palette.rs b/all-is-cubes/src/space/palette.rs index 2952876b6..40b1beab1 100644 --- a/all-is-cubes/src/space/palette.rs +++ b/all-is-cubes/src/space/palette.rs @@ -572,9 +572,7 @@ pub enum PaletteError { }, } -crate::util::cfg_should_impl_error! { - impl crate::util::ErrorIfStd for PaletteError {} -} + impl core::error::Error for PaletteError {} impl fmt::Display for PaletteError { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { diff --git a/all-is-cubes/src/space/space_txn.rs b/all-is-cubes/src/space/space_txn.rs index b2ae4150d..72fabfc9a 100644 --- a/all-is-cubes/src/space/space_txn.rs +++ b/all-is-cubes/src/space/space_txn.rs @@ -398,9 +398,8 @@ pub enum SpaceTransactionConflict { Behaviors(behavior::BehaviorTransactionConflict), } -crate::util::cfg_should_impl_error! { - impl crate::util::ErrorIfStd for SpaceTransactionMismatch { - fn source(&self) -> Option<&(dyn crate::util::ErrorIfStd + 'static)> { + impl core::error::Error for SpaceTransactionMismatch { + fn source(&self) -> Option<&(dyn core::error::Error + 'static)> { match self { SpaceTransactionMismatch::Cube(_) => None, SpaceTransactionMismatch::OutOfBounds {.. } => None, @@ -408,15 +407,15 @@ crate::util::cfg_should_impl_error! { } } } - impl crate::util::ErrorIfStd for SpaceTransactionConflict { - fn source(&self) -> Option<&(dyn crate::util::ErrorIfStd + 'static)> { + impl core::error::Error for SpaceTransactionConflict { + fn source(&self) -> Option<&(dyn core::error::Error + 'static)> { match self { SpaceTransactionConflict::Cube { conflict, .. } => Some(conflict), SpaceTransactionConflict::Behaviors(conflict) => Some(conflict), } } } -} + impl fmt::Display for SpaceTransactionMismatch { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { @@ -636,7 +635,7 @@ pub struct CubeConflict { pub(crate) new: bool, } -crate::util::cfg_should_impl_error! {impl crate::util::ErrorIfStd for CubeConflict {}} +impl core::error::Error for CubeConflict {} impl fmt::Display for CubeConflict { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { diff --git a/all-is-cubes/src/transaction.rs b/all-is-cubes/src/transaction.rs index 20d869a6c..7814e6f15 100644 --- a/all-is-cubes/src/transaction.rs +++ b/all-is-cubes/src/transaction.rs @@ -3,10 +3,10 @@ use alloc::string::String; use alloc::sync::Arc; use core::any::type_name; +use core::error::Error; use core::{fmt, mem}; use crate::universe::{Handle, HandleError, UTransactional, UniverseTransaction}; -use crate::util::ErrorIfStd; mod generic; pub use generic::*; @@ -66,7 +66,7 @@ pub trait Transaction: Merge { /// Accordingly, it might not describe the _entire_ set of unmet preconditions, /// but only one example from it, so as to avoid needing to allocate a /// data structure of arbitrary size. - type Mismatch: core::error::Error + 'static; + type Mismatch: Error + 'static; /// Checks whether the target's current state meets the preconditions and returns /// [`Err`] if it does not. @@ -164,7 +164,7 @@ pub trait Merge: Sized { /// Accordingly, it might not describe the _entire_ area of the conflict /// but only one example from it, so as to avoid needing to allocate a /// data structure of arbitrary size. - type Conflict: core::error::Error + 'static; + type Conflict: Error + 'static; /// Checks whether two transactions can be merged into a single transaction. /// If so, returns [`Ok`] containing data which may be passed to [`Self::commit_merge()`]. @@ -255,18 +255,16 @@ where } } -crate::util::cfg_should_impl_error! { - impl ErrorIfStd for ExecuteError - where - Txn: Transaction + Merge, - { - fn source(&self) -> Option<&(dyn ErrorIfStd + 'static)> { - match self { - ExecuteError::Merge(e) => e.source(), - ExecuteError::Check(e) => e.source(), - ExecuteError::Commit(e) => e.source(), - ExecuteError::Handle(e) => e.source(), - } +impl Error for ExecuteError +where + Txn: Transaction + Merge, +{ + fn source(&self) -> Option<&(dyn Error + 'static)> { + match self { + ExecuteError::Merge(e) => e.source(), + ExecuteError::Check(e) => e.source(), + ExecuteError::Commit(e) => e.source(), + ExecuteError::Handle(e) => e.source(), } } } @@ -332,7 +330,7 @@ enum CommitErrorKind { #[displaydoc("{transaction_type}::commit() failed")] Leaf { transaction_type: &'static str, - error: Arc, + error: Arc, }, #[displaydoc("{transaction_type}::commit() failed: {message}")] LeafMessage { @@ -351,7 +349,7 @@ impl CommitError { /// Wrap an arbitrary unexpected error as a [`CommitError`]. /// `T` should be the type of the transaction that caught it. #[must_use] - pub fn catch(error: E) -> Self { + pub fn catch(error: E) -> Self { CommitError(CommitErrorKind::Leaf { transaction_type: type_name::(), error: Arc::new(error), @@ -380,14 +378,12 @@ impl CommitError { } } -crate::util::cfg_should_impl_error! { - impl ErrorIfStd for CommitError { - fn source(&self) -> Option<&(dyn ErrorIfStd + 'static)> { - match &self.0 { - CommitErrorKind::Leaf { error, .. } => Some(error), - CommitErrorKind::LeafMessage { .. } => None, - CommitErrorKind::Context { error, .. } => Some(error), - } +impl Error for CommitError { + fn source(&self) -> Option<&(dyn Error + 'static)> { + match &self.0 { + CommitErrorKind::Leaf { error, .. } => Some(error), + CommitErrorKind::LeafMessage { .. } => None, + CommitErrorKind::Context { error, .. } => Some(error), } } } diff --git a/all-is-cubes/src/transaction/generic.rs b/all-is-cubes/src/transaction/generic.rs index 2422113ee..d0a4d3b76 100644 --- a/all-is-cubes/src/transaction/generic.rs +++ b/all-is-cubes/src/transaction/generic.rs @@ -24,19 +24,17 @@ pub struct MapConflict { pub conflict: C, } -crate::util::cfg_should_impl_error! { - impl crate::util::ErrorIfStd for MapMismatch { - fn source(&self) -> Option<&(dyn crate::util::ErrorIfStd + 'static)> { + impl core::error::Error for MapMismatch { + fn source(&self) -> Option<&(dyn core::error::Error + 'static)> { Some(&self.mismatch) } } - impl crate::util::ErrorIfStd for MapConflict { - fn source(&self) -> Option<&(dyn crate::util::ErrorIfStd + 'static)> { + impl core::error::Error for MapConflict { + fn source(&self) -> Option<&(dyn core::error::Error + 'static)> { Some(&self.conflict) } } -} impl fmt::Display for MapMismatch { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { @@ -275,25 +273,23 @@ macro_rules! impl_transaction_for_tuple { // TODO: TupleConflict should have its own message to report the position, // instead of delegating. - crate::util::cfg_should_impl_error! { - impl<$( []: crate::util::ErrorIfStd, )*> crate::util::ErrorIfStd for + impl<$( []: core::error::Error, )*> core::error::Error for [< TupleError $count >]<$( [], )*> { - fn source(&self) -> Option<&(dyn crate::util::ErrorIfStd + 'static)> { + fn source(&self) -> Option<&(dyn core::error::Error + 'static)> { match *self { $( Self::[](ref []) => [].source(), )* } } } - - impl<$( []: crate::util::ErrorIfStd, )*> crate::util::ErrorIfStd for + impl<$( []: core::error::Error, )*> core::error::Error for [< TupleConflict $count >]<$( [], )*> { - fn source(&self) -> Option<&(dyn crate::util::ErrorIfStd + 'static)> { + fn source(&self) -> Option<&(dyn core::error::Error + 'static)> { match *self { $( Self::[](ref []) => [].source(), )* } } } - } + impl<$( []: fmt::Display, )*> fmt::Display for [< TupleError $count >]<$( [], )*> { diff --git a/all-is-cubes/src/transaction/tester.rs b/all-is-cubes/src/transaction/tester.rs index 1333a1f64..be4903a20 100644 --- a/all-is-cubes/src/transaction/tester.rs +++ b/all-is-cubes/src/transaction/tester.rs @@ -1,4 +1,4 @@ -use crate::util::ErrorIfStd as Error; +use core::error::Error as Error; use alloc::boxed::Box; use alloc::rc::Rc; use alloc::vec::Vec; diff --git a/all-is-cubes/src/universe.rs b/all-is-cubes/src/universe.rs index e5012fca9..9d63c85af 100644 --- a/all-is-cubes/src/universe.rs +++ b/all-is-cubes/src/universe.rs @@ -793,9 +793,7 @@ pub enum InsertErrorKind { Poisoned, } -crate::util::cfg_should_impl_error! { - impl crate::util::ErrorIfStd for InsertError {} -} + impl core::error::Error for InsertError {} impl fmt::Display for InsertError { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { diff --git a/all-is-cubes/src/universe/handle.rs b/all-is-cubes/src/universe/handle.rs index a445617fd..1bd29bf21 100644 --- a/all-is-cubes/src/universe/handle.rs +++ b/all-is-cubes/src/universe/handle.rs @@ -526,9 +526,8 @@ pub enum HandleError { NotReady(Name), } -crate::util::cfg_should_impl_error! { - impl crate::util::ErrorIfStd for HandleError {} -} + + impl core::error::Error for HandleError {} /// Read access to the referent of a [`Handle`]. /// diff --git a/all-is-cubes/src/universe/members.rs b/all-is-cubes/src/universe/members.rs index a9df04953..5e060268c 100644 --- a/all-is-cubes/src/universe/members.rs +++ b/all-is-cubes/src/universe/members.rs @@ -362,24 +362,22 @@ macro_rules! member_enums_and_impls { )* } - crate::util::cfg_should_impl_error! { - impl crate::util::ErrorIfStd for AnyTransactionMismatch { - fn source(&self) -> Option<&(dyn crate::util::ErrorIfStd + 'static)> { + impl core::error::Error for AnyTransactionMismatch { + fn source(&self) -> Option<&(dyn core::error::Error + 'static)> { match self { $( Self::$member_type(e) => Some(e), )* } } } - impl crate::util::ErrorIfStd for AnyTransactionConflict { - fn source(&self) -> Option<&(dyn crate::util::ErrorIfStd + 'static)> { + impl core::error::Error for AnyTransactionConflict { + fn source(&self) -> Option<&(dyn core::error::Error + 'static)> { match self { Self::TypeMismatch => None, $( Self::$member_type(e) => Some(e), )* } } } - } impl fmt::Display for AnyTransactionMismatch { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { diff --git a/all-is-cubes/src/universe/universe_txn.rs b/all-is-cubes/src/universe/universe_txn.rs index 818382942..e1ebdc7d4 100644 --- a/all-is-cubes/src/universe/universe_txn.rs +++ b/all-is-cubes/src/universe/universe_txn.rs @@ -258,9 +258,8 @@ pub enum UniverseConflict { Behaviors(behavior::BehaviorTransactionConflict), } -crate::util::cfg_should_impl_error! { - impl crate::util::ErrorIfStd for UniverseMismatch { - fn source(&self) -> Option<&(dyn crate::util::ErrorIfStd + 'static)> { + impl core::error::Error for UniverseMismatch { + fn source(&self) -> Option<&(dyn core::error::Error + 'static)> { match self { UniverseMismatch::DifferentUniverse {..} => None, UniverseMismatch::Member(mc) => Some(&mc.mismatch), @@ -268,8 +267,8 @@ crate::util::cfg_should_impl_error! { UniverseMismatch::InvalidPending => None, } } - } impl crate::util::ErrorIfStd for UniverseConflict { - fn source(&self) -> Option<&(dyn crate::util::ErrorIfStd + 'static)> { + } impl core::error::Error for UniverseConflict { + fn source(&self) -> Option<&(dyn core::error::Error + 'static)> { match self { UniverseConflict::DifferentUniverse(_, _) => None, UniverseConflict::Member(mc) => Some(&mc.conflict), @@ -277,7 +276,6 @@ crate::util::cfg_should_impl_error! { } } } -} impl fmt::Display for UniverseMismatch { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { @@ -863,9 +861,8 @@ pub enum MemberConflict { Modify(ModifyMemberConflict), } -crate::util::cfg_should_impl_error! { - impl crate::util::ErrorIfStd for MemberConflict { - fn source(&self) -> Option<&(dyn crate::util::ErrorIfStd + 'static)> { + impl core::error::Error for MemberConflict { + fn source(&self) -> Option<&(dyn core::error::Error + 'static)> { match self { MemberConflict::InsertVsOther => None, MemberConflict::DeleteVsOther => None, @@ -873,7 +870,6 @@ crate::util::cfg_should_impl_error! { } } } -} /// Transaction precondition error type for a single member in a [`UniverseTransaction`]. #[derive(Clone, Debug, Eq, PartialEq, displaydoc::Display)] @@ -893,8 +889,8 @@ pub enum MemberMismatch { Modify(ModifyMemberMismatch), } -impl crate::util::ErrorIfStd for MemberMismatch { - fn source(&self) -> Option<&(dyn crate::util::ErrorIfStd + 'static)> { +impl core::error::Error for MemberMismatch { + fn source(&self) -> Option<&(dyn core::error::Error + 'static)> { match self { MemberMismatch::Insert(e) => e.source(), MemberMismatch::DeleteNonexistent(_) => None, @@ -922,18 +918,16 @@ pub struct ModifyMemberMismatch(AnyTransactionMismatch); #[derive(Clone, Debug, Eq, PartialEq)] pub struct ModifyMemberConflict(AnyTransactionConflict); -crate::util::cfg_should_impl_error! { - impl crate::util::ErrorIfStd for ModifyMemberMismatch { - fn source(&self) -> Option<&(dyn crate::util::ErrorIfStd + 'static)> { + impl core::error::Error for ModifyMemberMismatch { + fn source(&self) -> Option<&(dyn core::error::Error + 'static)> { self.0.source() } } - impl crate::util::ErrorIfStd for ModifyMemberConflict { - fn source(&self) -> Option<&(dyn crate::util::ErrorIfStd + 'static)> { + impl core::error::Error for ModifyMemberConflict { + fn source(&self) -> Option<&(dyn core::error::Error + 'static)> { self.0.source() } } -} impl fmt::Display for ModifyMemberMismatch { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { diff --git a/all-is-cubes/src/util.rs b/all-is-cubes/src/util.rs index e8f9fd4c2..f8672df06 100644 --- a/all-is-cubes/src/util.rs +++ b/all-is-cubes/src/util.rs @@ -6,21 +6,17 @@ pub use yield_progress::{Builder as YieldProgressBuilder, YieldProgress}; #[doc(no_inline)] pub use manyfmt::{refmt, Fmt, Refmt}; -// Unfortunately, we can't use a glob re-export here or `ErrorIfStd` ends up visible when it +// Unfortunately, we can't use a glob re-export here or hidden items end up visible when they // shouldn't be, mysteriously. So, explicit everything instead, with their various visibilities -// and cfgs. +// and cfgs. TODO: Does that only apply to macros? #[doc(hidden)] pub use all_is_cubes_base::util::ErrorChain; #[doc(hidden)] pub use all_is_cubes_base::util::{ - assert_conditional_send_sync, assert_send_sync, ErrorIfStd, MapExtend, TypeName, + assert_conditional_send_sync, assert_send_sync, MapExtend, TypeName, }; pub use all_is_cubes_base::util::{ConciseDebug, Executor, TimeStats}; -// macros can only be exported from their defining crate at the root, but we can fix the path here -#[doc(hidden)] -pub use all_is_cubes_base::cfg_should_impl_error; - #[doc(hidden)] // public to allow our other crates to match, only pub mod maybe_sync; diff --git a/all-is-cubes/src/util/maybe_sync.rs b/all-is-cubes/src/util/maybe_sync.rs index 007fe2b93..8d6355930 100644 --- a/all-is-cubes/src/util/maybe_sync.rs +++ b/all-is-cubes/src/util/maybe_sync.rs @@ -211,7 +211,7 @@ impl LockError { // } } -impl crate::util::ErrorIfStd for LockError {} +impl core::error::Error for LockError {} impl fmt::Display for LockError { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { @@ -235,7 +235,7 @@ pub(crate) enum TryLockError { WouldBlock, } -impl crate::util::ErrorIfStd for TryLockError {} +impl core::error::Error for TryLockError {} impl fmt::Display for TryLockError { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {