From 66bacbb53a0546ded1c331423350544e872d6e78 Mon Sep 17 00:00:00 2001 From: Xenira <1288524+Xenira@users.noreply.github.com> Date: Tue, 1 Jul 2025 12:30:12 +0200 Subject: [PATCH] fix(clippy): fix new clippy findings Some clippy findings were ignored as they require further investigation. Those findings are marked with a comment and will be tracked in #461. Refs: #461 --- crates/cli/src/lib.rs | 1 + flake.lock | 12 ++++++------ flake.nix | 5 +++-- src/embed/mod.rs | 6 +++--- src/types/array.rs | 6 ++++++ src/types/class_object.rs | 3 +++ src/types/zval.rs | 3 +++ src/zend/class.rs | 3 +++ src/zend/globals.rs | 3 +++ src/zend/try_catch.rs | 2 +- 10 files changed, 32 insertions(+), 12 deletions(-) diff --git a/crates/cli/src/lib.rs b/crates/cli/src/lib.rs index 092fa3d88c..8ea76a4997 100644 --- a/crates/cli/src/lib.rs +++ b/crates/cli/src/lib.rs @@ -90,6 +90,7 @@ enum Args { Stubs(Stubs), } +#[allow(clippy::struct_excessive_bools)] #[derive(Parser)] struct Install { /// Changes the path that the extension is copied to. This will not diff --git a/flake.lock b/flake.lock index d9dc302dc8..c4562e0afe 100644 --- a/flake.lock +++ b/flake.lock @@ -2,11 +2,11 @@ "nodes": { "nixpkgs": { "locked": { - "lastModified": 1749794982, - "narHash": "sha256-Kh9K4taXbVuaLC0IL+9HcfvxsSUx8dPB5s5weJcc9pc=", + "lastModified": 1751271578, + "narHash": "sha256-P/SQmKDu06x8yv7i0s8bvnnuJYkxVGBWLWHaU+tt4YY=", "owner": "nixos", "repo": "nixpkgs", - "rev": "ee930f9755f58096ac6e8ca94a1887e0534e2d81", + "rev": "3016b4b15d13f3089db8a41ef937b13a9e33a8df", "type": "github" }, "original": { @@ -29,11 +29,11 @@ ] }, "locked": { - "lastModified": 1749955444, - "narHash": "sha256-CllTHvHX8KAdAZ+Lxzd23AmZTxO1Pfy+zC43/5tYkAE=", + "lastModified": 1751338093, + "narHash": "sha256-/yd9nPcTfUZPFtwjRbdB5yGLdt3LTPqz6Ja63Joiahs=", "owner": "oxalica", "repo": "rust-overlay", - "rev": "539ba15741f0e6691a2448743dbc601d8910edce", + "rev": "6cfb7821732dac2d3e2dea857a5613d3b856c20c", "type": "github" }, "original": { diff --git a/flake.nix b/flake.nix index 1950ce5a61..3d9f93a150 100644 --- a/flake.nix +++ b/flake.nix @@ -17,7 +17,8 @@ system = "x86_64-linux"; overlays = [ (import rust-overlay) ]; pkgs = import nixpkgs { inherit system overlays; }; - php-dev = pkgs.php.unwrapped.dev; + php = pkgs.php.buildEnv { embedSupport = true; }; + php-dev = php.unwrapped.dev; in { devShells.${system} = { @@ -32,7 +33,7 @@ nativeBuildInputs = [ pkgs.rust-bin.stable.latest.default ]; shellHook = '' - export LIBCLANG_PATH="''$LIBCLANG_PATH ${pkgs.libclang.lib}/lib" + export LIBCLANG_PATH="${pkgs.libclang.lib}/lib" ''; }; }; diff --git a/src/embed/mod.rs b/src/embed/mod.rs index 1f52a60b52..8399010d0b 100644 --- a/src/embed/mod.rs +++ b/src/embed/mod.rs @@ -103,10 +103,10 @@ impl Embed { }; unsafe { - zend_stream_init_filename(&mut file_handle, path.as_ptr()); + zend_stream_init_filename(&raw mut file_handle, path.as_ptr()); } - let exec_result = try_catch(|| unsafe { php_execute_script(&mut file_handle) }); + let exec_result = try_catch(|| unsafe { php_execute_script(&raw mut file_handle) }); match exec_result { Err(_) => Err(EmbedError::CatchError), @@ -208,7 +208,7 @@ impl Embed { let exec_result = try_catch(|| unsafe { zend_eval_string( cstr.as_ptr().cast::(), - &mut result, + &raw mut result, c"run".as_ptr().cast(), ) }); diff --git a/src/types/array.rs b/src/types/array.rs index e1de698120..2a589f9c1a 100644 --- a/src/types/array.rs +++ b/src/types/array.rs @@ -215,6 +215,9 @@ impl ZendHashTable { /// ht.insert("test", "hello world"); /// assert_eq!(ht.get("test").and_then(|zv| zv.str()), Some("hello world")); /// ``` + // TODO: Verify if this is safe to use, as it allows mutating the + // hashtable while only having a reference to it. #461 + #[allow(clippy::mut_from_ref)] #[must_use] pub fn get_mut(&self, key: &'_ str) -> Option<&mut Zval> { let str = CString::new(key).ok()?; @@ -270,6 +273,9 @@ impl ZendHashTable { /// ht.push(100); /// assert_eq!(ht.get_index(0).and_then(|zv| zv.long()), Some(100)); /// ``` + // TODO: Verify if this is safe to use, as it allows mutating the + // hashtable while only having a reference to it. #461 + #[allow(clippy::mut_from_ref)] #[must_use] pub fn get_index_mut(&self, key: u64) -> Option<&mut Zval> { unsafe { zend_hash_index_find(self, key).as_mut() } diff --git a/src/types/class_object.rs b/src/types/class_object.rs index e5a8a4be06..a99778e36e 100644 --- a/src/types/class_object.rs +++ b/src/types/class_object.rs @@ -173,6 +173,9 @@ impl ZendClassObject { Self::internal_from_zend_obj(std) } + // TODO: Verify if this is safe to use, as it allows mutating the + // hashtable while only having a reference to it. #461 + #[allow(clippy::mut_from_ref)] fn internal_from_zend_obj(std: &zend_object) -> Option<&mut Self> { let std = ptr::from_ref(std).cast::(); let ptr = unsafe { diff --git a/src/types/zval.rs b/src/types/zval.rs index c367432526..1bca7bc2e8 100644 --- a/src/types/zval.rs +++ b/src/types/zval.rs @@ -261,6 +261,9 @@ impl Zval { /// Returns a mutable reference to the zval if it is an internal indirect /// reference. + // TODO: Verify if this is safe to use, as it allows mutating the + // hashtable while only having a reference to it. #461 + #[allow(clippy::mut_from_ref)] #[must_use] pub fn indirect_mut(&self) -> Option<&mut Zval> { if self.is_indirect() { diff --git a/src/zend/class.rs b/src/zend/class.rs index 47fcf0b460..ca6ed6a219 100644 --- a/src/zend/class.rs +++ b/src/zend/class.rs @@ -113,6 +113,9 @@ impl ClassEntry { /// Returns the iterator for the class for a specific instance /// /// Returns [`None`] if there is no associated iterator for the class. + // TODO: Verify if this is safe to use, as it allows mutating the + // hashtable while only having a reference to it. #461 + #[allow(clippy::mut_from_ref)] #[must_use] pub fn get_iterator<'a>(&self, zval: &'a Zval, by_ref: bool) -> Option<&'a mut ZendIterator> { let ptr: *const Self = self; diff --git a/src/zend/globals.rs b/src/zend/globals.rs index c687be4275..b119328b94 100644 --- a/src/zend/globals.rs +++ b/src/zend/globals.rs @@ -105,6 +105,9 @@ impl ExecutorGlobals { } /// Attempts to retrieve the global functions hash table as mutable. + // TODO: Verify if this is safe to use, as it allows mutating the + // hashtable while only having a reference to it. #461 + #[allow(clippy::mut_from_ref)] #[must_use] pub fn function_table_mut(&self) -> Option<&mut ZendHashTable> { unsafe { self.function_table.as_mut() } diff --git a/src/zend/try_catch.rs b/src/zend/try_catch.rs index c9e8c3165d..3e2bc1afe8 100644 --- a/src/zend/try_catch.rs +++ b/src/zend/try_catch.rs @@ -195,7 +195,7 @@ mod tests { let _ = try_catch(|| { let mut result = "foo".to_string(); - ptr = &mut result; + ptr = &raw mut result; unsafe { bailout();