Use Box::leak to get rid of some unsafe code

This commit is contained in:
Mathias Svensson 2019-12-10 11:36:36 +01:00
parent 4597769adc
commit 299d1d5c16
3 changed files with 3 additions and 5 deletions

View File

@ -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<Log>) -> Result<(), SetLoggerError> {
set_logger_inner(|| unsafe { &*Box::into_raw(logger) })
set_logger_inner(|| Box::leak(logger))
}
/// Sets the global logger to a `&'static Log`.

View File

@ -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<Log>) -> Result<(), log::SetLoggerError> {
unsafe {
log::set_logger(&*Box::into_raw(logger))
}
log::set_logger(Box::leak(logger))
}
struct State {

View File

@ -9,7 +9,7 @@ use log::set_boxed_logger;
#[cfg(not(feature = "std"))]
fn set_boxed_logger(logger: Box<Log>) -> Result<(), log::SetLoggerError> {
log::set_logger(unsafe { &*Box::into_raw(logger) })
log::set_logger(Box::leak(logger))
}
struct State {