From 96d86eaa069165f42abe6a0907c99016cab5db52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Wed, 8 Sep 2021 15:33:31 +0300 Subject: [PATCH] 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. --- .gitlab-ci.yml | 2 +- audio/audiofx/src/audioloudnorm/imp.rs | 4 +- audio/audiofx/tests/ebur128level.rs | 2 + net/reqwest/tests/reqwesthttpsrc.rs | 2 + net/rusoto/src/aws_transcriber/imp.rs | 19 ++-- text/json/tests/json.rs | 4 +- text/wrap/src/gsttextwrap/imp.rs | 7 +- .../fallbackswitch/src/fallbackswitch/imp.rs | 14 ++- utils/togglerecord/src/togglerecord/imp.rs | 1 + video/closedcaption/src/ccdetect/imp.rs | 11 ++- video/closedcaption/src/cea608overlay/imp.rs | 91 ++++++++----------- video/closedcaption/src/cea608tojson/imp.rs | 8 +- video/closedcaption/src/cea608tott/imp.rs | 1 + video/closedcaption/src/mcc_parse/parser.rs | 20 ++-- video/closedcaption/src/scc_parse/parser.rs | 6 +- video/closedcaption/src/transcriberbin/imp.rs | 3 + video/closedcaption/src/tttocea608/imp.rs | 1 + video/closedcaption/tests/mcc_parse.rs | 2 + video/closedcaption/tests/scc_parse.rs | 2 + video/hsv/src/hsvutils.rs | 2 - video/webp/src/dec/imp.rs | 1 - 21 files changed, 104 insertions(+), 99 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index ef742156..2159109b 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -208,7 +208,7 @@ clippy: rules: - when: 'always' 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: extends: .img-stable diff --git a/audio/audiofx/src/audioloudnorm/imp.rs b/audio/audiofx/src/audioloudnorm/imp.rs index 22eccec0..429f64ed 100644 --- a/audio/audiofx/src/audioloudnorm/imp.rs +++ b/audio/audiofx/src/audioloudnorm/imp.rs @@ -1049,7 +1049,7 @@ impl State { // Calculate the current position in the attack window 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; // Need to sustain in any case for this many samples to actually @@ -1684,6 +1684,7 @@ impl AudioLoudNorm { pad.event_default(Some(element), event) } + #[allow(clippy::single_match)] fn src_query( &self, pad: &gst::Pad, @@ -1911,6 +1912,7 @@ impl ElementImpl for AudioLoudNorm { PAD_TEMPLATES.as_ref() } + #[allow(clippy::single_match)] fn change_state( &self, element: &Self::Type, diff --git a/audio/audiofx/tests/ebur128level.rs b/audio/audiofx/tests/ebur128level.rs index 95a8f6d1..30f98654 100644 --- a/audio/audiofx/tests/ebur128level.rs +++ b/audio/audiofx/tests/ebur128level.rs @@ -6,6 +6,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![allow(clippy::single_match)] + use gst::glib; use gst::prelude::*; diff --git a/net/reqwest/tests/reqwesthttpsrc.rs b/net/reqwest/tests/reqwesthttpsrc.rs index 9f65544e..afe16216 100644 --- a/net/reqwest/tests/reqwesthttpsrc.rs +++ b/net/reqwest/tests/reqwesthttpsrc.rs @@ -6,6 +6,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![allow(clippy::single_match)] + use gst::glib; use gst::prelude::*; diff --git a/net/rusoto/src/aws_transcriber/imp.rs b/net/rusoto/src/aws_transcriber/imp.rs index b5c7ef42..ce3a53e8 100644 --- a/net/rusoto/src/aws_transcriber/imp.rs +++ b/net/rusoto/src/aws_transcriber/imp.rs @@ -589,17 +589,14 @@ impl Transcriber { }; let transcribe = Self::from_instance(&element); - match transcribe.loop_fn(&element, &mut receiver) { - Err(err) => { - element_error!( - &element, - gst::StreamError::Failed, - ["Streaming failed: {}", err] - ); - let _ = transcribe.srcpad.pause_task(); - } - Ok(_) => (), - }; + if let Err(err) = transcribe.loop_fn(&element, &mut receiver) { + element_error!( + &element, + gst::StreamError::Failed, + ["Streaming failed: {}", err] + ); + let _ = transcribe.srcpad.pause_task(); + } }); if res.is_err() { return Err(loggable_error!(CAT, "Failed to start pad task")); diff --git a/text/json/tests/json.rs b/text/json/tests/json.rs index bbe35fb5..f628e38d 100644 --- a/text/json/tests/json.rs +++ b/text/json/tests/json.rs @@ -15,7 +15,7 @@ // Free Software Foundation, Inc., 51 Franklin Street, Suite 500, // Boston, MA 02110-1335, USA. -use gst::EventView; +#![allow(clippy::single_match)] fn init() { use std::sync::Once; @@ -83,6 +83,8 @@ fn test_parse() { } while h.events_in_queue() > 0 { + use gst::EventView; + let ev = h.pull_event().unwrap(); match ev.view() { diff --git a/text/wrap/src/gsttextwrap/imp.rs b/text/wrap/src/gsttextwrap/imp.rs index 7fef1f06..d01e310a 100644 --- a/text/wrap/src/gsttextwrap/imp.rs +++ b/text/wrap/src/gsttextwrap/imp.rs @@ -201,13 +201,14 @@ impl TextWrap { let mut bufferlist = gst::BufferList::new(); let n_lines = std::cmp::max(self.settings.lock().unwrap().lines, 1); - if state + let add_buffer = state .start_ts .zip(Some(accumulate_time)) .map_or(false, |(start_ts, accumulate_time)| { start_ts + accumulate_time < pts - }) - { + }); + + if add_buffer { let mut buf = gst::Buffer::from_mut_slice(mem::take(&mut state.current_text).into_bytes()); { diff --git a/utils/fallbackswitch/src/fallbackswitch/imp.rs b/utils/fallbackswitch/src/fallbackswitch/imp.rs index 618c2a50..84da0899 100644 --- a/utils/fallbackswitch/src/fallbackswitch/imp.rs +++ b/utils/fallbackswitch/src/fallbackswitch/imp.rs @@ -128,6 +128,7 @@ impl Default for Settings { } impl OutputState { + #[allow(clippy::blocks_in_if_conditions)] fn health( &self, settings: &Settings, @@ -301,12 +302,13 @@ impl FallbackSwitch { 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, |(last_output_time, running_time)| { last_output_time + settings.timeout <= running_time }, - ) { + ); + if is_late { /* This buffer arrived too late - we either already switched * to the other pad or there's no point outputting this anyway */ gst_debug!( @@ -429,13 +431,15 @@ impl FallbackSwitch { }; if !ignore_timeout { - // Get the next one if this one is before the timeout - if state.last_output_time.zip(running_time).map_or( + let timed_out = !state.last_output_time.zip(running_time).map_or( false, |(last_output_time, 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!( CAT, obj: backup_pad, diff --git a/utils/togglerecord/src/togglerecord/imp.rs b/utils/togglerecord/src/togglerecord/imp.rs index 5ea63f22..e665c4e3 100644 --- a/utils/togglerecord/src/togglerecord/imp.rs +++ b/utils/togglerecord/src/togglerecord/imp.rs @@ -599,6 +599,7 @@ impl ToggleRecord { } } + #[allow(clippy::blocks_in_if_conditions)] fn handle_secondary_stream( &self, element: &super::ToggleRecord, diff --git a/video/closedcaption/src/ccdetect/imp.rs b/video/closedcaption/src/ccdetect/imp.rs index 5410ef34..ad1caf06 100644 --- a/video/closedcaption/src/ccdetect/imp.rs +++ b/video/closedcaption/src/ccdetect/imp.rs @@ -177,9 +177,11 @@ impl CCDetect { ); 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 - }) { + }); + + if changed { settings.cc608 = cc_packet.cc608; state.last_cc608_change = Some(ts); notify_cc608 = true; @@ -189,9 +191,10 @@ impl CCDetect { } 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 - }) { + }); + if changed { settings.cc708 = cc_packet.cc708; state.last_cc708_change = Some(ts); notify_cc708 = true; diff --git a/video/closedcaption/src/cea608overlay/imp.rs b/video/closedcaption/src/cea608overlay/imp.rs index bd817105..100416d5 100644 --- a/video/closedcaption/src/cea608overlay/imp.rs +++ b/video/closedcaption/src/cea608overlay/imp.rs @@ -353,26 +353,23 @@ impl Cea608Overlay { } if Some(cc_type) == state.selected_field { - match state + if let Ok(Status::Ready) = state .caption_frame .decode((triple[1] as u16) << 8 | triple[2] as u16, 0.0) { - Ok(Status::Ready) => { - let text = match state.caption_frame.to_text(true) { - Ok(text) => text, - Err(_) => { - gst_error!( - CAT, - obj: pad, - "Failed to convert caption frame to text" - ); - continue; - } - }; + let text = match state.caption_frame.to_text(true) { + Ok(text) => text, + Err(_) => { + gst_error!( + CAT, + obj: pad, + "Failed to convert caption frame to text" + ); + continue; + } + }; - self.overlay_text(element, &text, state); - } - _ => (), + self.overlay_text(element, &text, state); } } } else { @@ -406,26 +403,19 @@ impl Cea608Overlay { } if Some(cc_type) == state.selected_field { - match state + if let Ok(Status::Ready) = state .caption_frame .decode((triple[1] as u16) << 8 | triple[2] as u16, 0.0) { - Ok(Status::Ready) => { - let text = match state.caption_frame.to_text(true) { - Ok(text) => text, - Err(_) => { - gst_error!( - CAT, - obj: pad, - "Failed to convert caption frame to text" - ); - continue; - } - }; + let text = match state.caption_frame.to_text(true) { + Ok(text) => text, + Err(_) => { + gst_error!(CAT, obj: pad, "Failed to convert caption frame to text"); + continue; + } + }; - self.overlay_text(element, &text, state); - } - _ => (), + self.overlay_text(element, &text, state); } } } @@ -468,26 +458,23 @@ impl Cea608Overlay { let data = meta.data(); assert!(data.len() % 2 == 0); for i in 0..data.len() / 2 { - match state + if let Ok(Status::Ready) = state .caption_frame .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) { - Ok(text) => text, - Err(_) => { - gst_error!( - CAT, - obj: pad, - "Failed to convert caption frame to text" - ); - continue; - } - }; + let text = match state.caption_frame.to_text(true) { + Ok(text) => text, + Err(_) => { + gst_error!( + CAT, + obj: pad, + "Failed to convert caption frame to text" + ); + continue; + } + }; - self.overlay_text(element, &text, &mut state); - } - _ => (), + self.overlay_text(element, &text, &mut state); } } } @@ -503,11 +490,9 @@ impl Cea608Overlay { state.video_info.as_ref().unwrap(), ) .unwrap(); - match composition.blend(&mut frame) { - Err(_) => { - gst_error!(CAT, obj: pad, "Failed to blend composition"); - } - _ => (), + + if composition.blend(&mut frame).is_err() { + gst_error!(CAT, obj: pad, "Failed to blend composition"); } } } diff --git a/video/closedcaption/src/cea608tojson/imp.rs b/video/closedcaption/src/cea608tojson/imp.rs index 8aaf3958..faf49aeb 100644 --- a/video/closedcaption/src/cea608tojson/imp.rs +++ b/video/closedcaption/src/cea608tojson/imp.rs @@ -547,10 +547,9 @@ impl State { ret } Cea608Mode::PopOn => { - #[allow(clippy::map_entry)] - if !self.rows.contains_key(&self.cursor.row) { - self.rows.insert(self.cursor.row, Row::new(self.cursor.row)); - } + let row = self.cursor.row; + self.rows.entry(row).or_insert_with(|| Row::new(row)); + None } } @@ -930,6 +929,7 @@ impl ElementImpl for Cea608ToJson { PAD_TEMPLATES.as_ref() } + #[allow(clippy::single_match)] fn change_state( &self, element: &Self::Type, diff --git a/video/closedcaption/src/cea608tott/imp.rs b/video/closedcaption/src/cea608tott/imp.rs index 3dc1c338..83646dca 100644 --- a/video/closedcaption/src/cea608tott/imp.rs +++ b/video/closedcaption/src/cea608tott/imp.rs @@ -482,6 +482,7 @@ impl ElementImpl for Cea608ToTt { PAD_TEMPLATES.as_ref() } + #[allow(clippy::single_match)] fn change_state( &self, element: &Self::Type, diff --git a/video/closedcaption/src/mcc_parse/parser.rs b/video/closedcaption/src/mcc_parse/parser.rs index f08ffaa2..d52bd2f4 100644 --- a/video/closedcaption/src/mcc_parse/parser.rs +++ b/video/closedcaption/src/mcc_parse/parser.rs @@ -25,7 +25,7 @@ pub enum MccLine<'a> { Header, Comment, Empty, - UUID(&'a [u8]), + Uuid(&'a [u8]), Metadata(&'a [u8], &'a [u8]), TimeCodeRate(u8, bool), Caption(TimeCode, Option>), @@ -96,7 +96,7 @@ fn uuid(s: &[u8]) -> IResult<&[u8], MccLine> { take_while1(|b| b != b'\n' && b != b'\r'), end_of_line, )), - |(_, uuid, _)| MccLine::UUID(uuid), + |(_, uuid, _)| MccLine::Uuid(uuid), ), )(s) } @@ -238,9 +238,9 @@ fn mcc_payload_item(s: &[u8]) -> IResult<&[u8], Either> { map(tag("Z"), |_| Either::Right([0x00].as_ref())), map(take_while_m_n(2, 2, is_hex_digit), |s: &[u8]| { let hex_to_u8 = |v: u8| match v { - v if v >= b'0' && v <= b'9' => v - b'0', - v if v >= b'A' && v <= b'F' => 10 + v - b'A', - v if v >= b'a' && v <= b'f' => 10 + v - b'a', + v if (b'0'..=b'9').contains(&v) => v - b'0', + v if (b'A'..=b'F').contains(&v) => 10 + v - b'A', + v if (b'a'..=b'f').contains(&v) => 10 + v - b'a', _ => unreachable!(), }; let val = (hex_to_u8(s[0]) << 4) | hex_to_u8(s[1]); @@ -472,17 +472,17 @@ mod tests { fn test_uuid() { assert_eq!( 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!( 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!( 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!( @@ -697,10 +697,10 @@ mod tests { match line_cnt { 0 => assert_eq!(res, MccLine::Header), 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!( res, - MccLine::UUID(b"CA8BC94D-9931-4EEE-812F-2D68FA74F287".as_ref()) + MccLine::Uuid(b"CA8BC94D-9931-4EEE-812F-2D68FA74F287".as_ref()) ), 39 => assert_eq!( res, diff --git a/video/closedcaption/src/scc_parse/parser.rs b/video/closedcaption/src/scc_parse/parser.rs index ca2ae35f..903ee9bd 100644 --- a/video/closedcaption/src/scc_parse/parser.rs +++ b/video/closedcaption/src/scc_parse/parser.rs @@ -78,9 +78,9 @@ fn scc_payload_item(s: &[u8]) -> IResult<&[u8], (u8, u8)> { "invalid SCC payload item", map(take_while_m_n(4, 4, is_hex_digit), |s: &[u8]| { let hex_to_u8 = |v: u8| match v { - v if v >= b'0' && v <= b'9' => v - b'0', - v if v >= b'A' && v <= b'F' => 10 + v - b'A', - v if v >= b'a' && v <= b'f' => 10 + v - b'a', + v if (b'0'..=b'9').contains(&v) => v - b'0', + v if (b'A'..=b'F').contains(&v) => 10 + v - b'A', + v if (b'a'..=b'f').contains(&v) => 10 + v - b'a', _ => unreachable!(), }; diff --git a/video/closedcaption/src/transcriberbin/imp.rs b/video/closedcaption/src/transcriberbin/imp.rs index 9f75fffa..1361f1fc 100644 --- a/video/closedcaption/src/transcriberbin/imp.rs +++ b/video/closedcaption/src/transcriberbin/imp.rs @@ -398,6 +398,7 @@ impl TranscriberBin { Ok(()) } + #[allow(clippy::single_match)] fn src_query( &self, pad: &gst::Pad, @@ -474,6 +475,7 @@ impl TranscriberBin { }) } + #[allow(clippy::single_match)] fn video_sink_event( &self, pad: &gst::Pad, @@ -815,6 +817,7 @@ impl ElementImpl for TranscriberBin { PAD_TEMPLATES.as_ref() } + #[allow(clippy::single_match)] fn change_state( &self, element: &Self::Type, diff --git a/video/closedcaption/src/tttocea608/imp.rs b/video/closedcaption/src/tttocea608/imp.rs index ecfccb6f..c47562d6 100644 --- a/video/closedcaption/src/tttocea608/imp.rs +++ b/video/closedcaption/src/tttocea608/imp.rs @@ -1217,6 +1217,7 @@ impl ElementImpl for TtToCea608 { PAD_TEMPLATES.as_ref() } + #[allow(clippy::single_match)] fn change_state( &self, element: &Self::Type, diff --git a/video/closedcaption/tests/mcc_parse.rs b/video/closedcaption/tests/mcc_parse.rs index e2e9b75b..49ead5b8 100644 --- a/video/closedcaption/tests/mcc_parse.rs +++ b/video/closedcaption/tests/mcc_parse.rs @@ -15,6 +15,8 @@ // Free Software Foundation, Inc., 51 Franklin Street, Suite 500, // Boston, MA 02110-1335, USA. +#![allow(clippy::single_match)] + use gst::prelude::*; use gst::EventView; use pretty_assertions::assert_eq; diff --git a/video/closedcaption/tests/scc_parse.rs b/video/closedcaption/tests/scc_parse.rs index c690e14e..404de9d4 100644 --- a/video/closedcaption/tests/scc_parse.rs +++ b/video/closedcaption/tests/scc_parse.rs @@ -16,6 +16,8 @@ // Free Software Foundation, Inc., 51 Franklin Street, Suite 500, // Boston, MA 02110-1335, USA. +#![allow(clippy::single_match)] + use gst::prelude::*; use gst::EventView; use gst_video::{ValidVideoTimeCode, VideoTimeCode}; diff --git a/video/hsv/src/hsvutils.rs b/video/hsv/src/hsvutils.rs index ab2f54ba..18a23aae 100644 --- a/video/hsv/src/hsvutils.rs +++ b/video/hsv/src/hsvutils.rs @@ -8,8 +8,6 @@ // 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 // a subsititute implementaion here so we can still build with the stable toolchain. // Source: https://github.com/rust-lang/rust/issues/44095#issuecomment-624879262 diff --git a/video/webp/src/dec/imp.rs b/video/webp/src/dec/imp.rs index d5ad0e37..26ae39b8 100644 --- a/video/webp/src/dec/imp.rs +++ b/video/webp/src/dec/imp.rs @@ -151,7 +151,6 @@ pub struct WebPDec { } impl WebPDec { - #![allow(clippy::unnecessary_wraps)] fn sink_chain( &self, pad: &gst::Pad,