Skip to content

Commit

Permalink
Rust 1.81: Remove cfg_should_impl_error! and ErrorIfStd.
Browse files Browse the repository at this point in the history
  • Loading branch information
kpreid committed Sep 5, 2024
1 parent 9bf9647 commit 608b15d
Show file tree
Hide file tree
Showing 35 changed files with 124 additions and 193 deletions.
4 changes: 1 addition & 3 deletions all-is-cubes-base/src/math/grid_aab.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<GridCoordinate>);
Expand Down
4 changes: 1 addition & 3 deletions all-is-cubes-base/src/math/vol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
4 changes: 1 addition & 3 deletions all-is-cubes-base/src/resolution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,7 @@ impl<'de> serde::Deserialize<'de> for Resolution {
#[derive(Debug, Clone, Copy, Eq, Hash, PartialEq)]
pub struct IntoResolutionError<N>(N);

crate::util::cfg_should_impl_error! {
impl<N: fmt::Display + fmt::Debug> crate::util::ErrorIfStd for IntoResolutionError<N> {}
}
impl<N: fmt::Display + fmt::Debug> core::error::Error for IntoResolutionError<N> {}

impl<N: fmt::Display> fmt::Display for IntoResolutionError<N> {
#[allow(clippy::missing_inline_in_public_items)]
Expand Down
14 changes: 0 additions & 14 deletions all-is-cubes-base/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
///
Expand Down
8 changes: 4 additions & 4 deletions all-is-cubes-content/src/template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -283,7 +284,7 @@ impl WhenceUniverse for TemplateAndParameters {
fn load(
&self,
progress: YieldProgress,
) -> futures_core::future::BoxFuture<'static, Result<Universe, Box<dyn ErrorIfStd + Send + Sync>>>
) -> futures_core::future::BoxFuture<'static, Result<Universe, Box<dyn Error + Send + Sync>>>
{
let ingredients = self.clone();
Box::pin(async move {
Expand All @@ -304,8 +305,7 @@ impl WhenceUniverse for TemplateAndParameters {
&self,
universe: &Universe,
progress: YieldProgress,
) -> futures_core::future::BoxFuture<'static, Result<(), Box<dyn ErrorIfStd + Send + Sync>>>
{
) -> futures_core::future::BoxFuture<'static, Result<(), Box<dyn Error + Send + Sync>>> {
// Delegate to the same error as () would produce. TODO: Have an error enum instead
<() as WhenceUniverse>::save(&(), universe, progress)
}
Expand Down
5 changes: 2 additions & 3 deletions all-is-cubes-render/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
Expand Down
2 changes: 1 addition & 1 deletion all-is-cubes-ui/src/vui/widget_trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
2 changes: 1 addition & 1 deletion all-is-cubes-ui/src/vui/widgets/button.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion all-is-cubes-ui/src/vui/widgets/crosshair.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
2 changes: 1 addition & 1 deletion all-is-cubes-ui/src/vui/widgets/progress_bar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ impl vui::WidgetController for ProgressBarController {
fn step(
&mut self,
_context: &vui::WidgetContext<'_>,
) -> Result<(vui::WidgetTransaction, vui::Then), Box<dyn std::error::Error + Send + Sync>> {
) -> Result<(vui::WidgetTransaction, vui::Then), Box<dyn core::error::Error + Send + Sync>> {
if !self.todo.get_and_clear() {
return Ok((SpaceTransaction::default(), vui::Then::Step));
}
Expand Down
4 changes: 2 additions & 2 deletions all-is-cubes-ui/src/vui/widgets/toolbar.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
2 changes: 1 addition & 1 deletion all-is-cubes-ui/src/vui/widgets/tooltip.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down
4 changes: 2 additions & 2 deletions all-is-cubes-wasm/src/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ async fn start_game_with_dom(
document: Document,
gui_helpers: GuiHelpers,
static_dom: &StaticDom,
) -> Result<(), Box<dyn std::error::Error>> {
) -> Result<(), Box<dyn core::error::Error>> {
let progress = yield_progress::Builder::new()
.yield_using(|_| yield_to_event_loop())
.progress_using({
Expand Down Expand Up @@ -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<dyn std::error::Error>> {
) -> Result<(wgpu::Surface<'static>, wgpu::Adapter), Box<dyn core::error::Error>> {
let wgpu_instance = wgpu::Instance::new(wgpu::InstanceDescriptor {
backends,
..Default::default()
Expand Down
6 changes: 2 additions & 4 deletions all-is-cubes/src/behavior.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 2 additions & 4 deletions all-is-cubes/src/block/block_def.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 2 additions & 4 deletions all-is-cubes/src/block/eval/control.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,17 +285,15 @@ 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,
ErrorKind::Handle(e) => Some(e),
}
}
}
}

impl From<HandleError> for InEvalError {
fn from(value: HandleError) -> Self {
Expand Down
10 changes: 4 additions & 6 deletions all-is-cubes/src/character.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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,
Expand All @@ -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)]
Expand Down
6 changes: 2 additions & 4 deletions all-is-cubes/src/inv/inventory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
6 changes: 2 additions & 4 deletions all-is-cubes/src/inv/tool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -495,7 +494,6 @@ impl crate::util::ErrorIfStd for ToolError {
}
}
}
}

impl ToolError {
/// Return [`Fluff`] to accompany this error.
Expand Down
43 changes: 19 additions & 24 deletions all-is-cubes/src/linking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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”.
///
Expand All @@ -327,11 +326,9 @@ pub struct GenError {
for_object: Option<Name>,
}

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)
}
}

Expand Down Expand Up @@ -397,7 +394,7 @@ impl From<ExecuteError<UniverseTransaction>> for GenError {
#[non_exhaustive]
pub enum InGenError {
/// Generic error container for unusual situations.
Other(Box<dyn ErrorIfStd + Send + Sync>),
Other(Box<dyn Error + Send + Sync>),

/// Something else needed to be generated and that failed.
Gen(Box<GenError>),
Expand All @@ -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<E: ErrorIfStd + Send + Sync + 'static>(error: E) -> Self {
pub fn other<E: Error + Send + Sync + 'static>(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(),
}
}
}
Expand Down Expand Up @@ -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::<InGenError>()
.expect("is InGenError");
Expand Down
6 changes: 2 additions & 4 deletions all-is-cubes/src/op.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,17 +288,15 @@ 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,
Self::OutOfBounds {..} => None,
}
}
}
}

#[cfg(test)]
mod tests {
Expand Down
Loading

0 comments on commit 608b15d

Please sign in to comment.