From 7c68fbf3f155770b218c79b9a3fdf8a981d6d92d Mon Sep 17 00:00:00 2001 From: Ryo Yamashita Date: Fri, 29 Nov 2024 22:14:02 +0900 Subject: [PATCH] =?UTF-8?q?chore(deps):=20Rust=E3=82=921.83.0=E3=81=AB?= =?UTF-8?q?=E4=B8=8A=E3=81=92=E3=80=81=E3=81=9D=E3=81=AE=E6=96=B0=E6=A9=9F?= =?UTF-8?q?=E8=83=BD=E3=82=92=E5=88=A9=E7=94=A8=E3=81=99=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crates/voicevox_core/src/devices.rs | 4 ---- crates/voicevox_core/src/engine/model.rs | 4 ++-- crates/voicevox_core/src/manifest.rs | 2 +- crates/voicevox_core_c_api/src/c_impls.rs | 20 +++++++++---------- crates/voicevox_core_c_api/src/drop_check.rs | 4 ++-- crates/voicevox_core_c_api/src/lib.rs | 10 +++++----- crates/voicevox_core_c_api/src/object.rs | 10 ++++++---- .../e2e/testcases/user_dict_manipulate.rs | 6 ------ crates/voicevox_core_python_api/src/lib.rs | 15 ++++++++++++-- rust-toolchain | 2 +- 10 files changed, 39 insertions(+), 38 deletions(-) diff --git a/crates/voicevox_core/src/devices.rs b/crates/voicevox_core/src/devices.rs index 0890c0cff..fa7710c80 100644 --- a/crates/voicevox_core/src/devices.rs +++ b/crates/voicevox_core/src/devices.rs @@ -230,10 +230,6 @@ mod tests { reason = "比較対象としてここは網羅されてなければなりません" )] let SupportedDevices { cpu: _, cuda, dml } = &SUPPORTED_DEVICES; - #[expect( - clippy::borrow_deref_ref, - reason = "多分raw記法自体にまだ対応していない" - )] [&raw const *cuda, &raw const *dml] }, *GpuSpec::defaults() diff --git a/crates/voicevox_core/src/engine/model.rs b/crates/voicevox_core/src/engine/model.rs index 228c0bbd8..4c7d5c8f8 100644 --- a/crates/voicevox_core/src/engine/model.rs +++ b/crates/voicevox_core/src/engine/model.rs @@ -99,7 +99,7 @@ where struct Visitor; - impl<'de> de::Visitor<'de> for Visitor { + impl de::Visitor<'_> for Visitor { type Value = (); fn expecting(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result { @@ -140,7 +140,7 @@ where struct Visitor; - impl<'de> de::Visitor<'de> for Visitor { + impl de::Visitor<'_> for Visitor { type Value = (); fn expecting(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result { diff --git a/crates/voicevox_core/src/manifest.rs b/crates/voicevox_core/src/manifest.rs index 8a8290887..0b1a005cd 100644 --- a/crates/voicevox_core/src/manifest.rs +++ b/crates/voicevox_core/src/manifest.rs @@ -28,7 +28,7 @@ impl<'de> Deserialize<'de> for FormatVersionV1 { struct Visitor; - impl<'de> de::Visitor<'de> for Visitor { + impl de::Visitor<'_> for Visitor { type Value = FormatVersionV1; fn expecting(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result { diff --git a/crates/voicevox_core_c_api/src/c_impls.rs b/crates/voicevox_core_c_api/src/c_impls.rs index c83d9b3b0..bc1d89c3c 100644 --- a/crates/voicevox_core_c_api/src/c_impls.rs +++ b/crates/voicevox_core_c_api/src/c_impls.rs @@ -25,14 +25,12 @@ use crate::{ impl VoicevoxOnnxruntime { #[cfg(feature = "load-onnxruntime")] - pub(crate) fn lib_versioned_filename() -> &'static std::ffi::CStr { - to_cstr!(voicevox_core::blocking::Onnxruntime::LIB_VERSIONED_FILENAME) - } + pub(crate) const LIB_VERSIONED_FILENAME: &'static std::ffi::CStr = + to_cstr!(voicevox_core::blocking::Onnxruntime::LIB_VERSIONED_FILENAME); #[cfg(feature = "load-onnxruntime")] - pub(crate) fn lib_unversioned_filename() -> &'static std::ffi::CStr { - to_cstr!(voicevox_core::blocking::Onnxruntime::LIB_UNVERSIONED_FILENAME) - } + pub(crate) const LIB_UNVERSIONED_FILENAME: &'static std::ffi::CStr = + to_cstr!(voicevox_core::blocking::Onnxruntime::LIB_UNVERSIONED_FILENAME); #[ref_cast_custom] fn new(rust: &voicevox_core::blocking::Onnxruntime) -> &Self; @@ -61,11 +59,11 @@ impl VoicevoxOnnxruntime { #[cfg(feature = "load-onnxruntime")] macro_rules! to_cstr { ($s:expr) => {{ - const __RUST_STR: &str = $s; - static __C_STR: &[u8] = const_format::concatcp!(__RUST_STR, '\0').as_bytes(); - - std::ffi::CStr::from_bytes_with_nul(__C_STR) - .unwrap_or_else(|e| panic!("{__RUST_STR:?} should not contain `\\0`: {e}")) + static CSTR: &[u8] = const_format::concatcp!($s, '\0').as_bytes(); + unsafe { + // SAFETY: added a nul with `concatcp!` + std::ffi::CStr::from_bytes_with_nul_unchecked(CSTR) + } }}; } #[cfg(feature = "load-onnxruntime")] diff --git a/crates/voicevox_core_c_api/src/drop_check.rs b/crates/voicevox_core_c_api/src/drop_check.rs index 2dd85f3f3..92fdd5ec0 100644 --- a/crates/voicevox_core_c_api/src/drop_check.rs +++ b/crates/voicevox_core_c_api/src/drop_check.rs @@ -126,7 +126,7 @@ mod tests { )] fn it_denies_unknown_char_ptr() { let checker = CStringDropChecker::new(); - let s = CStr::from_bytes_with_nul(b"\0").unwrap().to_owned(); + let s = c"".to_owned(); checker.check(s.into_raw()); } @@ -139,6 +139,6 @@ mod tests { checker.blacklist(STATIC); checker.check(STATIC.as_ptr() as *mut c_char); - static STATIC: &CStr = unsafe { CStr::from_bytes_with_nul_unchecked(b"\0") }; + static STATIC: &CStr = c""; } } diff --git a/crates/voicevox_core_c_api/src/lib.rs b/crates/voicevox_core_c_api/src/lib.rs index 7efb1e9e3..3f1ab4897 100644 --- a/crates/voicevox_core_c_api/src/lib.rs +++ b/crates/voicevox_core_c_api/src/lib.rs @@ -104,8 +104,8 @@ fn init_logger_once() { #[no_mangle] pub extern "C" fn voicevox_get_onnxruntime_lib_versioned_filename() -> *const c_char { init_logger_once(); - let filename = VoicevoxOnnxruntime::lib_versioned_filename(); - C_STRING_DROP_CHECKER.blacklist(filename).as_ptr() + const FILENAME: &CStr = VoicevoxOnnxruntime::LIB_VERSIONED_FILENAME; + C_STRING_DROP_CHECKER.blacklist(FILENAME).as_ptr() } // TODO: cbindgenが`#[unsafe(no_mangle)]`に対応したら`#[no_mangle]`を置き換える @@ -119,8 +119,8 @@ pub extern "C" fn voicevox_get_onnxruntime_lib_versioned_filename() -> *const c_ #[no_mangle] pub extern "C" fn voicevox_get_onnxruntime_lib_unversioned_filename() -> *const c_char { init_logger_once(); - let filename = VoicevoxOnnxruntime::lib_unversioned_filename(); - C_STRING_DROP_CHECKER.blacklist(filename).as_ptr() + const FILENAME: &CStr = VoicevoxOnnxruntime::LIB_UNVERSIONED_FILENAME; + C_STRING_DROP_CHECKER.blacklist(FILENAME).as_ptr() } /// ::voicevox_onnxruntime_load_once のオプション。 @@ -151,7 +151,7 @@ pub struct VoicevoxLoadOnnxruntimeOptions { pub extern "C" fn voicevox_make_default_load_onnxruntime_options() -> VoicevoxLoadOnnxruntimeOptions { init_logger_once(); - let filename = VoicevoxOnnxruntime::lib_versioned_filename(); + let filename = VoicevoxOnnxruntime::LIB_VERSIONED_FILENAME; let filename = C_STRING_DROP_CHECKER.blacklist(filename).as_ptr(); VoicevoxLoadOnnxruntimeOptions { filename } } diff --git a/crates/voicevox_core_c_api/src/object.rs b/crates/voicevox_core_c_api/src/object.rs index ce5298a9a..5cd6aa3df 100644 --- a/crates/voicevox_core_c_api/src/object.rs +++ b/crates/voicevox_core_c_api/src/object.rs @@ -1,3 +1,9 @@ +#![expect( + clippy::type_complexity, + reason = "`CApiObject::bodies`に対するもの。型を分離するとかえって可読性を失う。その代わりコメ\ + ントを入れている。`#[…]`じゃなくて`#![…]`でやってるのは、Clippy 0.1.83でeasy-extに反\ + 応するようになってしまったため" +)] use std::{ any, collections::{HashMap, HashSet}, @@ -40,10 +46,6 @@ pub(crate) trait CApiObject: Default + Debug + 'static { fn heads() -> &'static boxcar::Vec; - #[expect( - clippy::type_complexity, - reason = "型を分離するとかえって可読性を失う。その代わりコメントを入れている" - )] fn bodies() -> &'static std::sync::Mutex< HashMap< NonZero, // `heads`の要素へのポインタのアドレス diff --git a/crates/voicevox_core_c_api/tests/e2e/testcases/user_dict_manipulate.rs b/crates/voicevox_core_c_api/tests/e2e/testcases/user_dict_manipulate.rs index 313b00125..14245444f 100644 --- a/crates/voicevox_core_c_api/tests/e2e/testcases/user_dict_manipulate.rs +++ b/crates/voicevox_core_c_api/tests/e2e/testcases/user_dict_manipulate.rs @@ -47,13 +47,7 @@ impl assert_cdylib::TestCase for TestCase { let add_word = |dict: *const VoicevoxUserDict, word: &VoicevoxUserDictWord| -> Uuid { let mut word_uuid = [0u8; 16]; - - #[expect( - clippy::borrow_deref_ref, - reason = "多分raw記法自体にまだ対応していない" - )] assert_ok(lib.voicevox_user_dict_add_word(dict, &raw const *word, &mut word_uuid)); - Uuid::from_slice(&word_uuid).expect("invalid uuid") }; diff --git a/crates/voicevox_core_python_api/src/lib.rs b/crates/voicevox_core_python_api/src/lib.rs index d0233c5e7..4873d7ccf 100644 --- a/crates/voicevox_core_python_api/src/lib.rs +++ b/crates/voicevox_core_python_api/src/lib.rs @@ -1,3 +1,8 @@ +#![expect( + non_local_definitions, + reason = "PyO3を≧0.21.0にすることで解決する予定" +)] + use std::{ marker::PhantomData, mem, @@ -202,7 +207,10 @@ trait RwLock: From { impl RwLock for std::sync::RwLock { type Item = T; - type RwLockWriteGuard<'a> = std::sync::RwLockWriteGuard<'a, Self::Item> where Self: 'a; + type RwLockWriteGuard<'a> + = std::sync::RwLockWriteGuard<'a, Self::Item> + where + Self: 'a; fn try_read_(&self) -> Result, ()> { self.try_read().map_err(|e| match e { @@ -229,7 +237,10 @@ impl RwLock for std::sync::RwLock { impl RwLock for tokio::sync::RwLock { type Item = T; - type RwLockWriteGuard<'a> = tokio::sync::RwLockWriteGuard<'a, Self::Item> where Self: 'a; + type RwLockWriteGuard<'a> + = tokio::sync::RwLockWriteGuard<'a, Self::Item> + where + Self: 'a; fn try_read_(&self) -> Result, ()> { self.try_read().map_err(|_| ()) diff --git a/rust-toolchain b/rust-toolchain index 71fae54fb..6b4de0a42 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1 +1 @@ -1.82.0 +1.83.0