Skip to content

Commit

Permalink
Tune lints for 1.81 Rust
Browse files Browse the repository at this point in the history
- bump up MSRV to 1.81

Additionally:
- update `cxx` crate to 1.0.128 version
  • Loading branch information
tyranron committed Sep 10, 2024
1 parent 489c594 commit b341f14
Show file tree
Hide file tree
Showing 13 changed files with 111 additions and 92 deletions.
12 changes: 6 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
2 changes: 1 addition & 1 deletion crates/libwebrtc-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
10 changes: 7 additions & 3 deletions crates/libwebrtc-sys/build.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -191,7 +195,7 @@ fn get_path_to_openal() -> anyhow::Result<PathBuf> {
/// 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")?);
Expand Down Expand Up @@ -401,7 +405,7 @@ fn get_cpp_files() -> anyhow::Result<Vec<PathBuf>> {
.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"))]
Expand Down
38 changes: 20 additions & 18 deletions crates/libwebrtc-sys/src/bridge.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![expect(clippy::allow_attributes, reason = "`cxx` fails on `#[expect]`")]

use std::fmt;

use anyhow::anyhow;
Expand Down Expand Up @@ -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<OptionI32> {
Box::new(OptionI32(None))
}
Expand All @@ -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<OptionRtcpFeedbackMessageType> {
Box::new(OptionRtcpFeedbackMessageType(None))
Expand All @@ -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<OptionString> {
Box::new(OptionString(None))
}
Expand All @@ -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<OptionF64> {
Box::new(OptionF64(None))
}
Expand All @@ -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<OptionU32> {
Box::new(OptionU32(None))
}
Expand All @@ -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<OptionU64> {
Box::new(OptionU64(None))
}
Expand All @@ -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<OptionBool> {
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.
Expand Down Expand Up @@ -2246,7 +2248,7 @@ pub(crate) mod webrtc {
);
}

#[allow(dead_code)]
#[allow(dead_code, reason = "FFI")]
#[rustfmt::skip]
unsafe extern "C++" {
pub type RTCMediaSourceStats;
Expand Down Expand Up @@ -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`
Expand All @@ -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,
Expand Down Expand Up @@ -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<DynCreateSdpCallback>,
sdp: &CxxString,
Expand All @@ -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<DynCreateSdpCallback>, 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<DynSetDescriptionCallback>) {
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<DynSetDescriptionCallback>,
error: &CxxString,
Expand Down Expand Up @@ -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<DynAddIceCandidateCallback>) {
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<DynAddIceCandidateCallback>,
error: &CxxString,
Expand All @@ -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<DynRTCStatsCollectorCallback>,
report: UniquePtr<webrtc::RTCStatsReport>,
Expand Down
16 changes: 11 additions & 5 deletions crates/libwebrtc-sys/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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<webrtc::RTCStatsWrap> for RtcStatsType {
type Error = anyhow::Error;

Expand Down
2 changes: 1 addition & 1 deletion crates/native/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "medea-flutter-webrtc-native"
edition = "2021"
rust-version = "1.75"
rust-version = "1.81"
publish = false

[lib]
Expand Down
11 changes: 9 additions & 2 deletions crates/native/build.rs
Original file line number Diff line number Diff line change
@@ -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")]
{
Expand Down
Loading

0 comments on commit b341f14

Please sign in to comment.