diff --git a/src/lib.rs b/src/lib.rs index c8f9377..fd87fcb 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1199,7 +1199,7 @@ pub fn max_level() -> LevelFilter { /// [`set_logger`]: fn.set_logger.html #[cfg(all(feature = "std", atomic_cas))] pub fn set_boxed_logger(logger: Box) -> Result<(), SetLoggerError> { - set_logger_inner(|| unsafe { &*Box::into_raw(logger) }) + set_logger_inner(|| Box::leak(logger)) } /// Sets the global logger to a `&'static Log`. diff --git a/test_max_level_features/main.rs b/test_max_level_features/main.rs index ba5ce11..bfbf2b2 100644 --- a/test_max_level_features/main.rs +++ b/test_max_level_features/main.rs @@ -8,9 +8,7 @@ use log::{Level, LevelFilter, Log, Record, Metadata}; use log::set_boxed_logger; #[cfg(not(feature = "std"))] fn set_boxed_logger(logger: Box) -> Result<(), log::SetLoggerError> { - unsafe { - log::set_logger(&*Box::into_raw(logger)) - } + log::set_logger(Box::leak(logger)) } struct State { diff --git a/tests/filters.rs b/tests/filters.rs index e4d21a8..11761b9 100644 --- a/tests/filters.rs +++ b/tests/filters.rs @@ -9,7 +9,7 @@ use log::set_boxed_logger; #[cfg(not(feature = "std"))] fn set_boxed_logger(logger: Box) -> Result<(), log::SetLoggerError> { - log::set_logger(unsafe { &*Box::into_raw(logger) }) + log::set_logger(Box::leak(logger)) } struct State {