From c19efb85dc5b3eb0685b181d3484b3702aa29f66 Mon Sep 17 00:00:00 2001 From: Alisa Sireneva Date: Thu, 31 Oct 2024 14:20:35 +0300 Subject: [PATCH] Fix unimplemented backend error --- Cargo.toml | 2 +- build.rs | 3 +++ src/backend/mod.rs | 4 ++-- src/backend/unimplemented.rs | 20 ++++++++++++++------ 4 files changed, 20 insertions(+), 9 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index d3fe00b..df58555 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -36,7 +36,7 @@ harness = false [lints.rust.unexpected_cfgs] level = "warn" -check-cfg = ["cfg(nightly)", "cfg(backend, values(\"itanium\", \"seh\", \"panic\"))"] +check-cfg = ["cfg(nightly)", "cfg(backend, values(\"itanium\", \"seh\", \"panic\", \"unimplemented\"))"] [profile.dev] panic = "unwind" diff --git a/build.rs b/build.rs index d2d97b0..fda4769 100644 --- a/build.rs +++ b/build.rs @@ -31,6 +31,9 @@ fn main() { { println!("cargo::rustc-cfg=backend=\"seh\""); } else { + #[cfg(feature = "std")] println!("cargo::rustc-cfg=backend=\"panic\""); + #[cfg(not(feature = "std"))] + println!("cargo::rustc-cfg=backend=\"unimplemented\""); } } diff --git a/src/backend/mod.rs b/src/backend/mod.rs index cc06149..ab242d9 100644 --- a/src/backend/mod.rs +++ b/src/backend/mod.rs @@ -169,11 +169,11 @@ mod imp; #[path = "seh.rs"] mod imp; -#[cfg(all(backend = "panic", feature = "std"))] +#[cfg(backend = "panic")] #[path = "panic.rs"] mod imp; -#[cfg(all(backend = "panic", not(feature = "std")))] +#[cfg(backend = "unimplemented")] #[path = "unimplemented.rs"] mod imp; diff --git a/src/backend/unimplemented.rs b/src/backend/unimplemented.rs index e3b5fb8..b5f46e6 100644 --- a/src/backend/unimplemented.rs +++ b/src/backend/unimplemented.rs @@ -1,19 +1,27 @@ -use super::Backend; +use super::{RethrowHandle, ThrowByValue}; pub(crate) struct ActiveBackend; compile_error!("Lithium does not support no_std in this configuration"); -unsafe impl Backend for ActiveBackend { - type ExceptionHeader = (); +unsafe impl ThrowByValue for ActiveBackend { + type RethrowHandle = UnimplementedRethrowHandle; - fn new_header() {} + unsafe fn throw(_cause: E) -> ! { + unimplemented!() + } - unsafe fn throw(_ex: *mut ()) -> ! { + unsafe fn intercept R, R, E>( + _func: Func, + ) -> Result)> { unimplemented!() } +} + +pub(crate) struct UnimplementedRethrowHandle; - fn intercept R, R>(_func: Func) -> Result { +impl RethrowHandle for UnimplementedRethrowHandle { + unsafe fn rethrow(self, _new_cause: F) -> ! { unimplemented!() } }