Skip to content

Commit

Permalink
fix warnings on latest rust
Browse files Browse the repository at this point in the history
  • Loading branch information
jkarneges committed Jan 7, 2025
1 parent ab68e43 commit b371f91
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/connmgr/batch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ impl Batch {
self.nodes.remove(key.nkey);
}

pub fn take_group<'a, 'b: 'a, F>(&'a mut self, get_id: F) -> Option<BatchGroup>
pub fn take_group<'a, 'b: 'a, F>(&'a mut self, get_id: F) -> Option<BatchGroup<'a, 'b>>
where
F: Fn(usize) -> Option<(&'b [u8], u32)>,
{
Expand Down
24 changes: 9 additions & 15 deletions src/core/log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@
use log::{Level, Log, Metadata, Record};
use std::fs::File;
use std::io::{self, Write};
use std::mem;
use std::str;
use std::sync::{Mutex, Once};
use std::sync::{Mutex, OnceLock};
use time::macros::format_description;
use time::{OffsetDateTime, UtcOffset};

Expand Down Expand Up @@ -129,12 +128,10 @@ unsafe fn get_offset() -> Option<UtcOffset> {
offset
}

static mut LOGGER: mem::MaybeUninit<SimpleLogger> = mem::MaybeUninit::uninit();
static LOGGER: OnceLock<SimpleLogger> = OnceLock::new();

pub fn ensure_init_simple_logger(output_file: Option<File>, runner_mode: bool) {
static INIT: Once = Once::new();

INIT.call_once(|| {
LOGGER.get_or_init(|| {
// SAFETY: we accept that this call is unsound. on some platforms it
// is the only way to know the time zone, with a chance of UB if
// another thread modifies environment vars during the call. the risk
Expand All @@ -143,22 +140,19 @@ pub fn ensure_init_simple_logger(output_file: Option<File>, runner_mode: bool) {
// zone than not know the time zone
let local_offset = unsafe { get_offset() };

// SAFETY: call_once ensures this only happens from one place
unsafe {
LOGGER.write(SimpleLogger {
local_offset,
output_file: output_file.map(Mutex::new),
runner_mode,
});
SimpleLogger {
local_offset,
output_file: output_file.map(Mutex::new),
runner_mode,
}
});
}

pub fn get_simple_logger() -> &'static SimpleLogger {
ensure_init_simple_logger(None, false);

// SAFETY: logger is guaranteed to have been initialized
unsafe { LOGGER.assume_init_ref() }
// logger is guaranteed to have been initialized
LOGGER.get().expect("logger should be initialized")
}

pub fn local_offset_check() {
Expand Down

0 comments on commit b371f91

Please sign in to comment.