[librsvg: 17/33] Fix warnings about trivial casts
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg: 17/33] Fix warnings about trivial casts
- Date: Mon, 2 Nov 2020 16:59:48 +0000 (UTC)
commit 5e61aa1d77f893509260e3b283f83c5a1fc3f103
Author: Federico Mena Quintero <federico gnome org>
Date: Fri Oct 30 12:00:06 2020 -0600
Fix warnings about trivial casts
Not entirely happy about the pointer ones, but hey.
src/c_api/c_api.rs | 18 ++++++++++++------
src/element.rs | 38 ++++++++++++++++++-------------------
src/surface_utils/iterators.rs | 2 +-
src/surface_utils/mod.rs | 3 ++-
src/surface_utils/shared_surface.rs | 2 +-
src/xml2_load.rs | 3 ++-
6 files changed, 37 insertions(+), 29 deletions(-)
---
diff --git a/src/c_api/c_api.rs b/src/c_api/c_api.rs
index 0a066dde..8b37257b 100644
--- a/src/c_api/c_api.rs
+++ b/src/c_api/c_api.rs
@@ -316,13 +316,19 @@ impl ops::Deref for RsvgHandleClass {
type Target = ObjectClass;
fn deref(&self) -> &Self::Target {
- unsafe { &*(self as *const _ as *const Self::Target) }
+ unsafe {
+ let self_ptr: *const RsvgHandleClass = self;
+ &*(self_ptr as *const Self::Target)
+ }
}
}
impl ops::DerefMut for RsvgHandleClass {
fn deref_mut(&mut self) -> &mut Self::Target {
- unsafe { &mut *(self as *mut _ as *mut Self::Target) }
+ unsafe {
+ let self_ptr: *mut RsvgHandleClass = self;
+ &mut *(self_ptr as *mut Self::Target)
+ }
}
}
@@ -508,9 +514,9 @@ impl ObjectImpl for CHandle {
Ok(self.get_dimensions_or_empty().ex.to_value()),
// the following three are deprecated
- subclass::Property("title", ..) => Ok((None as Option<String>).to_value()),
- subclass::Property("desc", ..) => Ok((None as Option<String>).to_value()),
- subclass::Property("metadata", ..) => Ok((None as Option<String>).to_value()),
+ subclass::Property("title", ..) => Ok(None::<String>.to_value()),
+ subclass::Property("desc", ..) => Ok(None::<String>.to_value()),
+ subclass::Property("metadata", ..) => Ok(None::<String>.to_value()),
_ => unreachable!("invalid property id={} for RsvgHandle", id),
}
@@ -1772,7 +1778,7 @@ pub unsafe extern "C" fn rsvg_handle_new_from_data(
let raw_stream = gio_sys::g_memory_input_stream_new_from_data(data as *mut u8, data_len, None);
let ret = rsvg_handle_new_from_stream_sync(
- raw_stream as *mut _,
+ raw_stream,
ptr::null_mut(), // base_file
0, // flags
ptr::null_mut(), // cancellable
diff --git a/src/element.rs b/src/element.rs
index f530953e..74dd2c6d 100644
--- a/src/element.rs
+++ b/src/element.rs
@@ -497,7 +497,7 @@ impl Element {
}
}
- let (create_fn, flags) = if name.ns == ns!(svg) {
+ let (create_fn, flags): (ElementCreateFn, ElementCreateFlags) = if name.ns == ns!(svg) {
match ELEMENT_CREATORS.get(name.local.as_ref()) {
// hack in the SVG namespace for supported element names
Some(&(create_fn, flags)) => (create_fn, flags),
@@ -506,13 +506,13 @@ impl Element {
// non-rendering element. This is like a group, but it doesn't do any rendering
// of children. The effect is that we will ignore all children of unknown elements.
None => (
- create_non_rendering as ElementCreateFn,
+ create_non_rendering,
ElementCreateFlags::Default,
),
}
} else {
(
- create_non_rendering as ElementCreateFn,
+ create_non_rendering,
ElementCreateFlags::Default,
)
};
@@ -576,22 +576,22 @@ impl Element {
pub fn as_filter_effect(&self) -> Option<&dyn FilterEffect> {
match self {
- Element::FeBlend(ref fe) => Some(&fe.element_impl as &dyn FilterEffect),
- Element::FeColorMatrix(ref fe) => Some(&fe.element_impl as &dyn FilterEffect),
- Element::FeComponentTransfer(ref fe) => Some(&fe.element_impl as &dyn FilterEffect),
- Element::FeComposite(ref fe) => Some(&fe.element_impl as &dyn FilterEffect),
- Element::FeConvolveMatrix(ref fe) => Some(&fe.element_impl as &dyn FilterEffect),
- Element::FeDiffuseLighting(ref fe) => Some(&fe.element_impl as &dyn FilterEffect),
- Element::FeDisplacementMap(ref fe) => Some(&fe.element_impl as &dyn FilterEffect),
- Element::FeFlood(ref fe) => Some(&fe.element_impl as &dyn FilterEffect),
- Element::FeGaussianBlur(ref fe) => Some(&fe.element_impl as &dyn FilterEffect),
- Element::FeImage(ref fe) => Some(&fe.element_impl as &dyn FilterEffect),
- Element::FeMerge(ref fe) => Some(&fe.element_impl as &dyn FilterEffect),
- Element::FeMorphology(ref fe) => Some(&fe.element_impl as &dyn FilterEffect),
- Element::FeOffset(ref fe) => Some(&fe.element_impl as &dyn FilterEffect),
- Element::FeSpecularLighting(ref fe) => Some(&fe.element_impl as &dyn FilterEffect),
- Element::FeTile(ref fe) => Some(&fe.element_impl as &dyn FilterEffect),
- Element::FeTurbulence(ref fe) => Some(&fe.element_impl as &dyn FilterEffect),
+ Element::FeBlend(ref fe) => Some(&fe.element_impl),
+ Element::FeColorMatrix(ref fe) => Some(&fe.element_impl),
+ Element::FeComponentTransfer(ref fe) => Some(&fe.element_impl),
+ Element::FeComposite(ref fe) => Some(&fe.element_impl),
+ Element::FeConvolveMatrix(ref fe) => Some(&fe.element_impl),
+ Element::FeDiffuseLighting(ref fe) => Some(&fe.element_impl),
+ Element::FeDisplacementMap(ref fe) => Some(&fe.element_impl),
+ Element::FeFlood(ref fe) => Some(&fe.element_impl),
+ Element::FeGaussianBlur(ref fe) => Some(&fe.element_impl),
+ Element::FeImage(ref fe) => Some(&fe.element_impl),
+ Element::FeMerge(ref fe) => Some(&fe.element_impl),
+ Element::FeMorphology(ref fe) => Some(&fe.element_impl),
+ Element::FeOffset(ref fe) => Some(&fe.element_impl),
+ Element::FeSpecularLighting(ref fe) => Some(&fe.element_impl),
+ Element::FeTile(ref fe) => Some(&fe.element_impl),
+ Element::FeTurbulence(ref fe) => Some(&fe.element_impl),
_ => None,
}
}
diff --git a/src/surface_utils/iterators.rs b/src/surface_utils/iterators.rs
index 62c15e5d..5227c62c 100644
--- a/src/surface_utils/iterators.rs
+++ b/src/surface_utils/iterators.rs
@@ -53,7 +53,7 @@ impl<'a> Pixels<'a> {
bounds,
x: bounds.x0 as u32,
y: bounds.y0 as u32,
- offset: bounds.y0 as isize * surface.stride() as isize + bounds.x0 as isize * 4,
+ offset: bounds.y0 as isize * surface.stride() + bounds.x0 as isize * 4,
}
}
}
diff --git a/src/surface_utils/mod.rs b/src/surface_utils/mod.rs
index 1e3d0aa3..97ddef65 100644
--- a/src/surface_utils/mod.rs
+++ b/src/surface_utils/mod.rs
@@ -64,7 +64,8 @@ pub trait ImageSurfaceDataExt: DerefMut<Target = [u8]> {
#[allow(clippy::cast_ptr_alignment)]
unsafe {
- *(&mut self[y as usize * stride + x as usize * 4] as *mut u8 as *mut u32) = value;
+ let p: *mut u8 = &mut self[y as usize * stride + x as usize * 4];
+ *(p as *mut u32) = value;
}
}
}
diff --git a/src/surface_utils/shared_surface.rs b/src/surface_utils/shared_surface.rs
index cd03a6c5..4bf6a822 100644
--- a/src/surface_utils/shared_surface.rs
+++ b/src/surface_utils/shared_surface.rs
@@ -346,7 +346,7 @@ impl ImageSurface<Shared> {
/// Retrieves the pixel value by offset into the pixel data array.
#[inline]
pub fn get_pixel_by_offset(&self, offset: isize) -> Pixel {
- assert!(offset < self.stride as isize * self.height as isize);
+ assert!(offset < self.stride * self.height as isize);
#[allow(clippy::cast_ptr_alignment)]
let value = unsafe { *(self.data_ptr.as_ptr().offset(offset) as *const u32) };
diff --git a/src/xml2_load.rs b/src/xml2_load.rs
index fe17fcec..2ab2d4ea 100644
--- a/src/xml2_load.rs
+++ b/src/xml2_load.rs
@@ -419,9 +419,10 @@ impl Xml2Parser {
});
unsafe {
+ let xml2_parser_ptr: *mut Xml2Parser = xml2_parser.as_mut();
let parser = xmlCreateIOParserCtxt(
&mut sax_handler,
- xml2_parser.as_mut() as *mut _ as *mut _,
+ xml2_parser_ptr as *mut _,
Some(stream_ctx_read),
Some(stream_ctx_close),
Box::into_raw(ctx) as *mut _,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]