Skip to content

Commit

Permalink
Rename Receiver -> LegacyReceiver
Browse files Browse the repository at this point in the history
As part of the "arbitrary self types v2" project, we are going to
replace the current `Receiver` trait with a new mechanism based on a
new, different `Receiver` trait.

This PR renames the old trait to get it out the way. Naming is hard.
Options considered included:
* HardCodedReceiver (because it should only be used for things in the
  standard library, and hence is sort-of hard coded)
* LegacyReceiver
* TargetLessReceiver
* OldReceiver

These are all bad names, but fortunately this will be temporary.
Assuming the new mechanism proceeds to stabilization as intended, the
legacy trait will be removed altogether.

Although we expect this trait to be used only in the standard library,
we suspect it may be in use elsehwere, so we're landing this change
separately to identify any surprising breakages.

It's known that this trait is used within the Rust for Linux project; a
patch is in progress to remove their dependency.

This is a part of the arbitrary self types v2 project,
rust-lang/rfcs#3519
rust-lang#44874

r? @wesleywiser
  • Loading branch information
adetaylor committed Sep 11, 2024
1 parent 7f4b270 commit 9040bb1
Show file tree
Hide file tree
Showing 22 changed files with 70 additions and 64 deletions.
10 changes: 5 additions & 5 deletions compiler/rustc_codegen_cranelift/example/mini_core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ impl<T: ?Sized + Unsize<U>, U: ?Sized> DispatchFromDyn<*const U> for *const T {}
impl<T: ?Sized + Unsize<U>, U: ?Sized> DispatchFromDyn<*mut U> for *mut T {}
impl<T: ?Sized + Unsize<U>, U: ?Sized> DispatchFromDyn<Box<U>> for Box<T> {}

#[lang = "receiver"]
pub trait Receiver {}
#[lang = "legacy_receiver"]
pub trait LegacyReceiver {}

impl<T: ?Sized> Receiver for &T {}
impl<T: ?Sized> Receiver for &mut T {}
impl<T: ?Sized> Receiver for Box<T> {}
impl<T: ?Sized> LegacyReceiver for &T {}
impl<T: ?Sized> LegacyReceiver for &mut T {}
impl<T: ?Sized> LegacyReceiver for Box<T> {}

#[lang = "copy"]
pub unsafe trait Copy {}
Expand Down
10 changes: 5 additions & 5 deletions compiler/rustc_codegen_gcc/example/mini_core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ impl<T: ?Sized+Unsize<U>, U: ?Sized> DispatchFromDyn<*const U> for *const T {}
impl<T: ?Sized+Unsize<U>, U: ?Sized> DispatchFromDyn<*mut U> for *mut T {}
impl<T: ?Sized + Unsize<U>, U: ?Sized> DispatchFromDyn<Box<U, ()>> for Box<T, ()> {}

#[lang = "receiver"]
pub trait Receiver {}
#[lang = "legacy_receiver"]
pub trait LegacyReceiver {}

impl<T: ?Sized> Receiver for &T {}
impl<T: ?Sized> Receiver for &mut T {}
impl<T: ?Sized, A: Allocator> Receiver for Box<T, A> {}
impl<T: ?Sized> LegacyReceiver for &T {}
impl<T: ?Sized> LegacyReceiver for &mut T {}
impl<T: ?Sized, A: Allocator> LegacyReceiver for Box<T, A> {}

#[lang = "copy"]
pub unsafe trait Copy {}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir/src/lang_items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ language_item_table! {
DerefMut, sym::deref_mut, deref_mut_trait, Target::Trait, GenericRequirement::Exact(0);
DerefPure, sym::deref_pure, deref_pure_trait, Target::Trait, GenericRequirement::Exact(0);
DerefTarget, sym::deref_target, deref_target, Target::AssocTy, GenericRequirement::None;
Receiver, sym::receiver, receiver_trait, Target::Trait, GenericRequirement::None;
LegacyReceiver, sym::legacy_receiver, legacy_receiver_trait, Target::Trait, GenericRequirement::None;

Fn, kw::Fn, fn_trait, Target::Trait, GenericRequirement::Exact(1);
FnMut, sym::fn_mut, fn_mut_trait, Target::Trait, GenericRequirement::Exact(1);
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_analysis/src/check/wfcheck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1794,7 +1794,7 @@ fn receiver_is_valid<'tcx>(
autoderef = autoderef.include_raw_pointers();
}

