diff --git a/core/src/mem/mod.rs b/core/src/mem/mod.rs index 4913a6de9..289305253 100644 --- a/core/src/mem/mod.rs +++ b/core/src/mem/mod.rs @@ -968,6 +968,7 @@ pub const fn replace(dest: &mut T, src: T) -> T { /// Integers and other types implementing [`Copy`] are unaffected by `drop`. /// /// ``` +/// # #![cfg_attr(not(bootstrap), allow(drop_copy))] /// #[derive(Copy, Clone)] /// struct Foo(u8); /// diff --git a/core/src/task/poll.rs b/core/src/task/poll.rs index 168516263..5283a576d 100644 --- a/core/src/task/poll.rs +++ b/core/src/task/poll.rs @@ -116,7 +116,7 @@ impl Poll { /// let fut = Pin::new(&mut fut); /// /// let num = fut.poll(cx).ready()?; - /// # drop(num); + /// # let _ = num; // to silence unused warning /// // ... use num /// /// Poll::Ready(()) diff --git a/core/src/task/ready.rs b/core/src/task/ready.rs index b1daf545f..8d12625e8 100644 --- a/core/src/task/ready.rs +++ b/core/src/task/ready.rs @@ -22,7 +22,7 @@ use core::task::Poll; /// let fut = Pin::new(&mut fut); /// /// let num = ready!(fut.poll(cx)); -/// # drop(num); +/// # let _ = num; /// // ... use num /// /// Poll::Ready(()) @@ -44,7 +44,7 @@ use core::task::Poll; /// Poll::Ready(t) => t, /// Poll::Pending => return Poll::Pending, /// }; -/// # drop(num); +/// # let _ = num; // to silence unused warning /// # // ... use num /// # /// # Poll::Ready(()) diff --git a/std/src/panicking.rs b/std/src/panicking.rs index a46a29cba..6d59266b6 100644 --- a/std/src/panicking.rs +++ b/std/src/panicking.rs @@ -541,7 +541,7 @@ pub fn begin_panic_handler(info: &PanicInfo<'_>) -> ! { // Lazily, the first time this gets called, run the actual string formatting. self.string.get_or_insert_with(|| { let mut s = String::new(); - drop(s.write_fmt(*inner)); + let _err = s.write_fmt(*inner); s }) } diff --git a/std/src/sys/sgx/waitqueue/mod.rs b/std/src/sys/sgx/waitqueue/mod.rs index 61bb11d9a..5e1d859ee 100644 --- a/std/src/sys/sgx/waitqueue/mod.rs +++ b/std/src/sys/sgx/waitqueue/mod.rs @@ -202,12 +202,18 @@ impl WaitQueue { pub fn notify_one( mut guard: SpinMutexGuard<'_, WaitVariable>, ) -> Result, SpinMutexGuard<'_, WaitVariable>> { + // SAFETY: lifetime of the pop() return value is limited to the map + // closure (The closure return value is 'static). The underlying + // stack frame won't be freed until after the WaitGuard created below + // is dropped. unsafe { - if let Some(entry) = guard.queue.inner.pop() { + let tcs = guard.queue.inner.pop().map(|entry| -> Tcs { let mut entry_guard = entry.lock(); - let tcs = entry_guard.tcs; entry_guard.wake = true; - drop(entry); + entry_guard.tcs + }); + + if let Some(tcs) = tcs { Ok(WaitGuard { mutex_guard: Some(guard), notified_tcs: NotifiedTcs::Single(tcs) }) } else { Err(guard) @@ -223,6 +229,9 @@ impl WaitQueue { pub fn notify_all( mut guard: SpinMutexGuard<'_, WaitVariable>, ) -> Result, SpinMutexGuard<'_, WaitVariable>> { + // SAFETY: lifetime of the pop() return values are limited to the + // while loop body. The underlying stack frames won't be freed until + // after the WaitGuard created below is dropped. unsafe { let mut count = 0; while let Some(entry) = guard.queue.inner.pop() { @@ -230,6 +239,7 @@ impl WaitQueue { let mut entry_guard = entry.lock(); entry_guard.wake = true; } + if let Some(count) = NonZeroUsize::new(count) { Ok(WaitGuard { mutex_guard: Some(guard), notified_tcs: NotifiedTcs::All { count } }) } else { diff --git a/std/src/sys/unix/fs.rs b/std/src/sys/unix/fs.rs index 22d2ae397..09db5b11d 100644 --- a/std/src/sys/unix/fs.rs +++ b/std/src/sys/unix/fs.rs @@ -1210,7 +1210,7 @@ impl File { // Redox doesn't appear to support `UTIME_OMIT`. // ESP-IDF and HorizonOS do not support `futimens` at all and the behavior for those OS is therefore // the same as for Redox. - drop(times); + let _ = times; Err(io::const_io_error!( io::ErrorKind::Unsupported, "setting file times not supported", diff --git a/std/src/thread/tests.rs b/std/src/thread/tests.rs index 6c9ce6fa0..b65e2572c 100644 --- a/std/src/thread/tests.rs +++ b/std/src/thread/tests.rs @@ -375,7 +375,9 @@ fn test_scoped_threads_nll() { // this is mostly a *compilation test* for this exact function: fn foo(x: &u8) { thread::scope(|s| { - s.spawn(|| drop(x)); + s.spawn(|| match x { + _ => (), + }); }); } // let's also run it for good measure