mirror of
https://gitee.com/openharmony/third_party_rust_log
synced 2024-11-26 17:30:24 +00:00
Use Box::leak to get rid of some unsafe code
This commit is contained in:
parent
4597769adc
commit
299d1d5c16
@ -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`.
|
||||
|
@ -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 {
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user