]> git.ipfire.org Git - thirdparty/qemu.git/commitdiff
rust: enable clippy::ptr_cast_constness
authorPaolo Bonzini <pbonzini@redhat.com>
Fri, 14 Feb 2025 10:34:44 +0000 (11:34 +0100)
committerPaolo Bonzini <pbonzini@redhat.com>
Tue, 6 May 2025 14:02:04 +0000 (16:02 +0200)
Reviewed-by: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
Reviewed-by: Zhao Liu <zhao1.liu@intel.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
docs/devel/rust.rst
rust/Cargo.toml
rust/hw/timer/hpet/src/hpet.rs
rust/qemu-api/src/cell.rs
rust/qemu-api/src/chardev.rs
rust/qemu-api/src/qom.rs
rust/qemu-api/src/timer.rs

index 13a002cfe6971fdd5e8baedaff4714bdfc682ad6..a315f668865903950648895a70bbe4e24c7fa147 100644 (file)
@@ -74,8 +74,6 @@ Supported tools
 QEMU supports rustc version 1.63.0 and newer.  Notably, the following features
 are missing:
 
-* ``cast_mut()``/``cast_const()`` (1.65.0).  Use ``as`` instead.
-
 * Generic Associated Types (1.65.0)
 
 * ``CStr::from_bytes_with_nul()`` as a ``const`` function (1.72.0).
index eda7980b31afe50fee57b2173c31f4bd3326d873..a328634d9498af33f787fd067411744824d5ba43 100644 (file)
@@ -71,6 +71,7 @@ no_effect_underscore_binding = "deny"
 option_option = "deny"
 or_fun_call = "deny"
 ptr_as_ptr = "deny"
+ptr_cast_constness = "deny"
 pub_underscore_fields = "deny"
 redundant_clone = "deny"
 redundant_closure_for_method_calls = "deny"
@@ -92,7 +93,6 @@ used_underscore_binding = "deny"
 
 # nice to have, but cannot be enabled yet
 #wildcard_imports = "deny"   # still have many bindings::* imports
-#ptr_cast_constness = "deny" # needs 1.65.0 for cast_mut()/cast_const()
 
 # these may have false positives
 #option_if_let_else = "deny"
index d4364f2f2f76a0940c71ac8e80d2487c1a415f7e..b7a1be05debe5f964e8e7c4f73330c689b53eac2 100644 (file)
@@ -219,7 +219,7 @@ impl HPETTimer {
             // SAFETY: the HPETTimer will only be used after the timer
             // is initialized below.
             qemu_timer: unsafe { Timer::new() },
-            state: NonNull::new(state as *const _ as *mut _).unwrap(),
+            state: NonNull::new((state as *const HPETState).cast_mut()).unwrap(),
             config: 0,
             cmp: 0,
             fsb: 0,
index ab0785a2692830bb9e836497f07c1758bcd1d29b..1cb9fdcd53f9df072dddca8915fcb222b79b8930 100644 (file)
@@ -1016,7 +1016,7 @@ impl<T> Opaque<T> {
 
     /// Returns a raw pointer to the opaque data.
     pub const fn as_ptr(&self) -> *const T {
-        self.as_mut_ptr() as *const _
+        self.as_mut_ptr().cast_const()
     }
 
     /// Returns a raw pointer to the opaque data that can be passed to a
index 146a4852da3cec1c3eb195b14f26e0fcaba1e1a9..6e0590d758ed537d66e7031f080dda64ac3697ca 100644 (file)
@@ -160,7 +160,7 @@ impl CharBackend {
                 receive_cb,
                 event_cb,
                 None,
-                (owner as *const T as *mut T).cast::<c_void>(),
+                (owner as *const T).cast_mut().cast::<c_void>(),
                 core::ptr::null_mut(),
                 true,
             );
index 52e3a1ec981f0f0aa3ea7575184b82b4d366878e..41e5a5e29a826ef05dcee47fb4ea2184b5bfc8ed 100644 (file)
@@ -388,7 +388,7 @@ where
     {
         #[allow(clippy::as_ptr_cast_mut)]
         {
-            self.as_ptr::<U>() as *mut _
+            self.as_ptr::<U>().cast_mut()
         }
     }
 }
@@ -638,7 +638,7 @@ impl<T: ObjectType> Owned<T> {
         // SAFETY NOTE: while NonNull requires a mutable pointer, only
         // Deref is implemented so the pointer passed to from_raw
         // remains const
-        Owned(NonNull::new(ptr as *mut T).unwrap())
+        Owned(NonNull::new(ptr.cast_mut()).unwrap())
     }
 
     /// Obtain a raw C pointer from a reference.  `src` is consumed
index d697fd742bc2769b1edde1d1f05017dcdd14b246..868bd88575f2496acb245c2b4bee1421fbba69e5 100644 (file)
@@ -81,7 +81,7 @@ impl Timer {
                 scale as c_int,
                 attributes as c_int,
                 Some(timer_cb),
-                (opaque as *const T).cast::<c_void>() as *mut c_void,
+                (opaque as *const T).cast::<c_void>().cast_mut(),
             )
         }
     }