From b0a1dfb696b044d08fa720f2d3e52ed65a12e521 Mon Sep 17 00:00:00 2001 From: tyranron Date: Fri, 6 Sep 2024 19:17:15 +0300 Subject: [PATCH] Tune up lints for 1.81 Rust - bump up MSRV to 1.81 --- .github/workflows/ci.yml | 2 +- CHANGELOG.md | 14 ++++++++++++++ Cargo.toml | 2 +- README.md | 2 +- src/allocation/manager.rs | 6 ++++-- src/allocation/mod.rs | 11 ++++++----- src/chandata.rs | 10 +++++----- src/lib.rs | 5 ++++- src/server/mod.rs | 4 ++-- src/server/request.rs | 9 ++++++--- src/transport/mod.rs | 12 ++++++++---- src/transport/tcp.rs | 16 ++++++++++------ 12 files changed, 62 insertions(+), 31 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 84ec29e87..5ae006681 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -73,7 +73,7 @@ jobs: strategy: fail-fast: false matrix: - msrv: ["1.74.0"] + msrv: ["1.81.0"] os: ["ubuntu", "macOS", "windows"] runs-on: ${{ matrix.os }}-latest steps: diff --git a/CHANGELOG.md b/CHANGELOG.md index 2bdef3a16..e0d446f44 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,20 @@ All user visible changes to this project will be documented in this file. This p +## [0.10.0] · 202?-??-?? (unreleased) +[0.10.0]: /../../tree/v0.10.0 + +[Diff](/../../compare/v0.9.2...v0.10.0) + +### BC Breaks + +- Bumped up [MSRV] to 1.81 because for `#[expect]` attribute usage. ([todo]) + +[todo]: /../../commit/todo + + + + ## [0.9.2] · 2024-07-11 [0.9.2]: /../../tree/v0.9.2 diff --git a/Cargo.toml b/Cargo.toml index 5c1824f5f..604778643 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,7 @@ name = "medea-turn" version = "0.9.2" edition = "2021" -rust-version = "1.74" +rust-version = "1.81" description = "STUN/TURN server implementation used by Medea media server." authors = ["Instrumentisto Team "] license = "MIT OR Apache-2.0" diff --git a/README.md b/README.md index c22d01c98..aac95c831 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ ============ [![crates.io](https://img.shields.io/crates/v/medea-turn.svg "crates.io")](https://crates.io/crates/medea-turn) -[![Rust 1.74+](https://img.shields.io/badge/rustc-1.74+-lightgray.svg "Rust 1.74+")](https://blog.rust-lang.org/2023/11/16/Rust-1.74.0.html) +[![Rust 1.81+](https://img.shields.io/badge/rustc-1.81+-lightgray.svg "Rust 1.81+")](https://blog.rust-lang.org/2024/09/05/Rust-1.81.0.html) [![Unsafe Forbidden](https://img.shields.io/badge/unsafe-forbidden-success.svg "Unsafe forbidden")](https://github.com/rust-secure-code/safety-dance) [![CI](https://github.com/instrumentisto/medea-turn-rs/actions/workflows/ci.yml/badge.svg?branch=main "CI")](https://github.com/instrumentisto/medea-turn-rs/actions?query=workflow%3ACI+branch%3Amain) [![Rust docs](https://docs.rs/medea-turn/badge.svg "Rust docs")](https://docs.rs/medea-turn) diff --git a/src/allocation/manager.rs b/src/allocation/manager.rs index 09d6db9a8..e99052a1e 100644 --- a/src/allocation/manager.rs +++ b/src/allocation/manager.rs @@ -54,7 +54,10 @@ impl Manager { ) -> HashMap { let mut infos = HashMap::new(); - #[allow(clippy::iter_over_hash_type)] // order doesn't matter here + #[expect( // order doesn't matter here + clippy::iter_over_hash_type, + reason = "order doesn't matter here", + )] for (five_tuple, alloc) in &self.allocations { if five_tuples.as_ref().map_or(true, |f| f.contains(five_tuple)) { drop(infos.insert( @@ -73,7 +76,6 @@ impl Manager { /// Creates a new [`Allocation`] with provided parameters and starts /// relaying it. - #[allow(clippy::too_many_arguments)] pub(crate) async fn create_allocation( &mut self, five_tuple: FiveTuple, diff --git a/src/allocation/mod.rs b/src/allocation/mod.rs index 1e5407e8d..118c5e296 100644 --- a/src/allocation/mod.rs +++ b/src/allocation/mod.rs @@ -233,7 +233,6 @@ impl Allocation { /// Adds a new [`ChannelBind`] to this [`Allocation`], also updating the /// [`Permission`]s needed for this [`ChannelBind`]. - #[allow(clippy::significant_drop_tightening)] // false positive pub(crate) async fn add_channel_bind( &self, number: u16, @@ -277,6 +276,7 @@ impl Allocation { ); drop(channel_bindings.insert(number, bind)); + drop(channel_bindings); // `ChannelBind`s also refresh `Permission`s. self.add_permission(peer_addr.ip()).await; @@ -344,7 +344,8 @@ impl Allocation { /// [2]: https://tools.ietf.org/html/rfc5766#section-11.7 /// [Section 8]: https://tools.ietf.org/html/rfc5766#section-8 /// [Section 11]: https://tools.ietf.org/html/rfc5766#section-11 - #[allow(clippy::too_many_lines)] + // TODO: Refactor to satisfy `clippy::too_many_lines` lint. + #[expect(clippy::too_many_lines, reason = "needs refactoring")] fn spawn_relay_handler( &self, mut refresh_rx: mpsc::Receiver, @@ -410,9 +411,9 @@ impl Allocation { transport::Error::TransportIsDead => { break; } - transport::Error::Decode(_) - | transport::Error::ChannelData(_) - | transport::Error::Io(_) => { + transport::Error::Decode(..) + | transport::Error::ChannelData(..) + | transport::Error::Io(..) => { log::warn!( "Failed to send `ChannelData` from \ `Allocation(scr: {src_addr}`: {e}", diff --git a/src/chandata.rs b/src/chandata.rs index a976d4d30..359435776 100644 --- a/src/chandata.rs +++ b/src/chandata.rs @@ -42,11 +42,11 @@ pub struct ChannelData { impl ChannelData { /// Checks whether the provided `data` represents a [`ChannelData`] message. + #[expect( // false positive + clippy::missing_asserts_for_indexing, + reason = "length is checked with the first `if` expression", + )] pub(crate) fn is_channel_data(data: &[u8]) -> bool { - // PANIC: Indexing is OK here, since the length is checked with the - // first `if` expression. - #![allow(clippy::missing_asserts_for_indexing)] // false positive - if data.len() < HEADER_SIZE { return false; } @@ -118,7 +118,7 @@ impl ChannelData { let length = HEADER_SIZE + payload.len(); let padded_length = nearest_padded_value_length(length); - #[allow(clippy::map_err_ignore)] // intentional + #[expect(clippy::map_err_ignore, reason = "useless")] let len = u16::try_from(payload.len()) .map_err(|_| FormatError::BadChannelDataLength)?; diff --git a/src/lib.rs b/src/lib.rs index e3f0a3eed..35a18391c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -10,10 +10,13 @@ #![forbid(non_ascii_idents, unsafe_code)] #![warn( clippy::absolute_paths, + clippy::allow_attributes, + clippy::allow_attributes_without_reason, clippy::as_conversions, clippy::as_ptr_cast_mut, clippy::assertions_on_result_states, clippy::branches_sharing_code, + clippy::cfg_not_test, clippy::clear_with_drain, clippy::clone_on_ref_ptr, clippy::collection_is_never_read, @@ -84,6 +87,7 @@ clippy::rest_pat_in_fully_bound_structs, clippy::same_name_method, clippy::semicolon_inside_block, + clippy::set_contains_or_insert, clippy::shadow_unrelated, clippy::significant_drop_in_scrutinee, clippy::significant_drop_tightening, @@ -206,7 +210,6 @@ impl AuthHandler for Arc { /// [TURN]: https://en.wikipedia.org/wiki/TURN #[derive(Debug, Display, Eq, From, PartialEq, StdError)] #[non_exhaustive] -#[allow(variant_size_differences)] pub enum Error { /// Failed to allocate new relay connection, since maximum retires count /// exceeded. diff --git a/src/server/mod.rs b/src/server/mod.rs index 3a2e64617..46fae2747 100644 --- a/src/server/mod.rs +++ b/src/server/mod.rs @@ -210,7 +210,7 @@ impl Server { username: String, ) -> Result<(), Error> { let (closed_tx, closed_rx) = mpsc::channel(1); - #[allow(clippy::map_err_ignore)] // intentional + #[expect(clippy::map_err_ignore, reason = "only errors on closing")] let _: usize = self .command_tx .send(Command::DeleteAllocations(username, Arc::new(closed_rx))) @@ -245,7 +245,7 @@ impl Server { let (infos_tx, mut infos_rx) = mpsc::channel(1); - #[allow(clippy::map_err_ignore)] // intentional + #[expect(clippy::map_err_ignore, reason = "only errors on closing")] let _: usize = self .command_tx .send(Command::GetAllocationsInfo(five_tuples, infos_tx)) diff --git a/src/server/request.rs b/src/server/request.rs index 8e0f3acb1..0411d7f7c 100644 --- a/src/server/request.rs +++ b/src/server/request.rs @@ -64,7 +64,8 @@ const NONCE_LIFETIME: Duration = Duration::from_secs(3600); /// See the [`Error`] for details. /// /// [1]: https://tools.ietf.org/html/rfc5389#section-7.3 -#[allow(clippy::too_many_arguments)] // TODO: refactor +// TODO: Refactor to satisfy `clippy::too_many_arguments` lint. +#[expect(clippy::too_many_arguments, reason = "needs refactoring")] pub(crate) async fn handle( msg: Request, conn: &Arc, @@ -195,7 +196,8 @@ async fn handle_data_packet( /// /// [1]: https://tools.ietf.org/html/rfc5766#section-6.2 /// [STUN]: https://en.wikipedia.org/wiki/STUN -#[allow(clippy::too_many_lines)] // TODO: refactor +// TODO: Refactor to satisfy `clippy::too_many_lines` lint. +#[expect(clippy::too_many_lines, reason = "needs refactoring")] async fn handle_allocate_request( msg: Message, conn: &Arc, @@ -720,7 +722,8 @@ async fn handle_send_indication( /// See the [`Error`] for details. /// /// [1]: https://tools.ietf.org/html/rfc5766#section-11.2 -#[allow(clippy::too_many_arguments)] // TODO: refactor +// TODO: Refactor to satisfy `clippy::too_many_arguments` lint. +#[expect(clippy::too_many_arguments, reason = "needs refactoring")] async fn handle_channel_bind_request( msg: Message, conn: &Arc, diff --git a/src/transport/mod.rs b/src/transport/mod.rs index d76d7c9e0..f4030bbf0 100644 --- a/src/transport/mod.rs +++ b/src/transport/mod.rs @@ -108,9 +108,10 @@ impl Transport for UdpSocket { } fn local_addr(&self) -> SocketAddr { - // PANIC: Unwrapping is OK here, as this function is intended to be - // called on the bound `UdpSocket` only. - #[allow(clippy::unwrap_used)] // intentional + #[expect( // intentional + clippy::unwrap_used, + reason = "called on the bound `UdpSocket` only" + )] self.local_addr().unwrap() } @@ -145,7 +146,10 @@ pub(crate) async fn lookup_host( /// Possible errors of a [`Transport`]. #[derive(Debug, Display, From, Eq, PartialEq, StdError)] -#[allow(variant_size_differences)] +#[expect( // false positive + variant_size_differences, + reason = "`io::Error` is pointer-sized" +)] pub enum Error { /// Tried to use a dead [`Transport`]. #[display("Underlying TCP/UDP transport is dead")] diff --git a/src/transport/tcp.rs b/src/transport/tcp.rs index 149737cc1..34be058a6 100644 --- a/src/transport/tcp.rs +++ b/src/transport/tcp.rs @@ -57,7 +57,8 @@ pub struct Server { #[async_trait] impl Transport for Server { async fn recv_from(&self) -> Result<(Request, SocketAddr), Error> { - if let Some((data, addr)) = self.ingress_rx.lock().await.recv().await { + let req_and_addr = self.ingress_rx.lock().await.recv().await; + if let Some((data, addr)) = req_and_addr { Ok((data, addr)) } else { Err(Error::TransportIsDead) @@ -70,7 +71,6 @@ impl Transport for Server { target: SocketAddr, ) -> Result<(), Error> { let mut writers = self.writers.lock().await; - #[allow(clippy::significant_drop_in_scrutinee)] // intentional match writers.entry(target) { Entry::Occupied(mut e) => { let (res_tx, res_rx) = oneshot::channel(); @@ -80,7 +80,10 @@ impl Transport for Server { Err(Error::TransportIsDead) } else { - #[allow(clippy::map_err_ignore)] // intentional + #[expect( // intentional + clippy::map_err_ignore, + reason = "only errors on channel closing", + )] res_rx.await.map_err(|_| Error::TransportIsDead)? } } @@ -297,13 +300,14 @@ impl Decoder for Codec { type Item = Request; type Error = Error; + #[expect( // false positive + clippy::missing_asserts_for_indexing, + reason = "indexing is guarded with `if` condition" + )] fn decode( &mut self, src: &mut BytesMut, ) -> Result, Self::Error> { - // PANIC: Indexing is OK below, since we guard it with `if` condition. - #![allow(clippy::missing_asserts_for_indexing)] // false positive - if self.current.is_none() && src.len() >= 4 { self.current = Some(RequestKind::detect_kind([ src[0], src[1], src[2], src[3],