Skip to content

Commit 60bfe32

Browse files
committed
Auto merge of #107318 - matthiaskrgr:rollup-776kd81, r=matthiaskrgr
Rollup of 9 pull requests Successful merges: - #97373 (impl DispatchFromDyn for Cell and UnsafeCell) - #106625 (Remove backwards compat for LLVM 12 coverage format) - #106779 (Avoid __cxa_thread_atexit_impl on Emscripten) - #106811 (Append .dwp to the binary filename instead of replacing the existing extension.) - #106836 (Remove optimistic spinning from `mpsc::SyncSender`) - #106946 (implement Hash for proc_macro::LineColumn) - #107074 (remove unnecessary check for opaque types) - #107287 (Improve fn pointer notes) - #107304 (Use `can_eq` to compare types for default assoc type error) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 7267216 + ab13660 commit 60bfe32

File tree

5 files changed

+43
-33
lines changed

5 files changed

+43
-33
lines changed

core/src/cell.rs

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ use crate::cmp::Ordering;
196196
use crate::fmt::{self, Debug, Display};
197197
use crate::marker::{PhantomData, Unsize};
198198
use crate::mem;
199-
use crate::ops::{CoerceUnsized, Deref, DerefMut};
199+
use crate::ops::{CoerceUnsized, Deref, DerefMut, DispatchFromDyn};
200200
use crate::ptr::{self, NonNull};
201201

