Clean up clippy warnings and CI configuration

Put clippy overrides into the sources files instead of the CI
configuration, and fix various warnings / clean up code.
This commit is contained in:
Sebastian Dröge 2021-09-08 15:33:31 +03:00 committed by Sebastian Dröge
parent 626df03961
commit 96d86eaa06
21 changed files with 104 additions and 99 deletions

View file

@ -208,7 +208,7 @@ clippy:
rules: rules:
- when: 'always' - when: 'always'
script: script:
- cargo clippy --locked --color=always --all --all-features --all-targets -- -A clippy::single_match -A clippy::manual_range_contains -A clippy::upper_case_acronyms -A clippy::blocks-in-if-conditions -D warnings - cargo clippy --locked --color=always --all --all-features --all-targets -- -D warnings
deny: deny:
extends: .img-stable extends: .img-stable

View file

@ -1049,7 +1049,7 @@ impl State {
// Calculate the current position in the attack window // Calculate the current position in the attack window
let cur_pos = (current_gain_reduction - self.gain_reduction[0]) / old_slope; let cur_pos = (current_gain_reduction - self.gain_reduction[0]) / old_slope;
assert!(cur_pos >= 0.0 && cur_pos <= 1.0); assert!((0.0..=1.0).contains(&cur_pos));
self.env_cnt = ((LIMITER_ATTACK_WINDOW as f64 - 1.0) * cur_pos) as usize; self.env_cnt = ((LIMITER_ATTACK_WINDOW as f64 - 1.0) * cur_pos) as usize;
// Need to sustain in any case for this many samples to actually // Need to sustain in any case for this many samples to actually
@ -1684,6 +1684,7 @@ impl AudioLoudNorm {
pad.event_default(Some(element), event) pad.event_default(Some(element), event)
} }
#[allow(clippy::single_match)]
fn src_query( fn src_query(
&self, &self,
pad: &gst::Pad, pad: &gst::Pad,
@ -1911,6 +1912,7 @@ impl ElementImpl for AudioLoudNorm {
PAD_TEMPLATES.as_ref() PAD_TEMPLATES.as_ref()
} }
#[allow(clippy::single_match)]
fn change_state( fn change_state(
&self, &self,
element: &Self::Type, element: &Self::Type,

View file

@ -6,6 +6,8 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
#![allow(clippy::single_match)]
use gst::glib; use gst::glib;
use gst::prelude::*; use gst::prelude::*;

View file

@ -6,6 +6,8 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
#![allow(clippy::single_match)]
use gst::glib; use gst::glib;
use gst::prelude::*; use gst::prelude::*;

View file

@ -589,8 +589,7 @@ impl Transcriber {
}; };
let transcribe = Self::from_instance(&element); let transcribe = Self::from_instance(&element);
match transcribe.loop_fn(&element, &mut receiver) { if let Err(err) = transcribe.loop_fn(&element, &mut receiver) {
Err(err) => {
element_error!( element_error!(
&element, &element,
gst::StreamError::Failed, gst::StreamError::Failed,
@ -598,8 +597,6 @@ impl Transcriber {
); );
let _ = transcribe.srcpad.pause_task(); let _ = transcribe.srcpad.pause_task();
} }
Ok(_) => (),
};
}); });
if res.is_err() { if res.is_err() {
return Err(loggable_error!(CAT, "Failed to start pad task")); return Err(loggable_error!(CAT, "Failed to start pad task"));

View file

@ -15,7 +15,7 @@
// Free Software Foundation, Inc., 51 Franklin Street, Suite 500, // Free Software Foundation, Inc., 51 Franklin Street, Suite 500,
// Boston, MA 02110-1335, USA. // Boston, MA 02110-1335, USA.
use gst::EventView; #![allow(clippy::single_match)]
fn init() { fn init() {
use std::sync::Once; use std::sync::Once;
@ -83,6 +83,8 @@ fn test_parse() {
} }
while h.events_in_queue() > 0 { while h.events_in_queue() > 0 {
use gst::EventView;
let ev = h.pull_event().unwrap(); let ev = h.pull_event().unwrap();
match ev.view() { match ev.view() {

View file

@ -201,13 +201,14 @@ impl TextWrap {
let mut bufferlist = gst::BufferList::new(); let mut bufferlist = gst::BufferList::new();
let n_lines = std::cmp::max(self.settings.lock().unwrap().lines, 1); let n_lines = std::cmp::max(self.settings.lock().unwrap().lines, 1);
if state let add_buffer = state
.start_ts .start_ts
.zip(Some(accumulate_time)) .zip(Some(accumulate_time))
.map_or(false, |(start_ts, accumulate_time)| { .map_or(false, |(start_ts, accumulate_time)| {
start_ts + accumulate_time < pts start_ts + accumulate_time < pts
}) });
{
if add_buffer {
let mut buf = let mut buf =
gst::Buffer::from_mut_slice(mem::take(&mut state.current_text).into_bytes()); gst::Buffer::from_mut_slice(mem::take(&mut state.current_text).into_bytes());
{ {

View file

@ -128,6 +128,7 @@ impl Default for Settings {
} }
impl OutputState { impl OutputState {
#[allow(clippy::blocks_in_if_conditions)]
fn health( fn health(
&self, &self,
settings: &Settings, settings: &Settings,
@ -301,12 +302,13 @@ impl FallbackSwitch {
deadline.display(), deadline.display(),
); );
if state.last_output_time.zip(running_time).map_or( let is_late = state.last_output_time.zip(running_time).map_or(
false, false,
|(last_output_time, running_time)| { |(last_output_time, running_time)| {
last_output_time + settings.timeout <= running_time last_output_time + settings.timeout <= running_time
}, },
) { );
if is_late {
/* This buffer arrived too late - we either already switched /* This buffer arrived too late - we either already switched
* to the other pad or there's no point outputting this anyway */ * to the other pad or there's no point outputting this anyway */
gst_debug!( gst_debug!(
@ -429,13 +431,15 @@ impl FallbackSwitch {
}; };
if !ignore_timeout { if !ignore_timeout {
// Get the next one if this one is before the timeout let timed_out = !state.last_output_time.zip(running_time).map_or(
if state.last_output_time.zip(running_time).map_or(
false, false,
|(last_output_time, running_time)| { |(last_output_time, running_time)| {
last_output_time + settings.timeout > running_time last_output_time + settings.timeout > running_time
}, },
) { );
// Get the next one if this one is before the timeout
if !timed_out {
gst_debug!( gst_debug!(
CAT, CAT,
obj: backup_pad, obj: backup_pad,

View file

@ -599,6 +599,7 @@ impl ToggleRecord {
} }
} }
#[allow(clippy::blocks_in_if_conditions)]
fn handle_secondary_stream<T: HandleData>( fn handle_secondary_stream<T: HandleData>(
&self, &self,
element: &super::ToggleRecord, element: &super::ToggleRecord,

View file

@ -177,9 +177,11 @@ impl CCDetect {
); );
if cc_packet.cc608 != settings.cc608 { if cc_packet.cc608 != settings.cc608 {
if state.last_cc608_change.map_or(true, |last_cc608_change| { let changed = state.last_cc608_change.map_or(true, |last_cc608_change| {
ts > last_cc608_change + settings.window ts > last_cc608_change + settings.window
}) { });
if changed {
settings.cc608 = cc_packet.cc608; settings.cc608 = cc_packet.cc608;
state.last_cc608_change = Some(ts); state.last_cc608_change = Some(ts);
notify_cc608 = true; notify_cc608 = true;
@ -189,9 +191,10 @@ impl CCDetect {
} }
if cc_packet.cc708 != settings.cc708 { if cc_packet.cc708 != settings.cc708 {
if state.last_cc708_change.map_or(true, |last_cc708_change| { let changed = state.last_cc708_change.map_or(true, |last_cc708_change| {
ts > last_cc708_change + settings.window ts > last_cc708_change + settings.window
}) { });
if changed {
settings.cc708 = cc_packet.cc708; settings.cc708 = cc_packet.cc708;
state.last_cc708_change = Some(ts); state.last_cc708_change = Some(ts);
notify_cc708 = true; notify_cc708 = true;

View file

@ -353,11 +353,10 @@ impl Cea608Overlay {
} }
if Some(cc_type) == state.selected_field { if Some(cc_type) == state.selected_field {
match state if let Ok(Status::Ready) = state
.caption_frame .caption_frame
.decode((triple[1] as u16) << 8 | triple[2] as u16, 0.0) .decode((triple[1] as u16) << 8 | triple[2] as u16, 0.0)
{ {
Ok(Status::Ready) => {
let text = match state.caption_frame.to_text(true) { let text = match state.caption_frame.to_text(true) {
Ok(text) => text, Ok(text) => text,
Err(_) => { Err(_) => {
@ -372,8 +371,6 @@ impl Cea608Overlay {
self.overlay_text(element, &text, state); self.overlay_text(element, &text, state);
} }
_ => (),
}
} }
} else { } else {
break; break;
@ -406,27 +403,20 @@ impl Cea608Overlay {
} }
if Some(cc_type) == state.selected_field { if Some(cc_type) == state.selected_field {
match state if let Ok(Status::Ready) = state
.caption_frame .caption_frame
.decode((triple[1] as u16) << 8 | triple[2] as u16, 0.0) .decode((triple[1] as u16) << 8 | triple[2] as u16, 0.0)
{ {
Ok(Status::Ready) => {
let text = match state.caption_frame.to_text(true) { let text = match state.caption_frame.to_text(true) {
Ok(text) => text, Ok(text) => text,
Err(_) => { Err(_) => {
gst_error!( gst_error!(CAT, obj: pad, "Failed to convert caption frame to text");
CAT,
obj: pad,
"Failed to convert caption frame to text"
);
continue; continue;
} }
}; };
self.overlay_text(element, &text, state); self.overlay_text(element, &text, state);
} }
_ => (),
}
} }
} }
} }
@ -468,11 +458,10 @@ impl Cea608Overlay {
let data = meta.data(); let data = meta.data();
assert!(data.len() % 2 == 0); assert!(data.len() % 2 == 0);
for i in 0..data.len() / 2 { for i in 0..data.len() / 2 {
match state if let Ok(Status::Ready) = state
.caption_frame .caption_frame
.decode((data[i * 2] as u16) << 8 | data[i * 2 + 1] as u16, 0.0) .decode((data[i * 2] as u16) << 8 | data[i * 2 + 1] as u16, 0.0)
{ {
Ok(Status::Ready) => {
let text = match state.caption_frame.to_text(true) { let text = match state.caption_frame.to_text(true) {
Ok(text) => text, Ok(text) => text,
Err(_) => { Err(_) => {
@ -487,8 +476,6 @@ impl Cea608Overlay {
self.overlay_text(element, &text, &mut state); self.overlay_text(element, &text, &mut state);
} }
_ => (),
}
} }
} }
} }
@ -503,12 +490,10 @@ impl Cea608Overlay {
state.video_info.as_ref().unwrap(), state.video_info.as_ref().unwrap(),
) )
.unwrap(); .unwrap();
match composition.blend(&mut frame) {
Err(_) => { if composition.blend(&mut frame).is_err() {
gst_error!(CAT, obj: pad, "Failed to blend composition"); gst_error!(CAT, obj: pad, "Failed to blend composition");
} }
_ => (),
}
} }
} }
drop(state); drop(state);

View file

@ -547,10 +547,9 @@ impl State {
ret ret
} }
Cea608Mode::PopOn => { Cea608Mode::PopOn => {
#[allow(clippy::map_entry)] let row = self.cursor.row;
if !self.rows.contains_key(&self.cursor.row) { self.rows.entry(row).or_insert_with(|| Row::new(row));
self.rows.insert(self.cursor.row, Row::new(self.cursor.row));
}
None None
} }
} }
@ -930,6 +929,7 @@ impl ElementImpl for Cea608ToJson {
PAD_TEMPLATES.as_ref() PAD_TEMPLATES.as_ref()
} }
#[allow(clippy::single_match)]
fn change_state( fn change_state(
&self, &self,
element: &Self::Type, element: &Self::Type,

View file

@ -482,6 +482,7 @@ impl ElementImpl for Cea608ToTt {
PAD_TEMPLATES.as_ref() PAD_TEMPLATES.as_ref()
} }
#[allow(clippy::single_match)]
fn change_state( fn change_state(
&self, &self,
element: &Self::Type, element: &Self::Type,

View file

@ -25,7 +25,7 @@ pub enum MccLine<'a> {
Header, Header,
Comment, Comment,
Empty, Empty,
UUID(&'a [u8]), Uuid(&'a [u8]),
Metadata(&'a [u8], &'a [u8]), Metadata(&'a [u8], &'a [u8]),
TimeCodeRate(u8, bool), TimeCodeRate(u8, bool),
Caption(TimeCode, Option<Vec<u8>>), Caption(TimeCode, Option<Vec<u8>>),
@ -96,7 +96,7 @@ fn uuid(s: &[u8]) -> IResult<&[u8], MccLine> {
take_while1(|b| b != b'\n' && b != b'\r'), take_while1(|b| b != b'\n' && b != b'\r'),
end_of_line, end_of_line,
)), )),
|(_, uuid, _)| MccLine::UUID(uuid), |(_, uuid, _)| MccLine::Uuid(uuid),
), ),
)(s) )(s)
} }
@ -238,9 +238,9 @@ fn mcc_payload_item(s: &[u8]) -> IResult<&[u8], Either<u8, &'static [u8]>> {
map(tag("Z"), |_| Either::Right([0x00].as_ref())), map(tag("Z"), |_| Either::Right([0x00].as_ref())),
map(take_while_m_n(2, 2, is_hex_digit), |s: &[u8]| { map(take_while_m_n(2, 2, is_hex_digit), |s: &[u8]| {
let hex_to_u8 = |v: u8| match v { let hex_to_u8 = |v: u8| match v {
v if v >= b'0' && v <= b'9' => v - b'0', v if (b'0'..=b'9').contains(&v) => v - b'0',
v if v >= b'A' && v <= b'F' => 10 + v - b'A', v if (b'A'..=b'F').contains(&v) => 10 + v - b'A',
v if v >= b'a' && v <= b'f' => 10 + v - b'a', v if (b'a'..=b'f').contains(&v) => 10 + v - b'a',
_ => unreachable!(), _ => unreachable!(),
}; };
let val = (hex_to_u8(s[0]) << 4) | hex_to_u8(s[1]); let val = (hex_to_u8(s[0]) << 4) | hex_to_u8(s[1]);
@ -472,17 +472,17 @@ mod tests {
fn test_uuid() { fn test_uuid() {
assert_eq!( assert_eq!(
uuid(b"UUID=1234".as_ref()), uuid(b"UUID=1234".as_ref()),
Ok((b"".as_ref(), MccLine::UUID(b"1234".as_ref()))) Ok((b"".as_ref(), MccLine::Uuid(b"1234".as_ref())))
); );
assert_eq!( assert_eq!(
uuid(b"UUID=1234\n".as_ref()), uuid(b"UUID=1234\n".as_ref()),
Ok((b"".as_ref(), MccLine::UUID(b"1234".as_ref()))) Ok((b"".as_ref(), MccLine::Uuid(b"1234".as_ref())))
); );
assert_eq!( assert_eq!(
uuid(b"UUID=1234\r\n".as_ref()), uuid(b"UUID=1234\r\n".as_ref()),
Ok((b"".as_ref(), MccLine::UUID(b"1234".as_ref()))) Ok((b"".as_ref(), MccLine::Uuid(b"1234".as_ref())))
); );
assert_eq!( assert_eq!(
@ -697,10 +697,10 @@ mod tests {
match line_cnt { match line_cnt {
0 => assert_eq!(res, MccLine::Header), 0 => assert_eq!(res, MccLine::Header),
1 | 37 | 43 => assert_eq!(res, MccLine::Empty), 1 | 37 | 43 => assert_eq!(res, MccLine::Empty),
x if x >= 2 && x <= 36 => assert_eq!(res, MccLine::Comment), x if (2..=36).contains(&x) => assert_eq!(res, MccLine::Comment),
38 => assert_eq!( 38 => assert_eq!(
res, res,
MccLine::UUID(b"CA8BC94D-9931-4EEE-812F-2D68FA74F287".as_ref()) MccLine::Uuid(b"CA8BC94D-9931-4EEE-812F-2D68FA74F287".as_ref())
), ),
39 => assert_eq!( 39 => assert_eq!(
res, res,

View file

@ -78,9 +78,9 @@ fn scc_payload_item(s: &[u8]) -> IResult<&[u8], (u8, u8)> {
"invalid SCC payload item", "invalid SCC payload item",
map(take_while_m_n(4, 4, is_hex_digit), |s: &[u8]| { map(take_while_m_n(4, 4, is_hex_digit), |s: &[u8]| {
let hex_to_u8 = |v: u8| match v { let hex_to_u8 = |v: u8| match v {
v if v >= b'0' && v <= b'9' => v - b'0', v if (b'0'..=b'9').contains(&v) => v - b'0',
v if v >= b'A' && v <= b'F' => 10 + v - b'A', v if (b'A'..=b'F').contains(&v) => 10 + v - b'A',
v if v >= b'a' && v <= b'f' => 10 + v - b'a', v if (b'a'..=b'f').contains(&v) => 10 + v - b'a',
_ => unreachable!(), _ => unreachable!(),
}; };

View file

@ -398,6 +398,7 @@ impl TranscriberBin {
Ok(()) Ok(())
} }
#[allow(clippy::single_match)]
fn src_query( fn src_query(
&self, &self,
pad: &gst::Pad, pad: &gst::Pad,
@ -474,6 +475,7 @@ impl TranscriberBin {
}) })
} }
#[allow(clippy::single_match)]
fn video_sink_event( fn video_sink_event(
&self, &self,
pad: &gst::Pad, pad: &gst::Pad,
@ -815,6 +817,7 @@ impl ElementImpl for TranscriberBin {
PAD_TEMPLATES.as_ref() PAD_TEMPLATES.as_ref()
} }
#[allow(clippy::single_match)]
fn change_state( fn change_state(
&self, &self,
element: &Self::Type, element: &Self::Type,

View file

@ -1217,6 +1217,7 @@ impl ElementImpl for TtToCea608 {
PAD_TEMPLATES.as_ref() PAD_TEMPLATES.as_ref()
} }
#[allow(clippy::single_match)]
fn change_state( fn change_state(
&self, &self,
element: &Self::Type, element: &Self::Type,

View file

@ -15,6 +15,8 @@
// Free Software Foundation, Inc., 51 Franklin Street, Suite 500, // Free Software Foundation, Inc., 51 Franklin Street, Suite 500,
// Boston, MA 02110-1335, USA. // Boston, MA 02110-1335, USA.
#![allow(clippy::single_match)]
use gst::prelude::*; use gst::prelude::*;
use gst::EventView; use gst::EventView;
use pretty_assertions::assert_eq; use pretty_assertions::assert_eq;

View file

@ -16,6 +16,8 @@
// Free Software Foundation, Inc., 51 Franklin Street, Suite 500, // Free Software Foundation, Inc., 51 Franklin Street, Suite 500,
// Boston, MA 02110-1335, USA. // Boston, MA 02110-1335, USA.
#![allow(clippy::single_match)]
use gst::prelude::*; use gst::prelude::*;
use gst::EventView; use gst::EventView;
use gst_video::{ValidVideoTimeCode, VideoTimeCode}; use gst_video::{ValidVideoTimeCode, VideoTimeCode};

View file

@ -8,8 +8,6 @@
// Reference used for implementation: https://en.wikipedia.org/wiki/HSL_and_HSV // Reference used for implementation: https://en.wikipedia.org/wiki/HSL_and_HSV
#![allow(unstable_name_collisions)]
// Since the standard 'clamp' feature is still considered unstable, we provide // Since the standard 'clamp' feature is still considered unstable, we provide
// a subsititute implementaion here so we can still build with the stable toolchain. // a subsititute implementaion here so we can still build with the stable toolchain.
// Source: https://github.com/rust-lang/rust/issues/44095#issuecomment-624879262 // Source: https://github.com/rust-lang/rust/issues/44095#issuecomment-624879262

View file

@ -151,7 +151,6 @@ pub struct WebPDec {
} }
impl WebPDec { impl WebPDec {
#![allow(clippy::unnecessary_wraps)]
fn sink_chain( fn sink_chain(
&self, &self,
pad: &gst::Pad, pad: &gst::Pad,