diff --git a/examples/a-chat/main.rs b/examples/a-chat/main.rs index 89e5e2b6..9d1b3a11 100644 --- a/examples/a-chat/main.rs +++ b/examples/a-chat/main.rs @@ -5,7 +5,7 @@ type Result = std::result::Result fn main() -> Result<()> { let mut args = std::env::args(); - match (args.nth(1).as_ref().map(String::as_str), args.next()) { + match (args.nth(1).as_deref(), args.next()) { (Some("client"), None) => client::main(), (Some("server"), None) => server::main(), _ => Err("Usage: a-chat [client|server]".into()), diff --git a/src/fs/file.rs b/src/fs/file.rs index 7dc12dd0..0299ff19 100644 --- a/src/fs/file.rs +++ b/src/fs/file.rs @@ -696,7 +696,7 @@ impl LockGuard { // file. This call should not block because it doesn't touch the actual file on disk. if pos == SeekFrom::Current(0) { // Poll the internal file cursor. - let internal = (&*self.file).seek(SeekFrom::Current(0))?; + let internal = (&*self.file).stream_position()?; // Factor in the difference caused by caching. let actual = match self.mode { @@ -714,7 +714,7 @@ impl LockGuard { if let Some(new) = (start as i64).checked_add(diff) { if 0 <= new && new <= self.cache.len() as i64 { // Poll the internal file cursor. - let internal = (&*self.file).seek(SeekFrom::Current(0))?; + let internal = (&*self.file).stream_position()?; // Adjust the current position in the read cache. self.mode = Mode::Reading(new as usize); diff --git a/src/future/poll_fn.rs b/src/future/poll_fn.rs index 19452640..ce4fbfea 100644 --- a/src/future/poll_fn.rs +++ b/src/future/poll_fn.rs @@ -44,6 +44,6 @@ where type Output = T; fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { - (&mut self.f)(cx) + (self.f)(cx) } } diff --git a/src/io/buf_read/lines.rs b/src/io/buf_read/lines.rs index c60529cd..c342cdfc 100644 --- a/src/io/buf_read/lines.rs +++ b/src/io/buf_read/lines.rs @@ -50,7 +50,7 @@ impl Stream for Lines { this.buf.pop(); } } - Poll::Ready(Some(Ok(mem::replace(this.buf, String::new())))) + Poll::Ready(Some(Ok(std::mem::take(this.buf)))) } } @@ -62,7 +62,7 @@ pub fn read_line_internal( read: &mut usize, ) -> Poll> { let ret = futures_core::ready!(read_until_internal(reader, cx, b'\n', bytes, read)); - if str::from_utf8(&bytes).is_err() { + if str::from_utf8(bytes).is_err() { Poll::Ready(ret.and_then(|_| { Err(io::Error::new( io::ErrorKind::InvalidData, diff --git a/src/io/buf_read/mod.rs b/src/io/buf_read/mod.rs index bcb9d907..e9618a6a 100644 --- a/src/io/buf_read/mod.rs +++ b/src/io/buf_read/mod.rs @@ -136,7 +136,7 @@ pub trait BufReadExt: BufRead { { ReadLineFuture { reader: self, - bytes: unsafe { mem::replace(buf.as_mut_vec(), Vec::new()) }, + bytes: unsafe { std::mem::take(buf.as_mut_vec()) }, buf, read: 0, } diff --git a/src/io/buf_read/read_line.rs b/src/io/buf_read/read_line.rs index b66079bc..a8ead433 100644 --- a/src/io/buf_read/read_line.rs +++ b/src/io/buf_read/read_line.rs @@ -29,7 +29,7 @@ impl Future for ReadLineFuture<'_, T> { let reader = Pin::new(reader); let ret = futures_core::ready!(read_until_internal(reader, cx, b'\n', bytes, read)); - if str::from_utf8(&bytes).is_err() { + if str::from_utf8(bytes).is_err() { Poll::Ready(ret.and_then(|_| { Err(io::Error::new( io::ErrorKind::InvalidData, diff --git a/src/io/buf_read/split.rs b/src/io/buf_read/split.rs index 229a99b3..290b295e 100644 --- a/src/io/buf_read/split.rs +++ b/src/io/buf_read/split.rs @@ -1,4 +1,3 @@ -use std::mem; use std::pin::Pin; use pin_project_lite::pin_project; @@ -46,6 +45,6 @@ impl Stream for Split { if this.buf[this.buf.len() - 1] == *this.delim { this.buf.pop(); } - Poll::Ready(Some(Ok(mem::replace(this.buf, vec![])))) + Poll::Ready(Some(Ok(std::mem::take(this.buf)))) } } diff --git a/src/io/read/chain.rs b/src/io/read/chain.rs index b5eac581..26488ef4 100644 --- a/src/io/read/chain.rs +++ b/src/io/read/chain.rs @@ -144,7 +144,7 @@ impl BufRead for Chain { let this = self.project(); if !*this.done_first { match futures_core::ready!(this.first.poll_fill_buf(cx)) { - Ok(buf) if buf.is_empty() => { + Ok([]) => { *this.done_first = true; } Ok(buf) => return Poll::Ready(Ok(buf)), diff --git a/src/io/read/mod.rs b/src/io/read/mod.rs index 40542258..e1f12384 100644 --- a/src/io/read/mod.rs +++ b/src/io/read/mod.rs @@ -13,7 +13,6 @@ use read_to_end::{read_to_end_internal, ReadToEndFuture}; use read_to_string::ReadToStringFuture; use read_vectored::ReadVectoredFuture; -use std::mem; use crate::io::IoSliceMut; @@ -168,7 +167,7 @@ pub trait ReadExt: Read { let start_len = buf.len(); ReadToStringFuture { reader: self, - bytes: unsafe { mem::replace(buf.as_mut_vec(), Vec::new()) }, + bytes: unsafe { std::mem::take(buf.as_mut_vec()) }, buf, start_len, } diff --git a/src/io/read/read_exact.rs b/src/io/read/read_exact.rs index 71cf004d..6a7ca7c6 100644 --- a/src/io/read/read_exact.rs +++ b/src/io/read/read_exact.rs @@ -1,4 +1,3 @@ -use std::mem; use std::pin::Pin; use std::future::Future; @@ -20,7 +19,7 @@ impl Future for ReadExactFuture<'_, T> { while !buf.is_empty() { let n = futures_core::ready!(Pin::new(&mut *reader).poll_read(cx, buf))?; - let (_, rest) = mem::replace(buf, &mut []).split_at_mut(n); + let (_, rest) = std::mem::take(buf).split_at_mut(n); *buf = rest; if n == 0 { diff --git a/src/io/read/read_to_string.rs b/src/io/read/read_to_string.rs index 5b74389e..77ebd10b 100644 --- a/src/io/read/read_to_string.rs +++ b/src/io/read/read_to_string.rs @@ -29,7 +29,7 @@ impl Future for ReadToStringFuture<'_, T> { let reader = Pin::new(reader); let ret = futures_core::ready!(read_to_end_internal(reader, cx, bytes, *start_len)); - if str::from_utf8(&bytes).is_err() { + if str::from_utf8(bytes).is_err() { Poll::Ready(ret.and_then(|_| { Err(io::Error::new( io::ErrorKind::InvalidData, diff --git a/src/io/write/write_all.rs b/src/io/write/write_all.rs index f04c55d6..07d3a84a 100644 --- a/src/io/write/write_all.rs +++ b/src/io/write/write_all.rs @@ -1,4 +1,3 @@ -use std::mem; use std::pin::Pin; use std::future::Future; @@ -20,7 +19,7 @@ impl Future for WriteAllFuture<'_, T> { while !buf.is_empty() { let n = futures_core::ready!(Pin::new(&mut **writer).poll_write(cx, buf))?; - let (_, rest) = mem::replace(buf, &[]).split_at(n); + let (_, rest) = std::mem::take(buf).split_at(n); *buf = rest; if n == 0 { diff --git a/src/net/addr.rs b/src/net/addr.rs index 71988fb3..793492d8 100644 --- a/src/net/addr.rs +++ b/src/net/addr.rs @@ -280,6 +280,6 @@ impl ToSocketAddrs for String { impl Future, ToSocketAddrsFuture ) { - (&**self).to_socket_addrs() + (**self).to_socket_addrs() } } diff --git a/src/path/path.rs b/src/path/path.rs index 185bfaff..bb3e922e 100644 --- a/src/path/path.rs +++ b/src/path/path.rs @@ -261,7 +261,7 @@ impl Path { /// assert_eq!(ancestors.next(), None); /// ``` pub fn ancestors(&self) -> Ancestors<'_> { - Ancestors { next: Some(&self) } + Ancestors { next: Some(self) } } /// Returns the final component of the `Path`, if there is one. @@ -1011,13 +1011,13 @@ impl_cmp_os_str!(&'a Path, OsString); impl<'a> From<&'a std::path::Path> for &'a Path { fn from(path: &'a std::path::Path) -> &'a Path { - &Path::new(path.as_os_str()) + Path::new(path.as_os_str()) } } -impl<'a> Into<&'a std::path::Path> for &'a Path { - fn into(self) -> &'a std::path::Path { - std::path::Path::new(&self.inner) +impl<'a> From<&'a Path> for &'a std::path::Path { + fn from(val: &'a Path) -> Self { + std::path::Path::new(&val.inner) } } diff --git a/src/path/pathbuf.rs b/src/path/pathbuf.rs index f9370cba..fc1cfbd9 100644 --- a/src/path/pathbuf.rs +++ b/src/path/pathbuf.rs @@ -364,9 +364,9 @@ impl From for PathBuf { } } -impl Into for PathBuf { - fn into(self) -> std::path::PathBuf { - self.inner +impl From for std::path::PathBuf { + fn from(val: PathBuf) -> Self { + val.inner } } diff --git a/src/stream/from_fn.rs b/src/stream/from_fn.rs index d3736454..3d2e20fb 100644 --- a/src/stream/from_fn.rs +++ b/src/stream/from_fn.rs @@ -62,7 +62,7 @@ where type Item = T; fn poll_next(mut self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll> { - let item = (&mut self.f)(); + let item = (self.f)(); Poll::Ready(item) } } diff --git a/src/stream/repeat_with.rs b/src/stream/repeat_with.rs index 39984a3a..26154fd0 100644 --- a/src/stream/repeat_with.rs +++ b/src/stream/repeat_with.rs @@ -78,7 +78,7 @@ where type Item = T; fn poll_next(mut self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll> { - let item = (&mut self.f)(); + let item = (self.f)(); Poll::Ready(Some(item)) } } diff --git a/src/stream/stream/all.rs b/src/stream/stream/all.rs index 06f4d7f8..8f162b86 100644 --- a/src/stream/stream/all.rs +++ b/src/stream/stream/all.rs @@ -37,7 +37,7 @@ where match next { Some(v) => { - let result = (&mut self.f)(v); + let result = (self.f)(v); if result { // don't forget to wake this task again to pull the next item from stream diff --git a/src/stream/stream/any.rs b/src/stream/stream/any.rs index 15154c50..e272c032 100644 --- a/src/stream/stream/any.rs +++ b/src/stream/stream/any.rs @@ -37,7 +37,7 @@ where match next { Some(v) => { - let result = (&mut self.f)(v); + let result = (self.f)(v); if result { Poll::Ready(true) diff --git a/src/stream/stream/find.rs b/src/stream/stream/find.rs index 8652ac09..7260d7f1 100644 --- a/src/stream/stream/find.rs +++ b/src/stream/stream/find.rs @@ -19,7 +19,7 @@ impl<'a, S, P> FindFuture<'a, S, P> { impl Unpin for FindFuture<'_, S, P> {} -impl<'a, S, P> Future for FindFuture<'a, S, P> +impl Future for FindFuture<'_, S, P> where S: Stream + Unpin + Sized, P: FnMut(&S::Item) -> bool, @@ -30,7 +30,7 @@ where let item = futures_core::ready!(Pin::new(&mut *self.stream).poll_next(cx)); match item { - Some(v) if (&mut self.p)(&v) => Poll::Ready(Some(v)), + Some(v) if (self.p)(&v) => Poll::Ready(Some(v)), Some(_) => { cx.waker().wake_by_ref(); Poll::Pending diff --git a/src/stream/stream/find_map.rs b/src/stream/stream/find_map.rs index f7e3c1e0..9cfadb6f 100644 --- a/src/stream/stream/find_map.rs +++ b/src/stream/stream/find_map.rs @@ -19,7 +19,7 @@ impl<'a, S, F> FindMapFuture<'a, S, F> { impl Unpin for FindMapFuture<'_, S, F> {} -impl<'a, S, B, F> Future for FindMapFuture<'a, S, F> +impl Future for FindMapFuture<'_, S, F> where S: Stream + Unpin + Sized, F: FnMut(S::Item) -> Option, @@ -30,7 +30,7 @@ where let item = futures_core::ready!(Pin::new(&mut *self.stream).poll_next(cx)); match item { - Some(v) => match (&mut self.f)(v) { + Some(v) => match (self.f)(v) { Some(v) => Poll::Ready(Some(v)), None => { cx.waker().wake_by_ref(); diff --git a/src/stream/stream/nth.rs b/src/stream/stream/nth.rs index 8cdabb6c..44a681d2 100644 --- a/src/stream/stream/nth.rs +++ b/src/stream/stream/nth.rs @@ -19,7 +19,7 @@ impl<'a, S> NthFuture<'a, S> { } } -impl<'a, S> Future for NthFuture<'a, S> +impl Future for NthFuture<'_, S> where S: Stream + Unpin + Sized, { diff --git a/src/stream/stream/position.rs b/src/stream/stream/position.rs index 2811b6d8..ae0f4207 100644 --- a/src/stream/stream/position.rs +++ b/src/stream/stream/position.rs @@ -12,7 +12,7 @@ pub struct PositionFuture<'a, S, P> { index: usize, } -impl<'a, S, P> Unpin for PositionFuture<'a, S, P> {} +impl Unpin for PositionFuture<'_, S, P> {} impl<'a, S, P> PositionFuture<'a, S, P> { pub(super) fn new(stream: &'a mut S, predicate: P) -> Self { @@ -24,7 +24,7 @@ impl<'a, S, P> PositionFuture<'a, S, P> { } } -impl<'a, S, P> Future for PositionFuture<'a, S, P> +impl Future for PositionFuture<'_, S, P> where S: Stream + Unpin, P: FnMut(S::Item) -> bool, @@ -36,7 +36,7 @@ where match next { Some(v) => { - if (&mut self.predicate)(v) { + if (self.predicate)(v) { Poll::Ready(Some(self.index)) } else { cx.waker().wake_by_ref(); diff --git a/src/stream/stream/try_fold.rs b/src/stream/stream/try_fold.rs index 73312ff7..d3b43bfa 100644 --- a/src/stream/stream/try_fold.rs +++ b/src/stream/stream/try_fold.rs @@ -12,7 +12,7 @@ pub struct TryFoldFuture<'a, S, F, T> { acc: Option, } -impl<'a, S, F, T> Unpin for TryFoldFuture<'a, S, F, T> {} +impl Unpin for TryFoldFuture<'_, S, F, T> {} impl<'a, S, F, T> TryFoldFuture<'a, S, F, T> { pub(super) fn new(stream: &'a mut S, init: T, f: F) -> Self { @@ -24,7 +24,7 @@ impl<'a, S, F, T> TryFoldFuture<'a, S, F, T> { } } -impl<'a, S, F, T, E> Future for TryFoldFuture<'a, S, F, T> +impl Future for TryFoldFuture<'_, S, F, T> where S: Stream + Unpin, F: FnMut(T, S::Item) -> Result, @@ -38,7 +38,7 @@ where match next { Some(v) => { let old = self.acc.take().unwrap(); - let new = (&mut self.f)(old, v); + let new = (self.f)(old, v); match new { Ok(o) => self.acc = Some(o), diff --git a/src/stream/stream/try_for_each.rs b/src/stream/stream/try_for_each.rs index 917bfd16..ae80aaf1 100644 --- a/src/stream/stream/try_for_each.rs +++ b/src/stream/stream/try_for_each.rs @@ -11,7 +11,7 @@ pub struct TryForEachFuture<'a, S, F> { f: F, } -impl<'a, S, F> Unpin for TryForEachFuture<'a, S, F> {} +impl Unpin for TryForEachFuture<'_, S, F> {} impl<'a, S, F> TryForEachFuture<'a, S, F> { pub(crate) fn new(stream: &'a mut S, f: F) -> Self { @@ -19,7 +19,7 @@ impl<'a, S, F> TryForEachFuture<'a, S, F> { } } -impl<'a, S, F, E> Future for TryForEachFuture<'a, S, F> +impl Future for TryForEachFuture<'_, S, F> where S: Stream + Unpin, F: FnMut(S::Item) -> Result<(), E>, @@ -33,7 +33,7 @@ where match item { None => return Poll::Ready(Ok(())), Some(v) => { - let res = (&mut self.f)(v); + let res = (self.f)(v); if let Err(e) = res { return Poll::Ready(Err(e)); } diff --git a/src/task/builder.rs b/src/task/builder.rs index aba0d611..534e8d68 100644 --- a/src/task/builder.rs +++ b/src/task/builder.rs @@ -154,7 +154,7 @@ impl Builder { thread_local! { /// Tracks the number of nested block_on calls. - static NUM_NESTED_BLOCKING: Cell = Cell::new(0); + static NUM_NESTED_BLOCKING: Cell = const { Cell::new(0) }; } // Run the future as a task. diff --git a/src/task/task_id.rs b/src/task/task_id.rs index 92c607c7..70fb5483 100644 --- a/src/task/task_id.rs +++ b/src/task/task_id.rs @@ -22,7 +22,7 @@ impl TaskId { static COUNTER: AtomicUsize = AtomicUsize::new(1); let id = COUNTER.fetch_add(1, Ordering::Relaxed); - if id > usize::max_value() / 2 { + if id > usize::MAX / 2 { std::process::abort(); } TaskId(id) diff --git a/src/task/task_local.rs b/src/task/task_local.rs index 1661c0bb..93556e73 100644 --- a/src/task/task_local.rs +++ b/src/task/task_local.rs @@ -120,7 +120,7 @@ impl LocalKey { static COUNTER: AtomicU32 = AtomicU32::new(1); let counter = COUNTER.fetch_add(1, Ordering::Relaxed); - if counter > u32::max_value() / 2 { + if counter > u32::MAX / 2 { std::process::abort(); } diff --git a/src/task/task_locals_wrapper.rs b/src/task/task_locals_wrapper.rs index 2a7ddb7a..97559937 100644 --- a/src/task/task_locals_wrapper.rs +++ b/src/task/task_locals_wrapper.rs @@ -6,7 +6,7 @@ use crate::utils::abort_on_panic; thread_local! { /// A pointer to the currently running task. - static CURRENT: Cell<*const TaskLocalsWrapper> = Cell::new(ptr::null_mut()); + static CURRENT: Cell<*const TaskLocalsWrapper> = const { Cell::new(ptr::null_mut()) }; } /// A wrapper to store task local data. diff --git a/src/utils.rs b/src/utils.rs index d1cb063b..cfd7362c 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -71,7 +71,7 @@ pub(crate) fn timer_after(dur: std::time::Duration) -> timer::Timer { Timer::after(dur) } -#[cfg(any(all(target_arch = "wasm32", feature = "default"),))] +#[cfg(all(target_arch = "wasm32", feature = "default"))] mod timer { use std::pin::Pin; use std::task::Poll; diff --git a/tests/channel.rs b/tests/channel.rs index 2aa27131..5ec31203 100644 --- a/tests/channel.rs +++ b/tests/channel.rs @@ -59,38 +59,38 @@ fn len_empty_full() { let (s, r) = channel(2); assert_eq!(s.len(), 0); - assert_eq!(s.is_empty(), true); - assert_eq!(s.is_full(), false); + assert!(s.is_empty()); + assert!(!s.is_full()); assert_eq!(r.len(), 0); - assert_eq!(r.is_empty(), true); - assert_eq!(r.is_full(), false); + assert!(r.is_empty()); + assert!(!r.is_full()); s.send(()).await.unwrap(); assert_eq!(s.len(), 1); - assert_eq!(s.is_empty(), false); - assert_eq!(s.is_full(), false); + assert!(!s.is_empty()); + assert!(!s.is_full()); assert_eq!(r.len(), 1); - assert_eq!(r.is_empty(), false); - assert_eq!(r.is_full(), false); + assert!(!r.is_empty()); + assert!(!r.is_full()); s.send(()).await.unwrap(); assert_eq!(s.len(), 2); - assert_eq!(s.is_empty(), false); - assert_eq!(s.is_full(), true); + assert!(!s.is_empty()); + assert!(s.is_full()); assert_eq!(r.len(), 2); - assert_eq!(r.is_empty(), false); - assert_eq!(r.is_full(), true); + assert!(!r.is_empty()); + assert!(r.is_full()); let _ = r.recv().await; assert_eq!(s.len(), 1); - assert_eq!(s.is_empty(), false); - assert_eq!(s.is_full(), false); + assert!(!s.is_empty()); + assert!(!s.is_full()); assert_eq!(r.len(), 1); - assert_eq!(r.is_empty(), false); - assert_eq!(r.is_full(), false); + assert!(!r.is_empty()); + assert!(!r.is_full()); }) } diff --git a/tests/rwlock.rs b/tests/rwlock.rs index 1d33a456..6c66997f 100644 --- a/tests/rwlock.rs +++ b/tests/rwlock.rs @@ -21,7 +21,7 @@ wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_browser); /// Generates a random number in `0..n`. pub fn random(n: u32) -> u32 { thread_local! { - static RNG: Cell> = Cell::new(Wrapping(1_406_868_647)); + static RNG: Cell> = const { Cell::new(Wrapping(1_406_868_647)) }; } RNG.with(|rng| { diff --git a/tests/tcp.rs b/tests/tcp.rs index f21737e8..2fab1679 100644 --- a/tests/tcp.rs +++ b/tests/tcp.rs @@ -60,7 +60,7 @@ fn smoke_std_stream_to_async_listener() -> io::Result<()> { let listener = TcpListener::bind("127.0.0.1:0").await?; let addr = listener.local_addr()?; - let mut std_stream = std::net::TcpStream::connect(&addr)?; + let mut std_stream = std::net::TcpStream::connect(addr)?; std_stream.write_all(THE_WINTERS_TALE)?; let mut buf = vec![0; 1024]; diff --git a/tests/uds.rs b/tests/uds.rs index dcdce443..d81786bb 100644 --- a/tests/uds.rs +++ b/tests/uds.rs @@ -96,7 +96,7 @@ async fn ping_pong_server(listener: UnixListener, iterations: u32) -> std::io::R let mut s = s?; let n = s.read(&mut buf[..]).await?; assert_eq!(&buf[..n], PING); - s.write_all(&PONG).await?; + s.write_all(PONG).await?; } } Ok(()) @@ -106,7 +106,7 @@ async fn ping_pong_client(socket: &std::path::PathBuf, iterations: u32) -> std:: let mut buf = [0; 1024]; for _ix in 0..iterations { let mut socket = UnixStream::connect(&socket).await?; - socket.write_all(&PING).await?; + socket.write_all(PING).await?; let n = async_std::io::timeout(TEST_TIMEOUT, socket.read(&mut buf[..])).await?; assert_eq!(&buf[..n], PONG); }