let receiver_trait_def_id = tcx.require_lang_item(LangItem::Receiver, Some(span));
let receiver_trait_def_id = tcx.require_lang_item(LangItem::LegacyReceiver, Some(span));

// Keep dereferencing `receiver_ty` until we get to `self_ty`.
while let Some((potential_self_ty, _)) = autoderef.next() {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_span/src/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1096,6 +1096,7 @@ symbols! {
lazy_normalization_consts,
lazy_type_alias,
le,
legacy_receiver,
len,
let_chains,
let_else,
Expand Down Expand Up @@ -1524,7 +1525,6 @@ symbols! {
readonly,
realloc,
reason,
receiver,
recursion_limit,
reexport_test_harness_main,
ref_pat_eat_one_layer_2024,
Expand Down
6 changes: 3 additions & 3 deletions library/alloc/src/boxed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ use core::marker::{Tuple, Unsize};
use core::mem::{self, SizedTypeProperties};
use core::ops::{
AsyncFn, AsyncFnMut, AsyncFnOnce, CoerceUnsized, Coroutine, CoroutineState, Deref, DerefMut,
DerefPure, DispatchFromDyn, Receiver,
DerefPure, DispatchFromDyn, LegacyReceiver,
};
use core::pin::{Pin, PinCoerceUnsized};
use core::ptr::{self, addr_of_mut, NonNull, Unique};
Expand Down Expand Up @@ -2153,8 +2153,8 @@ impl<T: ?Sized, A: Allocator> DerefMut for Box<T, A> {
#[unstable(feature = "deref_pure_trait", issue = "87121")]
unsafe impl<T: ?Sized, A: Allocator> DerefPure for Box<T, A> {}

#[unstable(feature = "receiver_trait", issue = "none")]
impl<T: ?Sized, A: Allocator> Receiver for Box<T, A> {}
#[unstable(feature = "legacy_receiver_trait", issue = "none")]
impl<T: ?Sized, A: Allocator> LegacyReceiver for Box<T, A> {}

#[stable(feature = "rust1", since = "1.0.0")]
impl<I: Iterator + ?Sized, A: Allocator> Iterator for Box<I, A> {
Expand Down
2 changes: 1 addition & 1 deletion library/alloc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@
#![feature(iter_advance_by)]
#![feature(iter_next_chunk)]
#![feature(layout_for_ptr)]
#![feature(legacy_receiver_trait)]
#![feature(local_waker)]
#![feature(maybe_uninit_slice)]
#![feature(maybe_uninit_uninit_array_transpose)]
Expand All @@ -140,7 +141,6 @@
#![feature(ptr_internals)]
#![feature(ptr_metadata)]
#![feature(ptr_sub_ptr)]
#![feature(receiver_trait)]
#![feature(set_ptr_value)]
#![feature(sized_type_properties)]
#![feature(slice_from_ptr_range)]
Expand Down
6 changes: 3 additions & 3 deletions library/alloc/src/rc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ use core::intrinsics::abort;
use core::iter;
use core::marker::{PhantomData, Unsize};
use core::mem::{self, align_of_val_raw, ManuallyDrop};
use core::ops::{CoerceUnsized, Deref, DerefMut, DerefPure, DispatchFromDyn, Receiver};
use core::ops::{CoerceUnsized, Deref, DerefMut, DerefPure, DispatchFromDyn, LegacyReceiver};
use core::panic::{RefUnwindSafe, UnwindSafe};
#[cfg(not(no_global_oom_handling))]
use core::pin::Pin;
Expand Down Expand Up @@ -2179,8 +2179,8 @@ unsafe impl<T: ?Sized, A: Allocator> PinCoerceUnsized for Weak<T, A> {}
#[unstable(feature = "deref_pure_trait", issue = "87121")]
unsafe impl<T: ?Sized, A: Allocator> DerefPure for Rc<T, A> {}

#[unstable(feature = "receiver_trait", issue = "none")]
impl<T: ?Sized> Receiver for Rc<T> {}
#[unstable(feature = "legacy_receiver_trait", issue = "none")]
impl<T: ?Sized> LegacyReceiver for Rc<T> {}

#[stable(feature = "rust1", since = "1.0.0")]
unsafe impl<#[may_dangle] T: ?Sized, A: Allocator> Drop for Rc<T, A> {
Expand Down
6 changes: 3 additions & 3 deletions library/alloc/src/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use core::intrinsics::abort;
use core::iter;
use core::marker::{PhantomData, Unsize};
use core::mem::{self, align_of_val_raw, ManuallyDrop};
use core::ops::{CoerceUnsized, Deref, DerefPure, DispatchFromDyn, Receiver};
use core::ops::{CoerceUnsized, Deref, DerefPure, DispatchFromDyn, LegacyReceiver};
use core::panic::{RefUnwindSafe, UnwindSafe};
use core::pin::{Pin, PinCoerceUnsized};
use core::ptr::{self, NonNull};
Expand Down Expand Up @@ -2143,8 +2143,8 @@ unsafe impl<T: ?Sized, A: Allocator> PinCoerceUnsized for Weak<T, A> {}
#[unstable(feature = "deref_pure_trait", issue = "87121")]
unsafe impl<T: ?Sized, A: Allocator> DerefPure for Arc<T, A> {}

#[unstable(feature = "receiver_trait", issue = "none")]
impl<T: ?Sized> Receiver for Arc<T> {}
#[unstable(feature = "legacy_receiver_trait", issue = "none")]
impl<T: ?Sized> LegacyReceiver for Arc<T> {}

#[cfg(not(no_global_oom_handling))]
impl<T: ?Sized + CloneToUninit, A: Allocator + Clone> Arc<T, A> {
Expand Down
20 changes: 13 additions & 7 deletions library/core/src/ops/deref.rs
Original file line number Diff line number Diff line change
Expand Up @@ -297,15 +297,21 @@ unsafe impl<T: ?Sized> DerefPure for &mut T {}
/// Indicates that a struct can be used as a method receiver, without the
/// `arbitrary_self_types` feature. This is implemented by stdlib pointer types like `Box<T>`,
/// `Rc<T>`, `&T`, and `Pin<P>`.
#[lang = "receiver"]
#[unstable(feature = "receiver_trait", issue = "none")]
///
/// This trait will shortly be removed and replaced with a more generic
/// facility based around the current "arbitrary self types" unstable feature.
/// That new facility will use a replacement trait called `Receiver` which is
/// why this is now named `LegacyReceiver`.
#[cfg_attr(bootstrap, lang = "receiver")]
#[cfg_attr(not(bootstrap), lang = "legacy_receiver")]
#[unstable(feature = "legacy_receiver_trait", issue = "none")]
#[doc(hidden)]
pub trait Receiver {
pub trait LegacyReceiver {
// Empty.
}

#[unstable(feature = "receiver_trait", issue = "none")]
impl<T: ?Sized> Receiver for &T {}
#[unstable(feature = "legacy_receiver_trait", issue = "none")]
impl<T: ?Sized> LegacyReceiver for &T {}

#[unstable(feature = "receiver_trait", issue = "none")]
impl<T: ?Sized> Receiver for &mut T {}
#[unstable(feature = "legacy_receiver_trait", issue = "none")]
impl<T: ?Sized> LegacyReceiver for &mut T {}
4 changes: 2 additions & 2 deletions library/core/src/ops/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,8 @@ pub use self::control_flow::ControlFlow;
pub use self::coroutine::{Coroutine, CoroutineState};
#[unstable(feature = "deref_pure_trait", issue = "87121")]
pub use self::deref::DerefPure;
#[unstable(feature = "receiver_trait", issue = "none")]
pub use self::deref::Receiver;
#[unstable(feature = "legacy_receiver_trait", issue = "none")]
pub use self::deref::LegacyReceiver;
#[stable(feature = "rust1", since = "1.0.0")]
pub use self::deref::{Deref, DerefMut};
pub(crate) use self::drop::fallback_surface_drop;
Expand Down
6 changes: 3 additions & 3 deletions library/core/src/pin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -921,7 +921,7 @@
#![stable(feature = "pin", since = "1.33.0")]

use crate::hash::{Hash, Hasher};
use crate::ops::{CoerceUnsized, Deref, DerefMut, DerefPure, DispatchFromDyn, Receiver};
use crate::ops::{CoerceUnsized, Deref, DerefMut, DerefPure, DispatchFromDyn, LegacyReceiver};
#[allow(unused_imports)]
use crate::{
cell::{RefCell, UnsafeCell},
Expand Down Expand Up @@ -1692,8 +1692,8 @@ impl<Ptr: DerefMut<Target: Unpin>> DerefMut for Pin<Ptr> {
#[unstable(feature = "deref_pure_trait", issue = "87121")]
unsafe impl<Ptr: DerefPure> DerefPure for Pin<Ptr> {}

#[unstable(feature = "receiver_trait", issue = "none")]
impl<Ptr: Receiver> Receiver for Pin<Ptr> {}
#[unstable(feature = "legacy_receiver_trait", issue = "none")]
impl<Ptr: LegacyReceiver> LegacyReceiver for Pin<Ptr> {}

#[stable(feature = "pin", since = "1.33.0")]
impl<Ptr: fmt::Debug> fmt::Debug for Pin<Ptr> {
Expand Down
4 changes: 2 additions & 2 deletions tests/codegen/avr/avr-func-addrspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ pub trait Sized {}
#[lang = "copy"]
pub trait Copy {}
impl<T: ?Sized> Copy for *const T {}
#[lang = "receiver"]
pub trait Receiver {}
#[lang = "legacy_receiver"]
pub trait LegacyReceiver {}
#[lang = "tuple_trait"]
pub trait Tuple {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ trait Sized {}
#[lang = "copy"]
trait Copy {}
impl<T: ?Sized> Copy for &T {}
#[lang = "receiver"]
trait Receiver {}
#[lang = "legacy_receiver"]
trait LegacyReceiver {}
#[lang = "dispatch_from_dyn"]
trait DispatchFromDyn<T> {}
impl<'a, T: ?Sized + Unsize<U>, U: ?Sized> DispatchFromDyn<&'a U> for &'a T {}
Expand Down
8 changes: 4 additions & 4 deletions tests/ui/abi/compatibility.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,10 @@ mod prelude {
#[lang = "sized"]
pub trait Sized {}

#[lang = "receiver"]
pub trait Receiver {}
impl<T: ?Sized> Receiver for &T {}
impl<T: ?Sized> Receiver for &mut T {}
#[lang = "legacy_receiver"]
pub trait LegacyReceiver {}
impl<T: ?Sized> LegacyReceiver for &T {}
impl<T: ?Sized> LegacyReceiver for &mut T {}

#[lang = "copy"]
pub trait Copy: Sized {}
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/closures/closure-move-sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ fn bar() {
let (send, recv) = channel();
let t = thread::spawn(|| {
recv.recv().unwrap();
//~^^ ERROR `std::sync::mpsc::Receiver<()>` cannot be shared between threads safely
//~^^ ERROR `Receiver<()>` cannot be shared between threads safely
});

send.send(());
Expand Down
8 changes: 4 additions & 4 deletions tests/ui/closures/closure-move-sync.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error[E0277]: `std::sync::mpsc::Receiver<()>` cannot be shared between threads safely
error[E0277]: `Receiver<()>` cannot be shared between threads safely
--> $DIR/closure-move-sync.rs:6:27
|
LL | let t = thread::spawn(|| {
Expand All @@ -8,10 +8,10 @@ LL | let t = thread::spawn(|| {
LL | | recv.recv().unwrap();
LL | |
LL | | });
| |_____^ `std::sync::mpsc::Receiver<()>` cannot be shared between threads safely
| |_____^ `Receiver<()>` cannot be shared between threads safely
|
= help: the trait `Sync` is not implemented for `std::sync::mpsc::Receiver<()>`, which is required by `{closure@$DIR/closure-move-sync.rs:6:27: 6:29}: Send`
= note: required for `&std::sync::mpsc::Receiver<()>` to implement `Send`
= help: the trait `Sync` is not implemented for `Receiver<()>`, which is required by `{closure@$DIR/closure-move-sync.rs:6:27: 6:29}: Send`
= note: required for `&Receiver<()>` to implement `Send`
note: required because it's used within this closure
--> $DIR/closure-move-sync.rs:6:27
|
Expand Down
6 changes: 3 additions & 3 deletions tests/ui/privacy/privacy1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ pub trait Deref {
type Target;
}

#[lang="receiver"]
pub trait Receiver: Deref {}
#[lang="legacy_receiver"]
pub trait LegacyReceiver: Deref {}

impl<'a, T> Deref for &'a T {
type Target = T;
}

impl<'a, T> Receiver for &'a T {}
impl<'a, T> LegacyReceiver for &'a T {}

mod bar {
// shouldn't bring in too much
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,12 @@ trait Copy {}
#[lang = "tuple_trait"]
trait Tuple {}

#[lang = "receiver"]
trait Receiver {}
#[lang = "legacy_receiver"]
trait LegacyReceiver {}

impl<T: ?Sized> Receiver for &T {}
impl<T: ?Sized> LegacyReceiver for &T {}

impl<T: ?Sized> Receiver for &mut T {}
impl<T: ?Sized> LegacyReceiver for &mut T {}

#[stable(feature = "minicore", since = "1.0.0")]
pub mod effects {
Expand Down
10 changes: 5 additions & 5 deletions tests/ui/rfcs/rfc-2632-const-trait-impl/effects/minicore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,12 @@ macro_rules! impl_fn_mut_tuple {
//impl_fn_mut_tuple!(A B C D);
//impl_fn_mut_tuple!(A B C D E);

#[lang = "receiver"]
trait Receiver {}
#[lang = "legacy_receiver"]
trait LegacyReceiver {}

impl<T: ?Sized> Receiver for &T {}
impl<T: ?Sized> LegacyReceiver for &T {}

impl<T: ?Sized> Receiver for &mut T {}
impl<T: ?Sized> LegacyReceiver for &mut T {}

#[lang = "destruct"]
#[const_trait]
Expand Down Expand Up @@ -454,7 +454,7 @@ impl<T> /* const */ Deref for Option<T> {
}
}

impl<P: Receiver> Receiver for Pin<P> {}
impl<P: LegacyReceiver> LegacyReceiver for Pin<P> {}

impl<T: Clone> Clone for RefCell<T> {
fn clone(&self) -> RefCell<T> {
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/stdlib-unit-tests/not-sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ fn main() {
//~^ ERROR `std::rc::Weak<i32>` cannot be shared between threads safely [E0277]

test::<Receiver<i32>>();
//~^ ERROR `std::sync::mpsc::Receiver<i32>` cannot be shared between threads safely [E0277]
//~^ ERROR `Receiver<i32>` cannot be shared between threads safely [E0277]
}
6 changes: 3 additions & 3 deletions tests/ui/stdlib-unit-tests/not-sync.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ note: required by a bound in `test`
LL | fn test<T: Sync>() {}
| ^^^^ required by this bound in `test`

error[E0277]: `std::sync::mpsc::Receiver<i32>` cannot be shared between threads safely
error[E0277]: `Receiver<i32>` cannot be shared between threads safely
--> $DIR/not-sync.rs:18:12
|
LL | test::<Receiver<i32>>();
| ^^^^^^^^^^^^^ `std::sync::mpsc::Receiver<i32>` cannot be shared between threads safely
| ^^^^^^^^^^^^^ `Receiver<i32>` cannot be shared between threads safely
|
= help: the trait `Sync` is not implemented for `std::sync::mpsc::Receiver<i32>`
= help: the trait `Sync` is not implemented for `Receiver<i32>`
note: required by a bound in `test`
--> $DIR/not-sync.rs:5:12
|
Expand Down

0 comments on commit 9040bb1

Please sign in to comment.