Fix various new clippy warnings

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1168>
This commit is contained in:
Sebastian Dröge 2022-12-13 11:28:00 +02:00
parent c1459c1de8
commit bb90b58547
24 changed files with 62 additions and 63 deletions

View file

@ -1,7 +1,7 @@
#[cfg(feature = "gl")]
fn generate_gl_bindings() {
let dest = std::path::PathBuf::from(&std::env::var("OUT_DIR").unwrap());
let mut file = std::fs::File::create(&dest.join("test_gl_bindings.rs")).unwrap();
let mut file = std::fs::File::create(dest.join("test_gl_bindings.rs")).unwrap();
gl_generator::Registry::new(
gl_generator::Api::Gles2,
(3, 0),

View file

@ -370,7 +370,7 @@ mod video_filter {
}
}
mod imp {
use std::{cmp, mem::ManuallyDrop, os::unix::prelude::FromRawFd};
use std::{mem::ManuallyDrop, os::unix::prelude::FromRawFd};
use anyhow::Error;
use gst::{subclass::prelude::*, PadDirection, PadPresence, PadTemplate};
@ -430,9 +430,9 @@ mod video_filter {
let mut mmap = MmapMut::map_mut(mfd.as_file())?;
for pixel in mmap.chunks_exact_mut(4) {
pixel[0] = cmp::max(0, cmp::min(255, (pixel[0] as f64 * factor) as u8));
pixel[1] = cmp::max(0, cmp::min(255, (pixel[1] as f64 * factor) as u8));
pixel[2] = cmp::max(0, cmp::min(255, (pixel[2] as f64 * factor) as u8));
pixel[0] = (pixel[0] as f64 * factor).clamp(0.0, 255.0) as u8;
pixel[1] = (pixel[1] as f64 * factor).clamp(0.0, 255.0) as u8;
pixel[2] = (pixel[2] as f64 * factor).clamp(0.0, 255.0) as u8;
}
}

View file

@ -92,7 +92,7 @@ impl<T> AudioBuffer<T> {
}
pub fn plane_size(&self) -> usize {
(self.n_samples() as usize * self.sample_stride() as usize * self.channels() as usize)
(self.n_samples() * self.sample_stride() as usize * self.channels() as usize)
/ self.n_planes() as usize
}
@ -330,7 +330,7 @@ impl<T> AudioBufferRef<T> {
}
pub fn plane_size(&self) -> usize {
(self.n_samples() as usize * self.sample_stride() as usize * self.channels() as usize)
(self.n_samples() * self.sample_stride() as usize * self.channels() as usize)
/ self.n_planes() as usize
}

View file

@ -29,7 +29,7 @@ impl AudioChannelPosition {
}
let positions_raw: [ffi::GstAudioChannelPosition; 64] = std::array::from_fn(|i| {
if i >= len as usize {
if i >= len {
ffi::GST_AUDIO_CHANNEL_POSITION_INVALID
} else {
positions[i].into_glib()
@ -95,7 +95,7 @@ impl AudioChannelPosition {
let len = positions.len();
let mut positions_raw: [ffi::GstAudioChannelPosition; 64] = std::array::from_fn(|i| {
if i >= len as usize {
if i >= len {
ffi::GST_AUDIO_CHANNEL_POSITION_INVALID
} else {
positions[i].into_glib()
@ -139,7 +139,7 @@ impl AudioChannelPosition {
let len = positions.len();
let positions_raw: [ffi::GstAudioChannelPosition; 64] = std::array::from_fn(|i| {
if i >= len as usize {
if i >= len {
ffi::GST_AUDIO_CHANNEL_POSITION_INVALID
} else {
positions[i].into_glib()
@ -174,7 +174,7 @@ pub fn buffer_reorder_channels(
let to_len = to.len();
let from_raw: [ffi::GstAudioChannelPosition; 64] = std::array::from_fn(|i| {
if i >= from_len as usize {
if i >= from_len {
ffi::GST_AUDIO_CHANNEL_POSITION_INVALID
} else {
from[i].into_glib()
@ -182,7 +182,7 @@ pub fn buffer_reorder_channels(
});
let to_raw: [ffi::GstAudioChannelPosition; 64] = std::array::from_fn(|i| {
if i >= to_len as usize {
if i >= to_len {
ffi::GST_AUDIO_CHANNEL_POSITION_INVALID
} else {
to[i].into_glib()
@ -224,7 +224,7 @@ pub fn reorder_channels(
let to_len = to.len();
let from_raw: [ffi::GstAudioChannelPosition; 64] = std::array::from_fn(|i| {
if i >= from_len as usize {
if i >= from_len {
ffi::GST_AUDIO_CHANNEL_POSITION_INVALID
} else {
from[i].into_glib()
@ -232,7 +232,7 @@ pub fn reorder_channels(
});
let to_raw: [ffi::GstAudioChannelPosition; 64] = std::array::from_fn(|i| {
if i >= to_len as usize {
if i >= to_len {
ffi::GST_AUDIO_CHANNEL_POSITION_INVALID
} else {
to[i].into_glib()
@ -274,7 +274,7 @@ pub fn channel_reorder_map(
let to_len = to.len();
let from_raw: [ffi::GstAudioChannelPosition; 64] = std::array::from_fn(|i| {
if i >= from_len as usize {
if i >= from_len {
ffi::GST_AUDIO_CHANNEL_POSITION_INVALID
} else {
from[i].into_glib()
@ -282,7 +282,7 @@ pub fn channel_reorder_map(
});
let to_raw: [ffi::GstAudioChannelPosition; 64] = std::array::from_fn(|i| {
if i >= to_len as usize {
if i >= to_len {
ffi::GST_AUDIO_CHANNEL_POSITION_INVALID
} else {
to[i].into_glib()

View file

@ -255,7 +255,7 @@ impl AudioInfo {
}
pub fn bps(&self) -> u32 {
(self.format_info().depth() as u32) >> 3
self.format_info().depth() >> 3
}
pub fn depth(&self) -> u32 {

View file

@ -154,6 +154,6 @@ fn buffer_n_gl_memory(buffer: &gst::BufferRef) -> Option<u32> {
return None;
}
}
Some(num as u32)
Some(num)
}
}

View file

@ -88,7 +88,7 @@ impl PtpClock {
);
assert_ne!(id, 0);
PtpStatisticsCallback(NonZeroU64::new_unchecked(id as u64))
PtpStatisticsCallback(NonZeroU64::new_unchecked(id as _))
}
}
}

View file

@ -16,7 +16,7 @@ impl PlayVideoInfo {
fps_n.as_mut_ptr(),
fps_d.as_mut_ptr(),
);
(fps_n.assume_init() as i32, fps_d.as_mut_ptr() as i32).into()
(fps_n.assume_init(), fps_d.assume_init()).into()
}
}

View file

@ -16,7 +16,7 @@ impl PlayerVideoInfo {
fps_n.as_mut_ptr(),
fps_d.as_mut_ptr(),
);
(fps_n.assume_init() as i32, fps_d.as_mut_ptr() as i32).into()
(fps_n.assume_init(), fps_d.assume_init()).into()
}
}

View file

@ -265,7 +265,6 @@ impl<'a, T> RTPBuffer<'a, T> {
pub fn payload_size(&self) -> u32 {
unsafe {
ffi::gst_rtp_buffer_get_payload_len(glib::translate::mut_override(&self.rtp_buffer))
as u32
}
}

View file

@ -34,7 +34,7 @@ impl SDPBandwidth {
}
pub fn value(&self) -> u32 {
self.0.bandwidth as u32
self.0.bandwidth
}
}

View file

@ -61,11 +61,11 @@ impl SDPConnection {
}
pub fn ttl(&self) -> u32 {
self.0.ttl as u32
self.0.ttl
}
pub fn addr_number(&self) -> u32 {
self.0.addr_number as u32
self.0.addr_number
}
}

View file

@ -186,8 +186,8 @@ pub fn guess_framerate(duration: gst::ClockTime) -> Option<gst::Fraction> {
));
if res {
Some(gst::Fraction::new(
dest_n.assume_init() as i32,
dest_d.assume_init() as i32,
dest_n.assume_init(),
dest_d.assume_init(),
))
} else {
None

View file

@ -350,7 +350,7 @@ impl Iterator for VideoFormatIterator {
return (0, Some(0));
}
let remaining = (self.len - self.idx) as usize;
let remaining = self.len - self.idx;
(remaining, Some(remaining))
}

View file

@ -89,7 +89,7 @@ impl BufferListRef {
#[doc(alias = "gst_buffer_list_calculate_size")]
pub fn calculate_size(&self) -> usize {
unsafe { ffi::gst_buffer_list_calculate_size(self.as_mut_ptr()) as usize }
unsafe { ffi::gst_buffer_list_calculate_size(self.as_mut_ptr()) }
}
pub fn is_empty(&self) -> bool {

View file

@ -60,7 +60,7 @@ impl Serialize for Date {
fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
DateTimeVariants::YMD(
self.0.year() as i32,
self.0.month().into_glib() as i32,
self.0.month().into_glib(),
self.0.day() as i32,
)
.serialize(serializer)

View file

@ -106,7 +106,7 @@ impl FromGlib<libc::c_ulong> for NotifyWatchId {
unsafe fn from_glib(val: libc::c_ulong) -> NotifyWatchId {
skip_assert_initialized!();
assert_ne!(val, 0);
NotifyWatchId(NonZeroU64::new_unchecked(val as u64))
NotifyWatchId(NonZeroU64::new_unchecked(val as _))
}
}

View file

@ -7,47 +7,47 @@ bitflags! {
#[doc(alias = "GstElementFactoryListType")]
pub struct ElementFactoryType: u64 {
#[doc(alias = "GST_ELEMENT_FACTORY_TYPE_DECODER")]
const DECODER = ffi::GST_ELEMENT_FACTORY_TYPE_DECODER as u64;
const DECODER = ffi::GST_ELEMENT_FACTORY_TYPE_DECODER;
#[doc(alias = "GST_ELEMENT_FACTORY_TYPE_ENCODER")]
const ENCODER = ffi::GST_ELEMENT_FACTORY_TYPE_ENCODER as u64;
const ENCODER = ffi::GST_ELEMENT_FACTORY_TYPE_ENCODER;
#[doc(alias = "GST_ELEMENT_FACTORY_TYPE_SINK")]
const SINK = ffi::GST_ELEMENT_FACTORY_TYPE_SINK as u64;
const SINK = ffi::GST_ELEMENT_FACTORY_TYPE_SINK;
#[doc(alias = "GST_ELEMENT_FACTORY_TYPE_SRC")]
const SRC = ffi::GST_ELEMENT_FACTORY_TYPE_SRC as u64;
const SRC = ffi::GST_ELEMENT_FACTORY_TYPE_SRC;
#[doc(alias = "GST_ELEMENT_FACTORY_TYPE_MUXER")]
const MUXER = ffi::GST_ELEMENT_FACTORY_TYPE_MUXER as u64;
const MUXER = ffi::GST_ELEMENT_FACTORY_TYPE_MUXER;
#[doc(alias = "GST_ELEMENT_FACTORY_TYPE_DEMUXER")]
const DEMUXER = ffi::GST_ELEMENT_FACTORY_TYPE_DEMUXER as u64;
const DEMUXER = ffi::GST_ELEMENT_FACTORY_TYPE_DEMUXER;
#[doc(alias = "GST_ELEMENT_FACTORY_TYPE_PARSER")]
const PARSER = ffi::GST_ELEMENT_FACTORY_TYPE_PARSER as u64;
const PARSER = ffi::GST_ELEMENT_FACTORY_TYPE_PARSER;
#[doc(alias = "GST_ELEMENT_FACTORY_TYPE_PAYLOADER")]
const PAYLOADER = ffi::GST_ELEMENT_FACTORY_TYPE_PAYLOADER as u64;
const PAYLOADER = ffi::GST_ELEMENT_FACTORY_TYPE_PAYLOADER;
#[doc(alias = "GST_ELEMENT_FACTORY_TYPE_DEPAYLOADER")]
const DEPAYLOADER = ffi::GST_ELEMENT_FACTORY_TYPE_DEPAYLOADER as u64;
const DEPAYLOADER = ffi::GST_ELEMENT_FACTORY_TYPE_DEPAYLOADER;
#[doc(alias = "GST_ELEMENT_FACTORY_TYPE_FORMATTER")]
const FORMATTER = ffi::GST_ELEMENT_FACTORY_TYPE_FORMATTER as u64;
const FORMATTER = ffi::GST_ELEMENT_FACTORY_TYPE_FORMATTER;
#[doc(alias = "GST_ELEMENT_FACTORY_TYPE_DECRYPTOR")]
const DECRYPTOR = ffi::GST_ELEMENT_FACTORY_TYPE_DECRYPTOR as u64;
const DECRYPTOR = ffi::GST_ELEMENT_FACTORY_TYPE_DECRYPTOR;
#[doc(alias = "GST_ELEMENT_FACTORY_TYPE_ENCRYPTOR")]
const ENCRYPTOR = ffi::GST_ELEMENT_FACTORY_TYPE_ENCRYPTOR as u64;
const ENCRYPTOR = ffi::GST_ELEMENT_FACTORY_TYPE_ENCRYPTOR;
#[doc(alias = "GST_ELEMENT_FACTORY_TYPE_HARDWARE")]
const HARDWARE = ffi::GST_ELEMENT_FACTORY_TYPE_HARDWARE as u64;
const HARDWARE = ffi::GST_ELEMENT_FACTORY_TYPE_HARDWARE;
#[doc(alias = "GST_ELEMENT_FACTORY_TYPE_MEDIA_VIDEO")]
const MEDIA_VIDEO = ffi::GST_ELEMENT_FACTORY_TYPE_MEDIA_VIDEO as u64;
const MEDIA_VIDEO = ffi::GST_ELEMENT_FACTORY_TYPE_MEDIA_VIDEO;
#[doc(alias = "GST_ELEMENT_FACTORY_TYPE_MEDIA_AUDIO")]
const MEDIA_AUDIO = ffi::GST_ELEMENT_FACTORY_TYPE_MEDIA_AUDIO as u64;
const MEDIA_AUDIO = ffi::GST_ELEMENT_FACTORY_TYPE_MEDIA_AUDIO;
#[doc(alias = "GST_ELEMENT_FACTORY_TYPE_MEDIA_IMAGE")]
const MEDIA_IMAGE = ffi::GST_ELEMENT_FACTORY_TYPE_MEDIA_IMAGE as u64;
const MEDIA_IMAGE = ffi::GST_ELEMENT_FACTORY_TYPE_MEDIA_IMAGE;
#[doc(alias = "GST_ELEMENT_FACTORY_TYPE_MEDIA_SUBTITLE")]
const MEDIA_SUBTITLE = ffi::GST_ELEMENT_FACTORY_TYPE_MEDIA_SUBTITLE as u64;
const MEDIA_SUBTITLE = ffi::GST_ELEMENT_FACTORY_TYPE_MEDIA_SUBTITLE;
#[doc(alias = "GST_ELEMENT_FACTORY_TYPE_MEDIA_METADATA")]
const MEDIA_METADATA = ffi::GST_ELEMENT_FACTORY_TYPE_MEDIA_METADATA as u64;
const MEDIA_METADATA = ffi::GST_ELEMENT_FACTORY_TYPE_MEDIA_METADATA;
#[doc(alias = "GST_ELEMENT_FACTORY_TYPE_ANY")]
const ANY = ffi::GST_ELEMENT_FACTORY_TYPE_ANY as u64;
const ANY = ffi::GST_ELEMENT_FACTORY_TYPE_ANY;
#[doc(alias = "GST_ELEMENT_FACTORY_TYPE_MEDIA_ANY")]
const MEDIA_ANY = ffi::GST_ELEMENT_FACTORY_TYPE_MEDIA_ANY as u64;
const MEDIA_ANY = ffi::GST_ELEMENT_FACTORY_TYPE_MEDIA_ANY;
const VIDEO_ENCODER = Self::ENCODER.bits | Self::MEDIA_VIDEO.bits | Self::MEDIA_IMAGE.bits;
const AUDIO_ENCODER = Self::ENCODER.bits | Self::MEDIA_AUDIO.bits;

View file

@ -321,7 +321,7 @@ impl FormattedValue for Option<Percent> {
impl FormattedValueFullRange for Option<Percent> {
unsafe fn from_raw(format: Format, value: i64) -> Self {
debug_assert_eq!(format, Format::Percent);
Percent::try_from_glib(value as i64).ok()
Percent::try_from_glib(value).ok()
}
}

View file

@ -46,7 +46,7 @@ impl FromGlib<libc::c_ulong> for PadProbeId {
unsafe fn from_glib(val: libc::c_ulong) -> PadProbeId {
skip_assert_initialized!();
assert_ne!(val, 0);
PadProbeId(NonZeroU64::new_unchecked(val as u64))
PadProbeId(NonZeroU64::new_unchecked(val as _))
}
}
@ -1097,7 +1097,7 @@ unsafe fn create_probe_info<'a>(
let flow_res = try_from_glib((*info).ABI.abi.flow_ret);
let info = PadProbeInfo {
mask: from_glib((*info).type_),
id: Some(PadProbeId(NonZeroU64::new_unchecked((*info).id as u64))),
id: Some(PadProbeId(NonZeroU64::new_unchecked((*info).id as _))),
offset: (*info).offset,
size: (*info).size,
data: if (*info).data.is_null() {

View file

@ -23,7 +23,7 @@ impl<'a> Iter<'a> {
Iter {
collection,
idx: 0,
size: collection.len() as usize,
size: collection.len(),
}
}
}

View file

@ -1112,7 +1112,7 @@ mod tests {
let s = Structure::builder("test")
.field("f1", "abc")
.field("f2", &String::from("bcd"))
.field("f2", String::from("bcd"))
.field("f3", 123i32)
.build();
@ -1153,7 +1153,7 @@ mod tests {
let s = Structure::builder("test")
.field("f1", "abc")
.field("f2", &String::from("bcd"))
.field("f2", String::from("bcd"))
.field("f3", 123i32)
.build();

View file

@ -177,7 +177,7 @@ mod tests {
let s = Structure::builder("test")
.field("f1", "abc")
.field("f2", &String::from("bcd"))
.field("f2", String::from("bcd"))
.field("f3", 123i32)
.field("fraction", Fraction::new(1, 2))
.field("date", Date::from_dmy(19, DateMonth::August, 2019).unwrap())

View file

@ -202,11 +202,11 @@ define_tracer_hooks! {
};
MiniObjectReffed("mini-object-reffed") = |this, ts, o: *mut ffi::GstMiniObject, rc: libc::c_int| {
let o = MiniObject::from_glib_borrow(o);
this.mini_object_reffed(ts, &o, rc as i32)
this.mini_object_reffed(ts, &o, rc)
};
MiniObjectUnreffed("mini-object-unreffed") = |this, ts, o: *mut ffi::GstMiniObject, rc: libc::c_int| {
let o = MiniObject::from_glib_borrow(o);
this.mini_object_unreffed(ts, &o, rc as i32)
this.mini_object_unreffed(ts, &o, rc)
};
ObjectCreated("object-created") = |this, ts, o: *mut ffi::GstObject| {
let o = Object::from_glib_borrow(o);
@ -218,11 +218,11 @@ define_tracer_hooks! {
};
ObjectReffed("object-reffed") = |this, ts, o: *mut ffi::GstObject, rc: libc::c_int| {
let o = Object::from_glib_borrow(o);
this.object_reffed(ts, &o, rc as i32)
this.object_reffed(ts, &o, rc)
};
ObjectUnreffed("object-unreffed") = |this, ts, o: *mut ffi::GstObject, rc: libc::c_int| {
let o = Object::from_glib_borrow(o);
this.object_unreffed(ts, &o, rc as i32)
this.object_unreffed(ts, &o, rc)
};
PadLinkPost("pad-link-post") = |this, ts, src: *mut ffi::GstPad, sink: *mut ffi::GstPad, r: ffi::GstPadLinkReturn| {
let src = Pad::from_glib_borrow(src);
@ -248,7 +248,7 @@ define_tracer_hooks! {
};
PadPullRangePre("pad-pull-range-pre") = |this, ts, p: *mut ffi::GstPad, o: u64, s: libc::c_uint| {
let p = Pad::from_glib_borrow(p);
this.pad_pull_range_pre(ts, &p, o, s as u32)
this.pad_pull_range_pre(ts, &p, o, s)
};
PadPushEventPost("pad-push-event-post") = |this, ts, p: *mut ffi::GstPad, r: glib::ffi::gboolean| {
let p = Pad::from_glib_borrow(p);