From ae4a45d7ddbeb0904a6e7cb78bbd43024a75b762 Mon Sep 17 00:00:00 2001 From: Ryo Yamashita Date: Fri, 17 Nov 2023 23:51:41 +0900 Subject: [PATCH] =?UTF-8?q?Cargo=E3=81=AE`lints`=E8=A8=AD=E5=AE=9A?= =?UTF-8?q?=E3=82=92=E5=88=A9=E7=94=A8=E3=81=99=E3=82=8B=20(#683)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crates/downloader/Cargo.toml | 4 ++++ crates/test_util/Cargo.toml | 4 ++++ crates/voicevox_core/Cargo.toml | 4 ++++ crates/voicevox_core/src/lib.rs | 2 -- crates/voicevox_core_c_api/Cargo.toml | 4 ++++ crates/voicevox_core_java_api/Cargo.toml | 4 ++++ crates/voicevox_core_java_api/src/common.rs | 4 ++-- crates/voicevox_core_macros/Cargo.toml | 4 ++++ crates/voicevox_core_python_api/Cargo.toml | 4 ++++ crates/voicevox_core_python_api/src/convert.rs | 2 +- crates/voicevox_core_python_api/src/lib.rs | 4 ++-- crates/xtask/Cargo.toml | 4 ++++ 12 files changed, 37 insertions(+), 7 deletions(-) diff --git a/crates/downloader/Cargo.toml b/crates/downloader/Cargo.toml index 7c45a74ca..93806d5e6 100644 --- a/crates/downloader/Cargo.toml +++ b/crates/downloader/Cargo.toml @@ -32,3 +32,7 @@ zip = "0.6.3" [dev-dependencies] rstest.workspace = true + +[lints.rust] +unsafe_code = "forbid" +rust_2018_idioms = "warn" diff --git a/crates/test_util/Cargo.toml b/crates/test_util/Cargo.toml index 35a7a6bf4..51238bba9 100644 --- a/crates/test_util/Cargo.toml +++ b/crates/test_util/Cargo.toml @@ -20,3 +20,7 @@ serde.workspace = true serde_json.workspace = true surf = "2.3.2" tar = "0.4.38" + +[lints.rust] +unsafe_code = "forbid" +rust_2018_idioms = "warn" diff --git a/crates/voicevox_core/Cargo.toml b/crates/voicevox_core/Cargo.toml index 763b69605..4e6d4ed98 100644 --- a/crates/voicevox_core/Cargo.toml +++ b/crates/voicevox_core/Cargo.toml @@ -53,3 +53,7 @@ test_util.workspace = true [target."cfg(windows)".dependencies] humansize = "2.1.2" windows = { version = "0.43.0", features = ["Win32_Foundation", "Win32_Graphics_Dxgi"] } + +[lints.rust] +unsafe_code = "deny" # FIXME: あまり意味が無くなっているため潔く`allow`にする。あるいはunsafeを撲滅する +rust_2018_idioms = "warn" diff --git a/crates/voicevox_core/src/lib.rs b/crates/voicevox_core/src/lib.rs index dc54551a7..c7efad532 100644 --- a/crates/voicevox_core/src/lib.rs +++ b/crates/voicevox_core/src/lib.rs @@ -1,7 +1,5 @@ //! 無料で使える中品質なテキスト読み上げソフトウェア、VOICEVOXのコア。 -#![deny(unsafe_code)] - mod devices; /// cbindgen:ignore mod engine; diff --git a/crates/voicevox_core_c_api/Cargo.toml b/crates/voicevox_core_c_api/Cargo.toml index fad0e1b7b..0567a0c9e 100644 --- a/crates/voicevox_core_c_api/Cargo.toml +++ b/crates/voicevox_core_c_api/Cargo.toml @@ -62,3 +62,7 @@ tempfile.workspace = true test_util.workspace = true toml = "0.7.2" typetag = "0.2.5" + +[lints.rust] +unsafe_code = "allow" # C APIのための操作 +rust_2018_idioms = "warn" diff --git a/crates/voicevox_core_java_api/Cargo.toml b/crates/voicevox_core_java_api/Cargo.toml index 22a1a23cd..616a51642 100644 --- a/crates/voicevox_core_java_api/Cargo.toml +++ b/crates/voicevox_core_java_api/Cargo.toml @@ -21,3 +21,7 @@ tokio.workspace = true tracing-subscriber.workspace = true uuid.workspace = true voicevox_core.workspace = true + +[lints.rust] +unsafe_code = "allow" # jni-rsが要求 +rust_2018_idioms = "warn" diff --git a/crates/voicevox_core_java_api/src/common.rs b/crates/voicevox_core_java_api/src/common.rs index 2c6847f73..138676a1d 100644 --- a/crates/voicevox_core_java_api/src/common.rs +++ b/crates/voicevox_core_java_api/src/common.rs @@ -86,9 +86,9 @@ macro_rules! enum_object { }; } -pub fn throw_if_err(mut env: JNIEnv, fallback: T, inner: F) -> T +pub fn throw_if_err(mut env: JNIEnv<'_>, fallback: T, inner: F) -> T where - F: FnOnce(&mut JNIEnv) -> Result, + F: FnOnce(&mut JNIEnv<'_>) -> Result, { match inner(&mut env) { Ok(value) => value as _, diff --git a/crates/voicevox_core_macros/Cargo.toml b/crates/voicevox_core_macros/Cargo.toml index 957fa3eb8..ab89a69f0 100644 --- a/crates/voicevox_core_macros/Cargo.toml +++ b/crates/voicevox_core_macros/Cargo.toml @@ -13,3 +13,7 @@ indexmap.workspace = true proc-macro2 = "1.0.69" quote = "1.0.33" syn = { version = "2.0.38", features = ["extra-traits"] } + +[lints.rust] +unsafe_code = "forbid" +rust_2018_idioms = "warn" diff --git a/crates/voicevox_core_python_api/Cargo.toml b/crates/voicevox_core_python_api/Cargo.toml index df9cc0eb1..338a73435 100644 --- a/crates/voicevox_core_python_api/Cargo.toml +++ b/crates/voicevox_core_python_api/Cargo.toml @@ -20,3 +20,7 @@ serde.workspace = true serde_json.workspace = true uuid.workspace = true voicevox_core.workspace = true + +[lints.rust] +unsafe_code = "forbid" +rust_2018_idioms = "warn" diff --git a/crates/voicevox_core_python_api/src/convert.rs b/crates/voicevox_core_python_api/src/convert.rs index d4f9cb0d7..7e8d437ad 100644 --- a/crates/voicevox_core_python_api/src/convert.rs +++ b/crates/voicevox_core_python_api/src/convert.rs @@ -119,7 +119,7 @@ pub fn to_rust_uuid(ob: &PyAny) -> PyResult { let uuid = ob.getattr("hex")?.extract::()?; uuid.parse::().into_py_value_result() } -pub fn to_py_uuid(py: Python, uuid: Uuid) -> PyResult { +pub fn to_py_uuid(py: Python<'_>, uuid: Uuid) -> PyResult { let uuid = uuid.hyphenated().to_string(); let uuid = py.import("uuid")?.call_method1("UUID", (uuid,))?; Ok(uuid.to_object(py)) diff --git a/crates/voicevox_core_python_api/src/lib.rs b/crates/voicevox_core_python_api/src/lib.rs index c39c72e1a..1531b463e 100644 --- a/crates/voicevox_core_python_api/src/lib.rs +++ b/crates/voicevox_core_python_api/src/lib.rs @@ -77,7 +77,7 @@ struct VoiceModel { } #[pyfunction] -fn supported_devices(py: Python) -> PyResult<&PyAny> { +fn supported_devices(py: Python<'_>) -> PyResult<&PyAny> { let class = py .import("voicevox_core")? .getattr("SupportedDevices")? @@ -547,7 +547,7 @@ impl UserDict { fn add_word( &mut self, #[pyo3(from_py_with = "to_rust_user_dict_word")] word: UserDictWord, - py: Python, + py: Python<'_>, ) -> PyResult { let uuid = self.dict.add_word(word).into_py_result(py)?; diff --git a/crates/xtask/Cargo.toml b/crates/xtask/Cargo.toml index 11420d2ff..63fbff47a 100644 --- a/crates/xtask/Cargo.toml +++ b/crates/xtask/Cargo.toml @@ -10,3 +10,7 @@ clap.workspace = true color-eyre = "0.6.2" eyre = "0.6.8" fs-err.workspace = true + +[lints.rust] +unsafe_code = "forbid" +rust_2018_idioms = "warn"