Skip to content

Commit

Permalink
Tune up lints for 1.81 Rust
Browse files Browse the repository at this point in the history
- bump up MSRV to 1.81
  • Loading branch information
tyranron committed Sep 6, 2024
1 parent b3ee2a2 commit 5ae0d13
Show file tree
Hide file tree
Showing 11 changed files with 48 additions and 31 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 <developer@instrumentisto.com>"]
license = "MIT OR Apache-2.0"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 4 additions & 2 deletions src/allocation/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,10 @@ impl Manager {
) -> HashMap<FiveTuple, Info> {
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(
Expand All @@ -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,
Expand Down
11 changes: 6 additions & 5 deletions src/allocation/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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<Duration>,
Expand Down Expand Up @@ -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}",
Expand Down
10 changes: 5 additions & 5 deletions src/chandata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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)?;

Expand Down
5 changes: 4 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -206,7 +210,6 @@ impl<T: ?Sized + AuthHandler> AuthHandler for Arc<T> {
/// [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.
Expand Down
4 changes: 2 additions & 2 deletions src/server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand Down Expand Up @@ -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))
Expand Down
9 changes: 6 additions & 3 deletions src/server/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<dyn Transport + Send + Sync>,
Expand Down Expand Up @@ -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<Attribute>,
conn: &Arc<dyn Transport + Send + Sync>,
Expand Down Expand Up @@ -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<Attribute>,
conn: &Arc<dyn Transport + Send + Sync>,
Expand Down
12 changes: 8 additions & 4 deletions src/transport/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

Expand Down Expand Up @@ -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")]
Expand Down
16 changes: 10 additions & 6 deletions src/transport/tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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();
Expand All @@ -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)?
}
}
Expand Down Expand Up @@ -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<Option<Self::Item>, 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],
Expand Down

0 comments on commit 5ae0d13

Please sign in to comment.