From b341f14565d1975be05246b703bb28af2820094d Mon Sep 17 00:00:00 2001 From: tyranron Date: Tue, 10 Sep 2024 15:45:13 +0300 Subject: [PATCH] Tune lints for 1.81 Rust - bump up MSRV to 1.81 Additionally: - update `cxx` crate to 1.0.128 version --- Cargo.lock | 12 ++++---- Makefile | 4 +-- crates/libwebrtc-sys/Cargo.toml | 2 +- crates/libwebrtc-sys/build.rs | 10 +++++-- crates/libwebrtc-sys/src/bridge.rs | 38 ++++++++++++------------ crates/libwebrtc-sys/src/lib.rs | 16 +++++++---- crates/native/Cargo.toml | 2 +- crates/native/build.rs | 11 +++++-- crates/native/src/api/mod.rs | 46 ++++++++++++++---------------- crates/native/src/devices.rs | 11 ++++--- crates/native/src/lib.rs | 14 +++++---- crates/native/src/renderer.rs | 6 ++-- crates/native/src/user_media.rs | 31 +++++++++++--------- 13 files changed, 111 insertions(+), 92 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2bef62be37..6f24033110 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -204,9 +204,9 @@ dependencies = [ [[package]] name = "cxx" -version = "1.0.124" +version = "1.0.128" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "273dcfd3acd4e1e276af13ed2a43eea7001318823e7a726a6b3ed39b4acc0b82" +checksum = "54ccead7d199d584d139148b04b4a368d1ec7556a1d9ea2548febb1b9d49f9a4" dependencies = [ "cc", "cxxbridge-flags", @@ -231,15 +231,15 @@ dependencies = [ [[package]] name = "cxxbridge-flags" -version = "1.0.124" +version = "1.0.128" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "839fcd5e43464614ffaa989eaf1c139ef1f0c51672a1ed08023307fa1b909ccd" +checksum = "65777e06cc48f0cb0152024c77d6cf9e4bdb4408e7b48bea993d42fa0f5b02b6" [[package]] name = "cxxbridge-macro" -version = "1.0.124" +version = "1.0.128" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4b2c1c1776b986979be68bb2285da855f8d8a35851a769fca8740df7c3d07877" +checksum = "98532a60dedaebc4848cb2cba5023337cc9ea3af16a5b062633fabfd9f18fb60" dependencies = [ "proc-macro2", "quote", diff --git a/Makefile b/Makefile index 25dc8eed65..7092c938b8 100644 --- a/Makefile +++ b/Makefile @@ -15,8 +15,8 @@ eq = $(if $(or $(1),$(2)),$(and $(findstring $(1),$(2)),\ # Project parameters # ###################### -RUST_VER ?= 1.75 -RUST_NIGHTLY_VER ?= nightly-2024-01-02 +RUST_VER ?= 1.81 +RUST_NIGHTLY_VER ?= nightly-2024-09-08 FLUTTER_RUST_BRIDGE_VER ?= $(strip \ $(shell grep -A1 'name = "flutter_rust_bridge"' Cargo.lock \ diff --git a/crates/libwebrtc-sys/Cargo.toml b/crates/libwebrtc-sys/Cargo.toml index 2a1c8ce5ec..589dc0daad 100644 --- a/crates/libwebrtc-sys/Cargo.toml +++ b/crates/libwebrtc-sys/Cargo.toml @@ -2,7 +2,7 @@ name = "libwebrtc-sys" version = "0.0.0+127.0.6533.72" edition = "2021" -rust-version = "1.75" +rust-version = "1.81" publish = false links = "webrtc" diff --git a/crates/libwebrtc-sys/build.rs b/crates/libwebrtc-sys/build.rs index dd0f30e7c6..f4623d6664 100644 --- a/crates/libwebrtc-sys/build.rs +++ b/crates/libwebrtc-sys/build.rs @@ -1,4 +1,8 @@ -#![warn(clippy::pedantic)] +#![warn( + clippy::allow_attributes, + clippy::allow_attributes_without_reason, + clippy::pedantic +)] #[cfg(not(target_os = "windows"))] use std::ffi::OsString; @@ -191,7 +195,7 @@ fn get_path_to_openal() -> anyhow::Result { /// Downloads and compiles OpenAL dynamic library. /// /// Copies OpenAL headers and compiled library to the required locations. -#[allow(clippy::too_many_lines)] +#[expect(clippy::too_many_lines, reason = "not matters here")] fn compile_openal() -> anyhow::Result<()> { let openal_version = OPENAL_URL.split('/').last().unwrap(); let manifest_path = PathBuf::from(env::var("CARGO_MANIFEST_DIR")?); @@ -401,7 +405,7 @@ fn get_cpp_files() -> anyhow::Result> { .join("src") .join("cpp"); - #[allow(unused_mut)] + #[cfg_attr(target_os = "macos", expect(unused_mut, reason = "cfg"))] let mut files = get_files_from_dir(dir); #[cfg(not(target_os = "macos"))] diff --git a/crates/libwebrtc-sys/src/bridge.rs b/crates/libwebrtc-sys/src/bridge.rs index 0602d62d97..9375c97517 100644 --- a/crates/libwebrtc-sys/src/bridge.rs +++ b/crates/libwebrtc-sys/src/bridge.rs @@ -1,3 +1,5 @@ +#![expect(clippy::allow_attributes, reason = "`cxx` fails on `#[expect]`")] + use std::fmt; use anyhow::anyhow; @@ -49,7 +51,7 @@ impl OptionI32 { } /// Creates an empty Rust [`Option`]`<`[`i32`]`>`. -#[allow(clippy::unnecessary_box_returns)] +#[expect(clippy::unnecessary_box_returns, reason = "FFI")] pub fn init_option_i32() -> Box { Box::new(OptionI32(None)) } @@ -69,7 +71,7 @@ impl OptionRtcpFeedbackMessageType { } /// Creates an empty Rust [`Option`]`<`[`RtcpFeedbackMessageType`]`>` value. -#[allow(clippy::unnecessary_box_returns)] // required for FFI +#[expect(clippy::unnecessary_box_returns, reason = "FFI")] pub fn init_option_rtcp_feedback_message_type( ) -> Box { Box::new(OptionRtcpFeedbackMessageType(None)) @@ -87,7 +89,7 @@ impl OptionString { } /// Creates an empty Rust [`Option`]`<`[`String`]`>`. -#[allow(clippy::unnecessary_box_returns)] +#[expect(clippy::unnecessary_box_returns, reason = "FFI")] pub fn init_option_string() -> Box { Box::new(OptionString(None)) } @@ -104,7 +106,7 @@ impl OptionF64 { } /// Creates an empty Rust [`Option`]`<`[`f64`]`>`. -#[allow(clippy::unnecessary_box_returns)] +#[expect(clippy::unnecessary_box_returns, reason = "FFI")] pub fn init_option_f64() -> Box { Box::new(OptionF64(None)) } @@ -121,7 +123,7 @@ impl OptionU32 { } /// Creates an empty Rust [`Option`]`<`[`u32`]`>`. -#[allow(clippy::unnecessary_box_returns)] +#[expect(clippy::unnecessary_box_returns, reason = "FFI")] pub fn init_option_u32() -> Box { Box::new(OptionU32(None)) } @@ -138,7 +140,7 @@ impl OptionU64 { } /// Creates an empty Rust [`Option`]`<`[`u64`]`>`. -#[allow(clippy::unnecessary_box_returns)] +#[expect(clippy::unnecessary_box_returns, reason = "FFI")] pub fn init_option_u64() -> Box { Box::new(OptionU64(None)) } @@ -155,12 +157,12 @@ impl OptionBool { } /// Creates an empty Rust [`Option`]`<`[`bool`]`>`. -#[allow(clippy::unnecessary_box_returns)] +#[expect(clippy::unnecessary_box_returns, reason = "FFI")] pub fn init_option_bool() -> Box { Box::new(OptionBool(None)) } -#[allow(clippy::unnecessary_box_returns)] +#[allow(clippy::unnecessary_box_returns, reason = "FFI")] #[cxx::bridge(namespace = "bridge")] pub(crate) mod webrtc { /// Wrapper for a `(String, String)` tuple transferable via FFI boundaries. @@ -2246,7 +2248,7 @@ pub(crate) mod webrtc { ); } - #[allow(dead_code)] + #[allow(dead_code, reason = "FFI")] #[rustfmt::skip] unsafe extern "C++" { pub type RTCMediaSourceStats; @@ -2811,7 +2813,7 @@ pub(crate) mod webrtc { /// # Safety /// /// Caller must ensure that the provided `buffer` is large enough. - #[allow(clippy::missing_safety_doc)] // false positive + #[allow(clippy::missing_safety_doc, reason = "false positive")] pub unsafe fn video_frame_to_abgr(frame: &VideoFrame, buffer: *mut u8); /// Converts the provided [`webrtc::VideoFrame`] pixels to the `ARGB` @@ -2820,7 +2822,7 @@ pub(crate) mod webrtc { /// # Safety /// /// Caller must ensure that the provided `buffer` is large enough. - #[allow(clippy::missing_safety_doc)] // false positive + #[allow(clippy::missing_safety_doc, reason = "false positive")] pub unsafe fn video_frame_to_argb( frame: &VideoFrame, argb_stride: i32, @@ -3148,7 +3150,7 @@ pub(crate) mod webrtc { } /// Successfully completes the provided [`DynSetDescriptionCallback`]. -#[allow(clippy::boxed_local)] +#[expect(clippy::boxed_local, reason = "FFI")] pub fn create_sdp_success( mut cb: Box, sdp: &CxxString, @@ -3158,19 +3160,19 @@ pub fn create_sdp_success( } /// Completes the provided [`DynCreateSdpCallback`] with an error. -#[allow(clippy::boxed_local)] +#[expect(clippy::boxed_local, reason = "FFI")] pub fn create_sdp_fail(mut cb: Box, error: &CxxString) { cb.fail(error); } /// Successfully completes the provided [`DynSetDescriptionCallback`]. -#[allow(clippy::boxed_local)] +#[expect(clippy::boxed_local, reason = "FFI")] pub fn set_description_success(mut cb: Box) { cb.success(); } /// Completes the provided [`DynSetDescriptionCallback`] with the given `error`. -#[allow(clippy::boxed_local)] +#[expect(clippy::boxed_local, reason = "FFI")] pub fn set_description_fail( mut cb: Box, error: &CxxString, @@ -3378,13 +3380,13 @@ fn new_string_pair(f: &CxxString, s: &CxxString) -> webrtc::StringPair { } /// Calls the success [`DynAddIceCandidateCallback`]. -#[allow(clippy::boxed_local)] +#[expect(clippy::boxed_local, reason = "FFI")] pub fn add_ice_candidate_success(mut cb: Box) { cb.on_success(); } /// Calls the fail [`DynAddIceCandidateCallback`]. -#[allow(clippy::boxed_local)] +#[expect(clippy::boxed_local, reason = "FFI")] pub fn add_ice_candidate_fail( mut cb: Box, error: &CxxString, @@ -3394,7 +3396,7 @@ pub fn add_ice_candidate_fail( /// Forwards the specified [`RTCStatsReport`] to the provided /// [`DynRTCStatsCollectorCallback`] when stats are delivered. -#[allow(clippy::boxed_local)] +#[expect(clippy::boxed_local, reason = "FFI")] pub fn on_stats_delivered( mut cb: Box, report: UniquePtr, diff --git a/crates/libwebrtc-sys/src/lib.rs b/crates/libwebrtc-sys/src/lib.rs index 393fa7f1a9..c0b1e74cc0 100644 --- a/crates/libwebrtc-sys/src/lib.rs +++ b/crates/libwebrtc-sys/src/lib.rs @@ -1,5 +1,10 @@ -#![warn(clippy::pedantic)] -#![allow(clippy::missing_errors_doc)] +#![warn( + clippy::allow_attributes, + clippy::allow_attributes_without_reason, + clippy::pedantic +)] +// TODO: Needs refactoring +#![expect(clippy::missing_errors_doc, reason = "needs refactoring")] mod bridge; @@ -245,14 +250,14 @@ impl AudioDeviceModule { /// Returns count of available audio playout devices. #[must_use] - #[allow(clippy::cast_sign_loss)] + #[expect(clippy::cast_sign_loss, reason = "never negative")] pub fn playout_devices(&self) -> u32 { webrtc::playout_devices(&self.0).max(0) as u32 } /// Returns count of available audio recording devices. #[must_use] - #[allow(clippy::cast_sign_loss)] + #[expect(clippy::cast_sign_loss, reason = "never negative")] pub fn recording_devices(&self) -> u32 { webrtc::recording_devices(&self.0).max(0) as u32 } @@ -3027,7 +3032,8 @@ pub enum RtcStatsType { Unimplemented, } -#[allow(clippy::too_many_lines)] +// TODO: Needs refactoring. +#[expect(clippy::too_many_lines, reason = "needs refactoring")] impl TryFrom for RtcStatsType { type Error = anyhow::Error; diff --git a/crates/native/Cargo.toml b/crates/native/Cargo.toml index c5e4058676..fe67e6a303 100644 --- a/crates/native/Cargo.toml +++ b/crates/native/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "medea-flutter-webrtc-native" edition = "2021" -rust-version = "1.75" +rust-version = "1.81" publish = false [lib] diff --git a/crates/native/build.rs b/crates/native/build.rs index b5fed8adf1..8ad9962337 100644 --- a/crates/native/build.rs +++ b/crates/native/build.rs @@ -1,9 +1,16 @@ -#![warn(clippy::pedantic)] +#![warn( + clippy::allow_attributes, + clippy::allow_attributes_without_reason, + clippy::pedantic +)] #[cfg(target_os = "macos")] use std::{env, path::PathBuf, process}; -#[allow(clippy::unnecessary_wraps)] +#[cfg_attr( + not(target_os = "macos"), + expect(clippy::unnecessary_wraps, reason = "uniformity") +)] fn main() -> anyhow::Result<()> { #[cfg(target_os = "macos")] { diff --git a/crates/native/src/api/mod.rs b/crates/native/src/api/mod.rs index cbf5c2d80c..b08bf24955 100644 --- a/crates/native/src/api/mod.rs +++ b/crates/native/src/api/mod.rs @@ -1372,7 +1372,7 @@ pub enum RtcStatsType { } impl From for RtcStatsType { - #[allow(clippy::too_many_lines)] + #[expect(clippy::too_many_lines, reason = "trivial code")] fn from(kind: sys::RtcStatsType) -> Self { use sys::RtcStatsType as T; @@ -2425,13 +2425,11 @@ pub enum VideoCodec { /// [H.264] Advanced Video Coding (AVC). /// /// [H.264]: https://en.wikipedia.org/wiki/Advanced_Video_Coding - #[allow(dead_code)] H264, /// [H.265] High Efficiency Video Coding (HEVC). /// /// [H.265]: https://en.wikipedia.org/wiki/High_Efficiency_Video_Coding - #[allow(dead_code)] H265, /// [VP8] codec. @@ -2516,7 +2514,7 @@ pub fn enumerate_displays() -> Vec { } /// Creates a new [`PeerConnection`] and returns its ID. -#[allow(clippy::needless_pass_by_value)] +#[expect(clippy::needless_pass_by_value, reason = "FFI")] pub fn create_peer_connection( cb: StreamSink, configuration: RtcConfiguration, @@ -2529,7 +2527,7 @@ pub fn create_peer_connection( /// Initiates the creation of an SDP offer for the purpose of starting a new /// WebRTC connection to a remote peer. -#[allow(clippy::needless_pass_by_value)] +#[expect(clippy::needless_pass_by_value, reason = "FFI")] pub fn create_offer( peer: RustOpaque>, voice_activity_detection: bool, @@ -2545,7 +2543,7 @@ pub fn create_offer( /// Creates an SDP answer to an offer received from a remote peer during an /// offer/answer negotiation of a WebRTC connection. -#[allow(clippy::needless_pass_by_value)] +#[expect(clippy::needless_pass_by_value, reason = "FFI")] pub fn create_answer( peer: RustOpaque>, voice_activity_detection: bool, @@ -2560,7 +2558,7 @@ pub fn create_answer( } /// Changes the local description associated with the connection. -#[allow(clippy::needless_pass_by_value)] +#[expect(clippy::needless_pass_by_value, reason = "FFI")] pub fn set_local_description( peer: RustOpaque>, kind: SdpType, @@ -2575,7 +2573,7 @@ pub fn set_local_description( /// Sets the specified session description as the remote peer's current offer or /// answer. -#[allow(clippy::needless_pass_by_value)] +#[expect(clippy::needless_pass_by_value, reason = "FFI")] pub fn set_remote_description( peer: RustOpaque>, kind: SdpType, @@ -2586,7 +2584,6 @@ pub fn set_remote_description( /// Creates a new [`RtcRtpTransceiver`] and adds it to the set of transceivers /// of the specified [`PeerConnection`]. -#[allow(clippy::needless_pass_by_value)] pub fn add_transceiver( peer: RustOpaque>, media_type: MediaType, @@ -2597,7 +2594,7 @@ pub fn add_transceiver( /// Returns a sequence of [`RtcRtpTransceiver`] objects representing the RTP /// transceivers currently attached to the specified [`PeerConnection`]. -#[allow(clippy::needless_pass_by_value)] +#[expect(clippy::needless_pass_by_value, reason = "FFI")] pub fn get_transceivers( peer: RustOpaque>, ) -> Vec { @@ -2605,7 +2602,7 @@ pub fn get_transceivers( } /// Changes the preferred `direction` of the specified [`RtcRtpTransceiver`]. -#[allow(clippy::needless_pass_by_value)] +#[expect(clippy::needless_pass_by_value, reason = "FFI")] pub fn set_transceiver_direction( transceiver: RustOpaque>, direction: RtpTransceiverDirection, @@ -2614,7 +2611,7 @@ pub fn set_transceiver_direction( } /// Changes the receive direction of the specified [`RtcRtpTransceiver`]. -#[allow(clippy::needless_pass_by_value)] +#[expect(clippy::needless_pass_by_value, reason = "FFI")] pub fn set_transceiver_recv( transceiver: RustOpaque>, recv: bool, @@ -2623,7 +2620,7 @@ pub fn set_transceiver_recv( } /// Changes the send direction of the specified [`RtcRtpTransceiver`]. -#[allow(clippy::needless_pass_by_value)] +#[expect(clippy::needless_pass_by_value, reason = "FFI")] pub fn set_transceiver_send( transceiver: RustOpaque>, send: bool, @@ -2635,7 +2632,7 @@ pub fn set_transceiver_send( /// [`RtcRtpTransceiver`]. /// /// [1]: https://w3.org/TR/webrtc#dfn-media-stream-identification-tag -#[allow(clippy::needless_pass_by_value)] +#[expect(clippy::needless_pass_by_value, reason = "FFI")] pub fn get_transceiver_mid( transceiver: RustOpaque>, ) -> Option { @@ -2643,7 +2640,7 @@ pub fn get_transceiver_mid( } /// Returns the preferred direction of the specified [`RtcRtpTransceiver`]. -#[allow(clippy::needless_pass_by_value)] +#[expect(clippy::needless_pass_by_value, reason = "FFI")] pub fn get_transceiver_direction( transceiver: RustOpaque>, ) -> RtpTransceiverDirection { @@ -2651,7 +2648,7 @@ pub fn get_transceiver_direction( } /// Returns [`RtcStats`] of the [`PeerConnection`] by its ID. -#[allow(clippy::needless_pass_by_value)] +#[expect(clippy::needless_pass_by_value, reason = "FFI")] pub fn get_peer_stats( peer: RustOpaque>, ) -> anyhow::Result> { @@ -2672,7 +2669,7 @@ pub fn get_peer_stats( /// /// This will immediately cause the transceiver's sender to no longer send, and /// its receiver to no longer receive. -#[allow(clippy::needless_pass_by_value)] +#[expect(clippy::needless_pass_by_value, reason = "FFI")] pub fn stop_transceiver( transceiver: RustOpaque>, ) -> anyhow::Result<()> { @@ -2681,7 +2678,7 @@ pub fn stop_transceiver( /// Changes the preferred [`RtpTransceiver`] codecs to the provided /// [`Vec`]`<`[`RtpCodecCapability`]`>`. -#[allow(clippy::needless_pass_by_value)] +#[expect(clippy::needless_pass_by_value, reason = "FFI")] pub fn set_codec_preferences( transceiver: RustOpaque>, codecs: Vec, @@ -2691,7 +2688,7 @@ pub fn set_codec_preferences( /// Replaces the specified [`AudioTrack`] (or [`VideoTrack`]) on the /// [`sys::Transceiver`]'s `sender`. -#[allow(clippy::needless_pass_by_value)] +#[expect(clippy::needless_pass_by_value, reason = "FFI")] pub fn sender_replace_track( peer: RustOpaque>, transceiver: RustOpaque>, @@ -2704,7 +2701,7 @@ pub fn sender_replace_track( } /// Returns [`RtpParameters`] from the provided [`RtpTransceiver`]'s `sender`. -#[allow(clippy::needless_pass_by_value)] +#[expect(clippy::needless_pass_by_value, reason = "FFI")] pub fn sender_get_parameters( transceiver: RustOpaque>, ) -> RtcRtpSendParameters { @@ -2714,7 +2711,6 @@ pub fn sender_get_parameters( /// Returns the capabilities of an [RTP] sender of the specified [`MediaType`]. /// /// [RTP]: https://en.wikipedia.org/wiki/Real-time_Transport_Protocol -#[allow(clippy::needless_pass_by_value)] pub fn get_rtp_sender_capabilities(kind: MediaType) -> RtpCapabilities { RtpCapabilities::from( WEBRTC @@ -2726,7 +2722,7 @@ pub fn get_rtp_sender_capabilities(kind: MediaType) -> RtpCapabilities { } /// Sets [`RtpParameters`] into the provided [`RtpTransceiver`]'s `sender`. -#[allow(clippy::needless_pass_by_value)] +#[expect(clippy::needless_pass_by_value, reason = "FFI")] pub fn sender_set_parameters( transceiver: RustOpaque>, params: RtcRtpSendParameters, @@ -2735,7 +2731,7 @@ pub fn sender_set_parameters( } /// Adds the new ICE `candidate` to the given [`PeerConnection`]. -#[allow(clippy::needless_pass_by_value)] +#[expect(clippy::needless_pass_by_value, reason = "FFI")] pub fn add_ice_candidate( peer: RustOpaque>, candidate: String, @@ -2750,13 +2746,13 @@ pub fn add_ice_candidate( } /// Tells the [`PeerConnection`] that ICE should be restarted. -#[allow(clippy::needless_pass_by_value)] +#[expect(clippy::needless_pass_by_value, reason = "FFI")] pub fn restart_ice(peer: RustOpaque>) { peer.restart_ice(); } /// Closes the [`PeerConnection`]. -#[allow(clippy::needless_pass_by_value)] +#[expect(clippy::needless_pass_by_value, reason = "FFI")] pub fn dispose_peer_connection(peer: RustOpaque>) { WEBRTC.lock().unwrap().dispose_peer_connection(&peer); } diff --git a/crates/native/src/devices.rs b/crates/native/src/devices.rs index 473d9e02d1..02b3974bf0 100644 --- a/crates/native/src/devices.rs +++ b/crates/native/src/devices.rs @@ -135,7 +135,6 @@ impl Webrtc { let count_playout = self.audio_device_module.playout_devices(); let count_recording = self.audio_device_module.recording_devices(); - #[allow(clippy::cast_sign_loss)] let mut result = Vec::with_capacity((count_playout + count_recording) as usize); @@ -235,7 +234,7 @@ impl Webrtc { for i in 0..count { let (_, id) = self.audio_device_module.recording_device_name(i)?; if id == device_id.to_string() { - #[allow(clippy::cast_sign_loss)] + #[expect(clippy::cast_sign_loss, reason = "never negative")] return Ok(Some(i as u16)); } } @@ -261,7 +260,7 @@ impl Webrtc { for i in 0..count { let (_, id) = self.audio_device_module.playout_device_name(i)?; if id == device_id.to_string() { - #[allow(clippy::cast_sign_loss)] + #[expect(clippy::cast_sign_loss, reason = "never negative")] return Ok(Some(i as u16)); } } @@ -555,7 +554,7 @@ pub unsafe fn init() { } #[cfg(target_os = "windows")] -#[allow(unused_must_use)] +#[expect(unused_must_use, reason = "FFI")] mod win_default_device_callback { //! Implementation of the default audio output device changes detector for //! Windows. @@ -592,7 +591,7 @@ mod win_default_device_callback { #[windows::core::implement(IMMNotificationClient)] struct AudioEndpointCallback; - #[allow(non_snake_case)] + #[expect(non_snake_case, reason = "FFI")] impl IMMNotificationClient_Impl for AudioEndpointCallback_Impl { fn OnDeviceStateChanged( &self, @@ -719,7 +718,7 @@ pub unsafe fn init() { .collect::>(); let lpsz_class_name_ptr = lpsz_class_name.as_ptr(); - #[allow(clippy::cast_possible_truncation)] + #[expect(clippy::cast_possible_truncation, reason = "size fits")] let class = WNDCLASSEXW { cbSize: mem::size_of::() as u32, lpfnWndProc: Some(wndproc), diff --git a/crates/native/src/lib.rs b/crates/native/src/lib.rs index 75a62ca0de..fecb721a22 100644 --- a/crates/native/src/lib.rs +++ b/crates/native/src/lib.rs @@ -1,20 +1,22 @@ -#![warn(clippy::pedantic)] +#![warn( + clippy::allow_attributes, + clippy::allow_attributes_without_reason, + clippy::pedantic +)] mod api; -#[allow( +#[expect( // codegen + clippy::allow_attributes_without_reason, clippy::cast_lossless, clippy::cast_possible_truncation, clippy::cast_possible_wrap, - clippy::default_trait_access, - clippy::let_underscore_untyped, - clippy::ptr_as_ptr, clippy::redundant_else, clippy::semicolon_if_nothing_returned, clippy::too_many_lines, clippy::uninlined_format_args, clippy::unreadable_literal, clippy::wildcard_imports, - let_underscore_drop + reason = "codegen" )] #[rustfmt::skip] mod frb_generated; diff --git a/crates/native/src/renderer.rs b/crates/native/src/renderer.rs index fa82cb22dc..f04e2c3399 100644 --- a/crates/native/src/renderer.rs +++ b/crates/native/src/renderer.rs @@ -141,7 +141,7 @@ mod frame_handler { } impl From> for VideoFrame { - #[allow(clippy::cast_sign_loss)] + #[expect(clippy::cast_sign_loss, reason = "guarded by `assert!`")] fn from(frame: UniquePtr) -> Self { let height = frame.height(); let width = frame.width(); @@ -278,7 +278,7 @@ mod frame_handler { pub buffer_size: usize, /// Actual [`sys::VideoFrame`]. - #[allow(clippy::struct_field_names)] + #[expect(clippy::struct_field_names, reason = "naming is OK")] pub frame: *mut sys::VideoFrame, } @@ -297,7 +297,7 @@ mod frame_handler { } /// Passes the provided [`sys::VideoFrame`] to the C side listener. - #[allow(clippy::cast_sign_loss, clippy::too_many_lines)] + #[expect(clippy::cast_sign_loss, reason = "guarded by `assert!`")] pub fn on_frame(&mut self, frame: UniquePtr) { let height = frame.height(); let width = frame.width(); diff --git a/crates/native/src/user_media.rs b/crates/native/src/user_media.rs index 83e2dceb9a..220839fe9f 100644 --- a/crates/native/src/user_media.rs +++ b/crates/native/src/user_media.rs @@ -87,7 +87,7 @@ impl Webrtc { track_id: String, kind: api::MediaType, ) { - #[allow(clippy::mutable_key_type)] // false positive + #[expect(clippy::mutable_key_type, reason = "false positive")] let senders = match kind { api::MediaType::Audio => { if let Some((_, mut track)) = self @@ -432,7 +432,6 @@ impl Webrtc { } /// Clones the specified [`api::MediaStreamTrack`]. - #[allow(clippy::too_many_lines)] pub fn clone_track( &mut self, id: String, @@ -853,7 +852,11 @@ impl AudioDeviceModule { let volume = f64::from(min_volume) + (f64::from(max_volume - min_volume) * (f64::from(level) / 100.0)); - #[allow(clippy::cast_possible_truncation, clippy::cast_sign_loss)] + #[expect( // intentional + clippy::cast_possible_truncation, + clippy::cast_sign_loss, + reason = "size fits and non-negative" + )] self.inner.set_microphone_volume(volume as u32) } @@ -864,15 +867,7 @@ impl AudioDeviceModule { /// If [`sys::AudioDeviceModule::microphone_volume_is_available()`] call /// fails. pub fn microphone_volume_is_available(&self) -> anyhow::Result { - Ok( - if let Ok(is_available) = - self.inner.microphone_volume_is_available() - { - is_available - } else { - false - }, - ) + Ok(self.inner.microphone_volume_is_available().unwrap_or(false)) } /// Returns the current level of the microphone volume in percents. @@ -888,7 +883,11 @@ impl AudioDeviceModule { let min_volume = self.inner.min_microphone_volume()?; let max_volume = self.inner.max_microphone_volume()?; - #[allow(clippy::cast_possible_truncation, clippy::cast_sign_loss)] + #[expect( // intentional + clippy::cast_possible_truncation, + clippy::cast_sign_loss, + reason = "size fits and non-negative" + )] let level = (f64::from(volume - min_volume) / f64::from(max_volume - min_volume) * 100.0) as u32; @@ -1568,7 +1567,11 @@ impl sys::TrackEventCallback for TrackEventHandler { struct AudioSourceAudioLevelHandler(StreamSink); impl AudioSourceAudioLevelHandler { - #[allow(clippy::cast_possible_truncation, clippy::cast_sign_loss)] + #[expect( // intentional + clippy::cast_possible_truncation, + clippy::cast_sign_loss, + reason = "size fits and non-negative" + )] fn on_audio_level_change(&self, level: f32) { _ = self.0.add(api::TrackEvent::AudioLevelUpdated(cmp::min( (level * 1000.0).round() as u32,