From 15cb980b46b40894fbd80ddba6fd246b214e017c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Laignel?= Date: Sat, 7 Dec 2024 12:51:00 +0100 Subject: [PATCH] Fix clippy 1.83 warning --- src/nameutil.rs | 24 ++++++++---------------- src/writer/to_code.rs | 6 +++--- 2 files changed, 11 insertions(+), 19 deletions(-) diff --git a/src/nameutil.rs b/src/nameutil.rs index 09b2c85ef..0529a2164 100644 --- a/src/nameutil.rs +++ b/src/nameutil.rs @@ -2,27 +2,19 @@ use std::{borrow::Cow, collections::HashMap, path::*, sync::OnceLock}; use crate::case::*; -static mut CRATE_NAME_OVERRIDES: Option> = None; +static CRATE_NAME_OVERRIDES: OnceLock> = OnceLock::new(); pub(crate) fn set_crate_name_overrides(overrides: HashMap) { - unsafe { - assert!( - CRATE_NAME_OVERRIDES.is_none(), - "Crate name overrides already set" - ); - CRATE_NAME_OVERRIDES = Some(overrides); - } + assert!( + CRATE_NAME_OVERRIDES.set(overrides).is_ok(), + "Crate name overrides already set" + ); } fn get_crate_name_override(crate_name: &str) -> Option { - unsafe { - if let Some(ref overrides) = CRATE_NAME_OVERRIDES { - if let Some(crate_name) = overrides.get(crate_name) { - return Some(crate_name.clone()); - } - } - None - } + CRATE_NAME_OVERRIDES + .get() + .and_then(|overrides| overrides.get(crate_name).cloned()) } pub fn split_namespace_name(name: &str) -> (Option<&str>, &str) { diff --git a/src/writer/to_code.rs b/src/writer/to_code.rs index 038813f20..8af7b053c 100644 --- a/src/writer/to_code.rs +++ b/src/writer/to_code.rs @@ -147,10 +147,10 @@ impl ToCode for Chunk { let mut v: Vec = Vec::with_capacity(6); if is_detailed { v.push(format!( - r#"let detailed_signal_name = detail.map(|name| {{ format!("{signal}::{{name}}\0") }});"# + r#"let detailed_signal_name = detail.map(|name| {{ format!(c"{signal}::{{name}}") }});"# )); v.push(format!( - r#"let signal_name: &[u8] = detailed_signal_name.as_ref().map_or(&b"{signal}\0"[..], |n| n.as_bytes());"# + r#"let signal_name: &[u8] = detailed_signal_name.as_ref().map_or(&c"{signal}"[..], |n| n.as_bytes());"# )); v.push( "connect_raw(self.as_ptr() as *mut _, signal_name.as_ptr() as *const _," @@ -158,7 +158,7 @@ impl ToCode for Chunk { ); } else { v.push(format!( - "connect_raw(self.as_ptr() as *mut _, b\"{signal}\\0\".as_ptr() as *const _," + "connect_raw(self.as_ptr() as *mut _, c\"{signal}\".as_ptr() as *const _," )); } let self_str = if in_trait { "Self, " } else { "" };