202202
mod lazy;
@@ -571,6 +571,16 @@ impl<T: Default> Cell<T> {
571571
#[unstable(feature = "coerce_unsized", issue = "18598")]
572572
impl<T: CoerceUnsized<U>, U> CoerceUnsized<Cell<U>> for Cell<T> {}
573573

574+
// Allow types that wrap `Cell` to also implement `DispatchFromDyn`
575+
// and become object safe method receivers.
576+
// Note that currently `Cell` itself cannot be a method receiver
577+
// because it does not implement Deref.
578+
// In other words:
579+
// `self: Cell<&Self>` won't work
580+
// `self: CellWrapper<Self>` becomes possible
581+
#[unstable(feature = "dispatch_from_dyn", issue = "none")]
582+
impl<T: DispatchFromDyn<U>, U> DispatchFromDyn<Cell<U>> for Cell<T> {}
583+
574584
impl<T> Cell<[T]> {
575585
/// Returns a `&[Cell<T>]` from a `&Cell<[T]>`
576586
///
@@ -2078,6 +2088,16 @@ impl<T> const From<T> for UnsafeCell<T> {
20782088
#[unstable(feature = "coerce_unsized", issue = "18598")]
20792089
impl<T: CoerceUnsized<U>, U> CoerceUnsized<UnsafeCell<U>> for UnsafeCell<T> {}
20802090

2091+
// Allow types that wrap `UnsafeCell` to also implement `DispatchFromDyn`
2092+
// and become object safe method receivers.
2093+
// Note that currently `UnsafeCell` itself cannot be a method receiver
2094+
// because it does not implement Deref.
2095+
// In other words:
2096+
// `self: UnsafeCell<&Self>` won't work
2097+
// `self: UnsafeCellWrapper<Self>` becomes possible
2098+
#[unstable(feature = "dispatch_from_dyn", issue = "none")]
2099+
impl<T: DispatchFromDyn<U>, U> DispatchFromDyn<UnsafeCell<U>> for UnsafeCell<T> {}
2100+
20812101
/// [`UnsafeCell`], but [`Sync`].
20822102
///
20832103
/// This is just an `UnsafeCell`, except it implements `Sync`
@@ -2169,6 +2189,17 @@ impl<T> const From<T> for SyncUnsafeCell<T> {
21692189
//#[unstable(feature = "sync_unsafe_cell", issue = "95439")]
21702190
impl<T: CoerceUnsized<U>, U> CoerceUnsized<SyncUnsafeCell<U>> for SyncUnsafeCell<T> {}
21712191

2192+
// Allow types that wrap `SyncUnsafeCell` to also implement `DispatchFromDyn`
2193+
// and become object safe method receivers.
2194+
// Note that currently `SyncUnsafeCell` itself cannot be a method receiver
2195+
// because it does not implement Deref.
2196+
// In other words:
2197+
// `self: SyncUnsafeCell<&Self>` won't work
2198+
// `self: SyncUnsafeCellWrapper<Self>` becomes possible
2199+
#[unstable(feature = "dispatch_from_dyn", issue = "none")]
2200+
//#[unstable(feature = "sync_unsafe_cell", issue = "95439")]
2201+
impl<T: DispatchFromDyn<U>, U> DispatchFromDyn<SyncUnsafeCell<U>> for SyncUnsafeCell<T> {}
2202+
21722203
#[allow(unused)]
21732204
fn assert_coerce_unsized(
21742205
a: UnsafeCell<&i32>,

proc_macro/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -582,7 +582,7 @@ impl fmt::Debug for Span {
582582

583583
/// A line-column pair representing the start or end of a `Span`.
584584
#[unstable(feature = "proc_macro_span", issue = "54725")]
585-
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
585+
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
586586
pub struct LineColumn {
587587
/// The 1-indexed line in the source file on which the span starts or ends (inclusive).
588588
#[unstable(feature = "proc_macro_span", issue = "54725")]

std/src/sync/mpmc/array.rs

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -319,19 +319,10 @@ impl<T> Channel<T> {
319319
) -> Result<(), SendTimeoutError<T>> {
320320
let token = &mut Token::default();
321321
loop {
322-
// Try sending a message several times.
323-
let backoff = Backoff::new();
324-
loop {
325-
if self.start_send(token) {
326-
let res = unsafe { self.write(token, msg) };
327-
return res.map_err(SendTimeoutError::Disconnected);
328-
}
329-
330-
if backoff.is_completed() {
331-
break;
332-
} else {
333-
backoff.spin_light();
334-
}
322+
// Try sending a message.
323+
if self.start_send(token) {
324+
let res = unsafe { self.write(token, msg) };
325+
return res.map_err(SendTimeoutError::Disconnected);
335326
}
336327

337328
if let Some(d) = deadline {
@@ -379,6 +370,7 @@ impl<T> Channel<T> {
379370
pub(crate) fn recv(&self, deadline: Option<Instant>) -> Result<T, RecvTimeoutError> {
380371
let token = &mut Token::default();
381372
loop {
373+
// Try receiving a message.
382374
if self.start_recv(token) {
383375
let res = unsafe { self.read(token) };
384376
return res.map_err(|_| RecvTimeoutError::Disconnected);

std/src/sync/mpmc/utils.rs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,8 @@ impl Backoff {
105105

106106
/// Backs off using lightweight spinning.
107107
///
108-
/// This method should be used for:
109-
/// - Retrying an operation because another thread made progress. i.e. on CAS failure.
110-
/// - Waiting for an operation to complete by spinning optimistically for a few iterations
111-
/// before falling back to parking the thread (see `Backoff::is_completed`).
108+
/// This method should be used for retrying an operation because another thread made
109+
/// progress. i.e. on CAS failure.
112110
#[inline]
113111
pub fn spin_light(&self) {
114112
let step = self.step.get().min(SPIN_LIMIT);
@@ -134,10 +132,4 @@ impl Backoff {
134132

135133
self.step.set(self.step.get() + 1);
136134
}
137-
138-
/// Returns `true` if quadratic backoff has completed and parking the thread is advised.
139-
#[inline]
140-
pub fn is_completed(&self) -> bool {
141-
self.step.get() > SPIN_LIMIT
142-
}
143135
}

std/src/sys/unix/thread_local_dtor.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,7 @@
1111
// Note, however, that we run on lots older linuxes, as well as cross
1212
// compiling from a newer linux to an older linux, so we also have a
1313
// fallback implementation to use as well.
14-
#[cfg(any(
15-
target_os = "linux",
16-
target_os = "fuchsia",
17-
target_os = "redox",
18-
target_os = "emscripten"
19-
))]
20-
#[cfg_attr(target_family = "wasm", allow(unused))] // might remain unused depending on target details (e.g. wasm32-unknown-emscripten)
14+
#[cfg(any(target_os = "linux", target_os = "fuchsia", target_os = "redox"))]
2115
pub unsafe fn register_dtor(t: *mut u8, dtor: unsafe extern "C" fn(*mut u8)) {
2216
use crate::mem;
2317
use crate::sys_common::thread_local_dtor::register_dtor_fallback;
@@ -89,7 +83,8 @@ pub unsafe fn register_dtor(t: *mut u8, dtor: unsafe extern "C" fn(*mut u8)) {
8983
}
9084
}
9185

92-
#[cfg(any(target_os = "vxworks", target_os = "horizon"))]
86+
#[cfg(any(target_os = "vxworks", target_os = "horizon", target_os = "emscripten"))]
87+
#[cfg_attr(target_family = "wasm", allow(unused))] // might remain unused depending on target details (e.g. wasm32-unknown-emscripten)
9388
pub unsafe fn register_dtor(t: *mut u8, dtor: unsafe extern "C" fn(*mut u8)) {
9489
use crate::sys_common::thread_local_dtor::register_dtor_fallback;
9590
register_dtor_fallback(t, dtor);

0 commit comments

Comments
 (0)