mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-08-20 00:00:08 +02:00
chore: fix clippy warnings (#4727)
This commit is contained in:
@@ -35,6 +35,6 @@ where
|
||||
type Output = T;
|
||||
|
||||
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<T> {
|
||||
(&mut self.f)(cx)
|
||||
(self.f)(cx)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,19 +1,18 @@
|
||||
use crate::io::ReadBuf;
|
||||
use std::mem::MaybeUninit;
|
||||
|
||||
mod private {
|
||||
pub trait Sealed {}
|
||||
/// Something that looks like a `Vec<u8>`.
|
||||
///
|
||||
/// # Safety
|
||||
///
|
||||
/// The implementor must guarantee that the vector returned by the
|
||||
/// `as_mut` and `as_mut` methods do not change from one call to
|
||||
/// another.
|
||||
pub(crate) unsafe trait VecU8: AsRef<Vec<u8>> + AsMut<Vec<u8>> {}
|
||||
|
||||
impl Sealed for Vec<u8> {}
|
||||
impl Sealed for &mut Vec<u8> {}
|
||||
}
|
||||
unsafe impl VecU8 for Vec<u8> {}
|
||||
unsafe impl VecU8 for &mut Vec<u8> {}
|
||||
|
||||
/// A sealed trait that constrains the generic type parameter in `VecWithInitialized<V>`. That struct's safety relies
|
||||
/// on certain invariants upheld by `Vec<u8>`.
|
||||
pub(crate) trait VecU8: AsMut<Vec<u8>> + private::Sealed {}
|
||||
|
||||
impl VecU8 for Vec<u8> {}
|
||||
impl VecU8 for &mut Vec<u8> {}
|
||||
/// This struct wraps a `Vec<u8>` or `&mut Vec<u8>`, combining it with a
|
||||
/// `num_initialized`, which keeps track of the number of initialized bytes
|
||||
/// in the unused capacity.
|
||||
@@ -64,8 +63,8 @@ where
|
||||
}
|
||||
|
||||
#[cfg(feature = "io-util")]
|
||||
pub(crate) fn is_empty(&mut self) -> bool {
|
||||
self.vec.as_mut().is_empty()
|
||||
pub(crate) fn is_empty(&self) -> bool {
|
||||
self.vec.as_ref().is_empty()
|
||||
}
|
||||
|
||||
pub(crate) fn get_read_buf<'a>(&'a mut self) -> ReadBuf<'a> {
|
||||
|
||||
+12
-6
@@ -136,16 +136,22 @@ impl sealed::ToSocketAddrsPriv for &[SocketAddr] {
|
||||
type Future = ReadyFuture<Self::Iter>;
|
||||
|
||||
fn to_socket_addrs(&self, _: sealed::Internal) -> Self::Future {
|
||||
// Clippy doesn't like the `to_vec()` call here (as it will allocate,
|
||||
// while `self.iter().copied()` would not), but it's actually necessary
|
||||
// in order to ensure that the returned iterator is valid for the
|
||||
// `'static` lifetime, which the borrowed `slice::Iter` iterator would
|
||||
// not be.
|
||||
#[inline]
|
||||
fn slice_to_vec(addrs: &[SocketAddr]) -> Vec<SocketAddr> {
|
||||
addrs.to_vec()
|
||||
}
|
||||
|
||||
// This uses a helper method because clippy doesn't like the `to_vec()`
|
||||
// call here (it will allocate, whereas `self.iter().copied()` would
|
||||
// not), but it's actually necessary in order to ensure that the
|
||||
// returned iterator is valid for the `'static` lifetime, which the
|
||||
// borrowed `slice::Iter` iterator would not be.
|
||||
//
|
||||
// Note that we can't actually add an `allow` attribute for
|
||||
// `clippy::unnecessary_to_owned` here, as Tokio's CI runs clippy lints
|
||||
// on Rust 1.52 to avoid breaking LTS releases of Tokio. Users of newer
|
||||
// Rust versions who see this lint should just ignore it.
|
||||
let iter = self.to_vec().into_iter();
|
||||
let iter = slice_to_vec(self).into_iter();
|
||||
future::ready(Ok(iter))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user