Skip to content

Commit d8e021e

Browse files
authored
chore(deps): Rustを1.83.0に上げ、その新機能を利用する (#878)
Rustを1.83.0に上げてClippyとRustfmtの対応を行うとともに、次の新機能を利 用する。 - `const_refs_to_static` (rust-lang/rust#129759)
1 parent a5745c2 commit d8e021e

File tree

10 files changed

+39
-38
lines changed

10 files changed

+39
-38
lines changed

crates/voicevox_core/src/devices.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -230,10 +230,6 @@ mod tests {
230230
reason = "比較対象としてここは網羅されてなければなりません"
231231
)]
232232
let SupportedDevices { cpu: _, cuda, dml } = &SUPPORTED_DEVICES;
233-
#[expect(
234-
clippy::borrow_deref_ref,
235-
reason = "多分raw記法自体にまだ対応していない"
236-
)]
237233
[&raw const *cuda, &raw const *dml]
238234
},
239235
*GpuSpec::defaults()

crates/voicevox_core/src/engine/model.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ where
9999

100100
struct Visitor;
101101

102-
impl<'de> de::Visitor<'de> for Visitor {
102+
impl de::Visitor<'_> for Visitor {
103103
type Value = ();
104104

105105
fn expecting(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
@@ -140,7 +140,7 @@ where
140140

141141
struct Visitor;
142142

143-
impl<'de> de::Visitor<'de> for Visitor {
143+
impl de::Visitor<'_> for Visitor {
144144
type Value = ();
145145

146146
fn expecting(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {

crates/voicevox_core/src/manifest.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ impl<'de> Deserialize<'de> for FormatVersionV1 {
2828

2929
struct Visitor;
3030

31-
impl<'de> de::Visitor<'de> for Visitor {
31+
impl de::Visitor<'_> for Visitor {
3232
type Value = FormatVersionV1;
3333

3434
fn expecting(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {

crates/voicevox_core_c_api/src/c_impls.rs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,12 @@ use crate::{
2525

2626
impl VoicevoxOnnxruntime {
2727
#[cfg(feature = "load-onnxruntime")]
28-
pub(crate) fn lib_versioned_filename() -> &'static std::ffi::CStr {
29-
to_cstr!(voicevox_core::blocking::Onnxruntime::LIB_VERSIONED_FILENAME)
30-
}
28+
pub(crate) const LIB_VERSIONED_FILENAME: &'static std::ffi::CStr =
29+
to_cstr!(voicevox_core::blocking::Onnxruntime::LIB_VERSIONED_FILENAME);
3130

3231
#[cfg(feature = "load-onnxruntime")]
33-
pub(crate) fn lib_unversioned_filename() -> &'static std::ffi::CStr {
34-
to_cstr!(voicevox_core::blocking::Onnxruntime::LIB_UNVERSIONED_FILENAME)
35-
}
32+
pub(crate) const LIB_UNVERSIONED_FILENAME: &'static std::ffi::CStr =
33+
to_cstr!(voicevox_core::blocking::Onnxruntime::LIB_UNVERSIONED_FILENAME);
3634

3735
#[ref_cast_custom]
3836
fn new(rust: &voicevox_core::blocking::Onnxruntime) -> &Self;
@@ -61,11 +59,11 @@ impl VoicevoxOnnxruntime {
6159
#[cfg(feature = "load-onnxruntime")]
6260
macro_rules! to_cstr {
6361
($s:expr) => {{
64-
const __RUST_STR: &str = $s;
65-
static __C_STR: &[u8] = const_format::concatcp!(__RUST_STR, '\0').as_bytes();
66-
67-
std::ffi::CStr::from_bytes_with_nul(__C_STR)
68-
.unwrap_or_else(|e| panic!("{__RUST_STR:?} should not contain `\\0`: {e}"))
62+
static CSTR: &[u8] = const_format::concatcp!($s, '\0').as_bytes();
63+
unsafe {
64+
// SAFETY: added a nul with `concatcp!`
65+
std::ffi::CStr::from_bytes_with_nul_unchecked(CSTR)
66+
}
6967
}};
7068
}
7169
#[cfg(feature = "load-onnxruntime")]

crates/voicevox_core_c_api/src/drop_check.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ mod tests {
126126
)]
127127
fn it_denies_unknown_char_ptr() {
128128
let checker = CStringDropChecker::new();
129-
let s = CStr::from_bytes_with_nul(b"\0").unwrap().to_owned();
129+
let s = c"".to_owned();
130130
checker.check(s.into_raw());
131131
}
132132

@@ -139,6 +139,6 @@ mod tests {
139139
checker.blacklist(STATIC);
140140
checker.check(STATIC.as_ptr() as *mut c_char);
141141

142-
static STATIC: &CStr = unsafe { CStr::from_bytes_with_nul_unchecked(b"\0") };
142+
static STATIC: &CStr = c"";
143143
}
144144
}

crates/voicevox_core_c_api/src/lib.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,8 @@ fn init_logger_once() {
104104
#[no_mangle]
105105
pub extern "C" fn voicevox_get_onnxruntime_lib_versioned_filename() -> *const c_char {
106106
init_logger_once();
107-
let filename = VoicevoxOnnxruntime::lib_versioned_filename();
108-
C_STRING_DROP_CHECKER.blacklist(filename).as_ptr()
107+
const FILENAME: &CStr = VoicevoxOnnxruntime::LIB_VERSIONED_FILENAME;
108+
C_STRING_DROP_CHECKER.blacklist(FILENAME).as_ptr()
109109
}
110110

111111
// TODO: cbindgenが`#[unsafe(no_mangle)]`に対応したら`#[no_mangle]`を置き換える
@@ -119,8 +119,8 @@ pub extern "C" fn voicevox_get_onnxruntime_lib_versioned_filename() -> *const c_
119119
#[no_mangle]
120120
pub extern "C" fn voicevox_get_onnxruntime_lib_unversioned_filename() -> *const c_char {
121121
init_logger_once();
122-
let filename = VoicevoxOnnxruntime::lib_unversioned_filename();
123-
C_STRING_DROP_CHECKER.blacklist(filename).as_ptr()
122+
const FILENAME: &CStr = VoicevoxOnnxruntime::LIB_UNVERSIONED_FILENAME;
123+
C_STRING_DROP_CHECKER.blacklist(FILENAME).as_ptr()
124124
}
125125

126126
/// ::voicevox_onnxruntime_load_once のオプション。
@@ -151,7 +151,7 @@ pub struct VoicevoxLoadOnnxruntimeOptions {
151151
pub extern "C" fn voicevox_make_default_load_onnxruntime_options() -> VoicevoxLoadOnnxruntimeOptions
152152
{
153153
init_logger_once();
154-
let filename = VoicevoxOnnxruntime::lib_versioned_filename();
154+
let filename = VoicevoxOnnxruntime::LIB_VERSIONED_FILENAME;
155155
let filename = C_STRING_DROP_CHECKER.blacklist(filename).as_ptr();
156156
VoicevoxLoadOnnxruntimeOptions { filename }
157157
}

crates/voicevox_core_c_api/src/object.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
#![expect(
2+
clippy::type_complexity,
3+
reason = "`CApiObject::bodies`に対するもの。型を分離するとかえって可読性を失う。その代わりコメ\
4+
ントを入れている。`#[…]`じゃなくて`#![…]`でやってるのは、Clippy 0.1.83でeasy-extに反\
5+
応するようになってしまったため"
6+
)]
17
use std::{
28
any,
39
collections::{HashMap, HashSet},
@@ -40,10 +46,6 @@ pub(crate) trait CApiObject: Default + Debug + 'static {
4046

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

43-
#[expect(
44-
clippy::type_complexity,
45-
reason = "型を分離するとかえって可読性を失う。その代わりコメントを入れている"
46-
)]
4749
fn bodies() -> &'static std::sync::Mutex<
4850
HashMap<
4951
NonZero<usize>, // `heads`の要素へのポインタのアドレス

crates/voicevox_core_c_api/tests/e2e/testcases/user_dict_manipulate.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,7 @@ impl assert_cdylib::TestCase for TestCase {
4747

4848
let add_word = |dict: *const VoicevoxUserDict, word: &VoicevoxUserDictWord| -> Uuid {
4949
let mut word_uuid = [0u8; 16];
50-
51-
#[expect(
52-
clippy::borrow_deref_ref,
53-
reason = "多分raw記法自体にまだ対応していない"
54-
)]
5550
assert_ok(lib.voicevox_user_dict_add_word(dict, &raw const *word, &mut word_uuid));
56-
5751
Uuid::from_slice(&word_uuid).expect("invalid uuid")
5852
};
5953

crates/voicevox_core_python_api/src/lib.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
#![expect(
2+
non_local_definitions,
3+
reason = "PyO3を≧0.21.0にすることで解決する予定"
4+
)]
5+
16
use std::{
27
marker::PhantomData,
38
mem,
@@ -202,7 +207,10 @@ trait RwLock: From<Self::Item> {
202207

203208
impl<T> RwLock for std::sync::RwLock<T> {
204209
type Item = T;
205-
type RwLockWriteGuard<'a> = std::sync::RwLockWriteGuard<'a, Self::Item> where Self: 'a;
210+
type RwLockWriteGuard<'a>
211+
= std::sync::RwLockWriteGuard<'a, Self::Item>
212+
where
213+
Self: 'a;
206214

207215
fn try_read_(&self) -> Result<impl Deref<Target = Self::Item>, ()> {
208216
self.try_read().map_err(|e| match e {
@@ -229,7 +237,10 @@ impl<T> RwLock for std::sync::RwLock<T> {
229237

230238
impl<T> RwLock for tokio::sync::RwLock<T> {
231239
type Item = T;
232-
type RwLockWriteGuard<'a> = tokio::sync::RwLockWriteGuard<'a, Self::Item> where Self: 'a;
240+
type RwLockWriteGuard<'a>
241+
= tokio::sync::RwLockWriteGuard<'a, Self::Item>
242+
where
243+
Self: 'a;
233244

234245
fn try_read_(&self) -> Result<impl Deref<Target = Self::Item>, ()> {
235246
self.try_read().map_err(|_| ())

rust-toolchain

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.82.0
1+
1.83.0

0 commit comments

Comments
 (0)