From 392239c7f522acb7ca5847a48dd9ab2480242924 Mon Sep 17 00:00:00 2001 From: Brian Cully Date: Tue, 6 Aug 2019 16:31:34 -0400 Subject: Add compatibilty with rust-stable. * Add feature flag for const-fn functionality, which simplifies some things and lets this crate run on architectures where atomic CAS isn't available (e.g., thumbv6). * Remove `const fn` where necessary to compile under rust-stable. * BREAKING CHANGE - Change signature of `Handler::replace` to take a mutable borrow. This is required because the underlying type is now a NonNull, which needs `mut`. The old behavior was never desired, but a consequence of trying to avoid `Option` by using a default handler. * Use lazy_static crate for initialization of Handler/HandlerArray. * Specify Sync for Handler. This is not amazing, since it isn't, but it's necessary for initialization in static contexts inside `lazy_static`. This should be fine, because any actual manipulation of the handler is done in unsafe functions. --- tests/compile-fail/handler.rs | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'tests/compile-fail') diff --git a/tests/compile-fail/handler.rs b/tests/compile-fail/handler.rs index fdc464a..64ab961 100644 --- a/tests/compile-fail/handler.rs +++ b/tests/compile-fail/handler.rs @@ -1,8 +1,13 @@ extern crate clint; +#[macro_use] +extern crate lazy_static; + use clint::Handler; -static mut HANDLER: Handler = Handler::new(); +lazy_static! { + static ref HANDLER: Handler<'static> = Handler::new(); +} fn main() { need_move(); @@ -12,11 +17,11 @@ fn main() { fn need_move() { let x = vec![1, 2, 3]; - let c = || { + let mut c = || { println!("x(h-c): {:?}", x); //~ ERROR does not live long enough }; unsafe { - HANDLER.replace(&c); + HANDLER.replace(&mut c); HANDLER.call(); HANDLER.call(); } @@ -25,11 +30,11 @@ fn need_move() { fn borrow_error() { let x = vec![1, 2, 3]; - let c = move || { + let mut c = move || { println!("x(h-c): {:?}", x); }; unsafe { - HANDLER.replace(&c); + HANDLER.replace(&mut c); HANDLER.call(); HANDLER.call(); } @@ -38,11 +43,11 @@ fn borrow_error() { fn no_borrow_needed() { let x = vec![1, 2, 3]; - let c = || { + let mut c = || { println!("x(h-c): hi!"); }; unsafe { - HANDLER.replace(&c); + HANDLER.replace(&mut c); HANDLER.call(); HANDLER.call(); } -- cgit v1.2.3