Skip to content

Commit

Permalink
Fix unimplemented backend error
Browse files Browse the repository at this point in the history
  • Loading branch information
purplesyringa committed Oct 31, 2024
1 parent 1d36028 commit c19efb8
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
3 changes: 3 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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\"");
}
}
4 changes: 2 additions & 2 deletions src/backend/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
20 changes: 14 additions & 6 deletions src/backend/unimplemented.rs
Original file line number Diff line number Diff line change
@@ -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<E> = UnimplementedRethrowHandle;

fn new_header() {}
unsafe fn throw<E>(_cause: E) -> ! {
unimplemented!()
}

unsafe fn throw(_ex: *mut ()) -> ! {
unsafe fn intercept<Func: FnOnce() -> R, R, E>(
_func: Func,
) -> Result<R, (E, Self::RethrowHandle<E>)> {
unimplemented!()
}
}

pub(crate) struct UnimplementedRethrowHandle;

fn intercept<Func: FnOnce() -> R, R>(_func: Func) -> Result<R, *mut ()> {
impl RethrowHandle for UnimplementedRethrowHandle {
unsafe fn rethrow<F>(self, _new_cause: F) -> ! {
unimplemented!()
}
}

0 comments on commit c19efb8

Please sign in to comment.