Skip to content

Commit

Permalink
feat: Add static assertions for errors with dyn Error
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilippGackstatter committed Nov 29, 2024
1 parent b751322 commit ed6acb5
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
12 changes: 12 additions & 0 deletions core/src/debuginfo/source_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -389,3 +389,15 @@ impl SourceManager for DefaultSourceManager {
.ok_or(SourceManagerError::InvalidBounds)
}
}

#[cfg(test)]
mod error_assertions {
use super::*;

/// Asserts at compile time that the passed error has Send + Sync + 'static bounds.
fn _assert_error_is_send_sync_static<E: core::error::Error + Send + Sync + 'static>(_: E) {}

fn _assert_source_manager_error_bounds(err: SourceManagerError) {
_assert_error_is_send_sync_static(err);
}
}
12 changes: 12 additions & 0 deletions processor/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,3 +159,15 @@ pub enum Ext2InttError {
#[error("uninitialized memory at address {0}")]
UninitializedMemoryAddress(u32),
}

#[cfg(test)]
mod error_assertions {
use super::*;

/// Asserts at compile time that the passed error has Send + Sync + 'static bounds.
fn _assert_error_is_send_sync_static<E: core::error::Error + Send + Sync + 'static>(_: E) {}

fn _assert_execution_error_bounds(err: ExecutionError) {
_assert_error_is_send_sync_static(err);
}
}

0 comments on commit ed6acb5

Please sign in to comment.