Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(deps): Rustを1.83.0に上げ、その新機能を利用する #878

Merged
merged 1 commit into from
Nov 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions crates/voicevox_core/src/devices.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions crates/voicevox_core/src/engine/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion crates/voicevox_core/src/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
20 changes: 9 additions & 11 deletions crates/voicevox_core_c_api/src/c_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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")]
Expand Down
4 changes: 2 additions & 2 deletions crates/voicevox_core_c_api/src/drop_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

Expand All @@ -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"";
}
}
10 changes: 5 additions & 5 deletions crates/voicevox_core_c_api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]`を置き換える
Expand All @@ -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 のオプション。
Expand Down Expand Up @@ -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 }
}
Expand Down
10 changes: 6 additions & 4 deletions crates/voicevox_core_c_api/src/object.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
#![expect(
clippy::type_complexity,
reason = "`CApiObject::bodies`に対するもの。型を分離するとかえって可読性を失う。その代わりコメ\
ントを入れている。`#[…]`じゃなくて`#![…]`でやってるのは、Clippy 0.1.83でeasy-extに反\
応するようになってしまったため"
)]
use std::{
any,
collections::{HashMap, HashSet},
Expand Down Expand Up @@ -40,10 +46,6 @@ pub(crate) trait CApiObject: Default + Debug + 'static {

fn heads() -> &'static boxcar::Vec<Self>;

#[expect(
clippy::type_complexity,
reason = "型を分離するとかえって可読性を失う。その代わりコメントを入れている"
)]
fn bodies() -> &'static std::sync::Mutex<
HashMap<
NonZero<usize>, // `heads`の要素へのポインタのアドレス
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
};

Expand Down
15 changes: 13 additions & 2 deletions crates/voicevox_core_python_api/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
#![expect(
non_local_definitions,
reason = "PyO3を≧0.21.0にすることで解決する予定"
)]

use std::{
marker::PhantomData,
mem,
Expand Down Expand Up @@ -202,7 +207,10 @@ trait RwLock: From<Self::Item> {

impl<T> RwLock for std::sync::RwLock<T> {
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<impl Deref<Target = Self::Item>, ()> {
self.try_read().map_err(|e| match e {
Expand All @@ -229,7 +237,10 @@ impl<T> RwLock for std::sync::RwLock<T> {

impl<T> RwLock for tokio::sync::RwLock<T> {
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<impl Deref<Target = Self::Item>, ()> {
self.try_read().map_err(|_| ())
Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.82.0
1.83.0
Loading