Rename Receiver -> LegacyReceiver

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,
https://github.com/rust-lang/rfcs/pull/3519
https://github.com/rust-lang/rust/issues/44874

r? @wesleywiser
This commit is contained in:
Adrian Taylor 2024-09-11 12:27:08 +00:00
parent 916e9ced40
commit 8f85b90ca6
19 changed files with 63 additions and 57 deletions

View File

@ -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<*mut U> for *mut T {}
impl<T: ?Sized + Unsize<U>, U: ?Sized> DispatchFromDyn<Box<U>> for Box<T> {} impl<T: ?Sized + Unsize<U>, U: ?Sized> DispatchFromDyn<Box<U>> for Box<T> {}
#[lang = "receiver"] #[lang = "legacy_receiver"]
pub trait Receiver {} pub 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 {}
impl<T: ?Sized> Receiver for Box<T> {} impl<T: ?Sized> LegacyReceiver for Box<T> {}
#[lang = "copy"] #[lang = "copy"]
pub unsafe trait Copy {} pub unsafe trait Copy {}

View File

@ -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<*mut U> for *mut T {}
impl<T: ?Sized + Unsize<U>, U: ?Sized> DispatchFromDyn<Box<U, ()>> for Box<T, ()> {} impl<T: ?Sized + Unsize<U>, U: ?Sized> DispatchFromDyn<Box<U, ()>> for Box<T, ()> {}
#[lang = "receiver"] #[lang = "legacy_receiver"]
pub trait Receiver {} pub 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 {}
impl<T: ?Sized, A: Allocator> Receiver for Box<T, A> {} impl<T: ?Sized, A: Allocator> LegacyReceiver for Box<T, A> {}
#[lang = "copy"] #[lang = "copy"]
pub unsafe trait Copy {} pub unsafe trait Copy {}

View File

@ -241,7 +241,7 @@ pub fn extract(attrs: &[ast::Attribute]) -> Option<(Symbol, Span)> {
DerefMut, sym::deref_mut, deref_mut_trait, Target::Trait, GenericRequirement::Exact(0); DerefMut, sym::deref_mut, deref_mut_trait, Target::Trait, GenericRequirement::Exact(0);
DerefPure, sym::deref_pure, deref_pure_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; 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); Fn, kw::Fn, fn_trait, Target::Trait, GenericRequirement::Exact(1);
FnMut, sym::fn_mut, fn_mut_trait, Target::Trait, GenericRequirement::Exact(1); FnMut, sym::fn_mut, fn_mut_trait, Target::Trait, GenericRequirement::Exact(1);

View File

@ -1801,7 +1801,7 @@ fn receiver_is_valid<'tcx>(
autoderef = autoderef.include_raw_pointers(); 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`. // Keep dereferencing `receiver_ty` until we get to `self_ty`.
while let Some((potential_self_ty, _)) = autoderef.next() { while let Some((potential_self_ty, _)) = autoderef.next() {

View File

@ -1133,6 +1133,7 @@
lazy_normalization_consts, lazy_normalization_consts,
lazy_type_alias, lazy_type_alias,
le, le,
legacy_receiver,
len, len,
let_chains, let_chains,
let_else, let_else,
@ -1573,7 +1574,6 @@
readonly, readonly,
realloc, realloc,
reason, reason,
receiver,
recursion_limit, recursion_limit,
reexport_test_harness_main, reexport_test_harness_main,
ref_pat_eat_one_layer_2024, ref_pat_eat_one_layer_2024,

View File

@ -196,7 +196,7 @@
use core::mem::{self, SizedTypeProperties}; use core::mem::{self, SizedTypeProperties};
use core::ops::{ use core::ops::{
AsyncFn, AsyncFnMut, AsyncFnOnce, CoerceUnsized, Coroutine, CoroutineState, Deref, DerefMut, AsyncFn, AsyncFnMut, AsyncFnOnce, CoerceUnsized, Coroutine, CoroutineState, Deref, DerefMut,
DerefPure, DispatchFromDyn, Receiver, DerefPure, DispatchFromDyn, LegacyReceiver,
}; };
use core::pin::{Pin, PinCoerceUnsized}; use core::pin::{Pin, PinCoerceUnsized};
use core::ptr::{self, NonNull, Unique}; use core::ptr::{self, NonNull, Unique};
@ -2378,8 +2378,8 @@ fn deref_mut(&mut self) -> &mut T {
#[unstable(feature = "deref_pure_trait", issue = "87121")] #[unstable(feature = "deref_pure_trait", issue = "87121")]
unsafe impl<T: ?Sized, A: Allocator> DerefPure for Box<T, A> {} unsafe impl<T: ?Sized, A: Allocator> DerefPure for Box<T, A> {}
#[unstable(feature = "receiver_trait", issue = "none")] #[unstable(feature = "legacy_receiver_trait", issue = "none")]
impl<T: ?Sized, A: Allocator> Receiver for Box<T, A> {} impl<T: ?Sized, A: Allocator> LegacyReceiver for Box<T, A> {}
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
impl<I: Iterator + ?Sized, A: Allocator> Iterator for Box<I, A> { impl<I: Iterator + ?Sized, A: Allocator> Iterator for Box<I, A> {

View File

@ -129,6 +129,7 @@
#![feature(iter_advance_by)] #![feature(iter_advance_by)]
#![feature(iter_next_chunk)] #![feature(iter_next_chunk)]
#![feature(layout_for_ptr)] #![feature(layout_for_ptr)]
#![feature(legacy_receiver_trait)]
#![feature(local_waker)] #![feature(local_waker)]
#![feature(maybe_uninit_slice)] #![feature(maybe_uninit_slice)]
#![feature(maybe_uninit_uninit_array_transpose)] #![feature(maybe_uninit_uninit_array_transpose)]
@ -138,7 +139,6 @@
#![feature(ptr_internals)] #![feature(ptr_internals)]
#![feature(ptr_metadata)] #![feature(ptr_metadata)]
#![feature(ptr_sub_ptr)] #![feature(ptr_sub_ptr)]
#![feature(receiver_trait)]
#![feature(set_ptr_value)] #![feature(set_ptr_value)]
#![feature(sized_type_properties)] #![feature(sized_type_properties)]
#![feature(slice_from_ptr_range)] #![feature(slice_from_ptr_range)]

View File

@ -252,7 +252,7 @@
use core::iter; use core::iter;
use core::marker::{PhantomData, Unsize}; use core::marker::{PhantomData, Unsize};
use core::mem::{self, ManuallyDrop, align_of_val_raw}; use core::mem::{self, ManuallyDrop, align_of_val_raw};
use core::ops::{CoerceUnsized, Deref, DerefMut, DerefPure, DispatchFromDyn, Receiver}; use core::ops::{CoerceUnsized, Deref, DerefMut, DerefPure, DispatchFromDyn, LegacyReceiver};
use core::panic::{RefUnwindSafe, UnwindSafe}; use core::panic::{RefUnwindSafe, UnwindSafe};
#[cfg(not(no_global_oom_handling))] #[cfg(not(no_global_oom_handling))]
use core::pin::Pin; use core::pin::Pin;
@ -2222,8 +2222,8 @@ unsafe impl<T: ?Sized, A: Allocator> PinCoerceUnsized for Weak<T, A> {}
#[unstable(feature = "deref_pure_trait", issue = "87121")] #[unstable(feature = "deref_pure_trait", issue = "87121")]
unsafe impl<T: ?Sized, A: Allocator> DerefPure for Rc<T, A> {} unsafe impl<T: ?Sized, A: Allocator> DerefPure for Rc<T, A> {}
#[unstable(feature = "receiver_trait", issue = "none")] #[unstable(feature = "legacy_receiver_trait", issue = "none")]
impl<T: ?Sized> Receiver for Rc<T> {} impl<T: ?Sized> LegacyReceiver for Rc<T> {}
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
unsafe impl<#[may_dangle] T: ?Sized, A: Allocator> Drop for Rc<T, A> { unsafe impl<#[may_dangle] T: ?Sized, A: Allocator> Drop for Rc<T, A> {

View File

@ -18,7 +18,7 @@
use core::iter; use core::iter;
use core::marker::{PhantomData, Unsize}; use core::marker::{PhantomData, Unsize};
use core::mem::{self, ManuallyDrop, align_of_val_raw}; use core::mem::{self, ManuallyDrop, align_of_val_raw};
use core::ops::{CoerceUnsized, Deref, DerefPure, DispatchFromDyn, Receiver}; use core::ops::{CoerceUnsized, Deref, DerefPure, DispatchFromDyn, LegacyReceiver};
use core::panic::{RefUnwindSafe, UnwindSafe}; use core::panic::{RefUnwindSafe, UnwindSafe};
use core::pin::{Pin, PinCoerceUnsized}; use core::pin::{Pin, PinCoerceUnsized};
use core::ptr::{self, NonNull}; use core::ptr::{self, NonNull};
@ -2189,8 +2189,8 @@ unsafe impl<T: ?Sized, A: Allocator> PinCoerceUnsized for Weak<T, A> {}
#[unstable(feature = "deref_pure_trait", issue = "87121")] #[unstable(feature = "deref_pure_trait", issue = "87121")]
unsafe impl<T: ?Sized, A: Allocator> DerefPure for Arc<T, A> {} unsafe impl<T: ?Sized, A: Allocator> DerefPure for Arc<T, A> {}
#[unstable(feature = "receiver_trait", issue = "none")] #[unstable(feature = "legacy_receiver_trait", issue = "none")]
impl<T: ?Sized> Receiver for Arc<T> {} impl<T: ?Sized> LegacyReceiver for Arc<T> {}
#[cfg(not(no_global_oom_handling))] #[cfg(not(no_global_oom_handling))]
impl<T: ?Sized + CloneToUninit, A: Allocator + Clone> Arc<T, A> { impl<T: ?Sized + CloneToUninit, A: Allocator + Clone> Arc<T, A> {

View File

@ -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 /// 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>`, /// `arbitrary_self_types` feature. This is implemented by stdlib pointer types like `Box<T>`,
/// `Rc<T>`, `&T`, and `Pin<P>`. /// `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)] #[doc(hidden)]
pub trait Receiver { pub trait LegacyReceiver {
// Empty. // Empty.
} }
#[unstable(feature = "receiver_trait", issue = "none")] #[unstable(feature = "legacy_receiver_trait", issue = "none")]
impl<T: ?Sized> Receiver for &T {} impl<T: ?Sized> LegacyReceiver for &T {}
#[unstable(feature = "receiver_trait", issue = "none")] #[unstable(feature = "legacy_receiver_trait", issue = "none")]
impl<T: ?Sized> Receiver for &mut T {} impl<T: ?Sized> LegacyReceiver for &mut T {}

View File

@ -168,8 +168,8 @@
pub use self::coroutine::{Coroutine, CoroutineState}; pub use self::coroutine::{Coroutine, CoroutineState};
#[unstable(feature = "deref_pure_trait", issue = "87121")] #[unstable(feature = "deref_pure_trait", issue = "87121")]
pub use self::deref::DerefPure; pub use self::deref::DerefPure;
#[unstable(feature = "receiver_trait", issue = "none")] #[unstable(feature = "legacy_receiver_trait", issue = "none")]
pub use self::deref::Receiver; pub use self::deref::LegacyReceiver;
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
pub use self::deref::{Deref, DerefMut}; pub use self::deref::{Deref, DerefMut};
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]

View File

@ -921,7 +921,7 @@
#![stable(feature = "pin", since = "1.33.0")] #![stable(feature = "pin", since = "1.33.0")]
use crate::hash::{Hash, Hasher}; 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)] #[allow(unused_imports)]
use crate::{ use crate::{
cell::{RefCell, UnsafeCell}, cell::{RefCell, UnsafeCell},
@ -1692,8 +1692,8 @@ fn deref_mut(&mut self) -> &mut Ptr::Target {
#[unstable(feature = "deref_pure_trait", issue = "87121")] #[unstable(feature = "deref_pure_trait", issue = "87121")]
unsafe impl<Ptr: DerefPure> DerefPure for Pin<Ptr> {} unsafe impl<Ptr: DerefPure> DerefPure for Pin<Ptr> {}
#[unstable(feature = "receiver_trait", issue = "none")] #[unstable(feature = "legacy_receiver_trait", issue = "none")]
impl<Ptr: Receiver> Receiver for Pin<Ptr> {} impl<Ptr: LegacyReceiver> LegacyReceiver for Pin<Ptr> {}
#[stable(feature = "pin", since = "1.33.0")] #[stable(feature = "pin", since = "1.33.0")]
impl<Ptr: fmt::Debug> fmt::Debug for Pin<Ptr> { impl<Ptr: fmt::Debug> fmt::Debug for Pin<Ptr> {

View File

@ -18,8 +18,8 @@ pub trait Sized {}
#[lang = "copy"] #[lang = "copy"]
pub trait Copy {} pub trait Copy {}
impl<T: ?Sized> Copy for *const T {} impl<T: ?Sized> Copy for *const T {}
#[lang = "receiver"] #[lang = "legacy_receiver"]
pub trait Receiver {} pub trait LegacyReceiver {}
#[lang = "tuple_trait"] #[lang = "tuple_trait"]
pub trait Tuple {} pub trait Tuple {}

View File

@ -16,8 +16,8 @@ trait Sized {}
#[lang = "copy"] #[lang = "copy"]
trait Copy {} trait Copy {}
impl<T: ?Sized> Copy for &T {} impl<T: ?Sized> Copy for &T {}
#[lang = "receiver"] #[lang = "legacy_receiver"]
trait Receiver {} trait LegacyReceiver {}
#[lang = "dispatch_from_dyn"] #[lang = "dispatch_from_dyn"]
trait DispatchFromDyn<T> {} trait DispatchFromDyn<T> {}
impl<'a, T: ?Sized + Unsize<U>, U: ?Sized> DispatchFromDyn<&'a U> for &'a T {} impl<'a, T: ?Sized + Unsize<U>, U: ?Sized> DispatchFromDyn<&'a U> for &'a T {}

View File

@ -4,8 +4,8 @@
#[lang = "sized"] #[lang = "sized"]
trait Sized {} trait Sized {}
#[lang = "receiver"] #[lang = "legacy_receiver"]
pub trait Receiver {} pub trait LegacyReceiver {}
pub auto trait Bar {} pub auto trait Bar {}

View File

@ -79,10 +79,10 @@ mod prelude {
#[lang = "sized"] #[lang = "sized"]
pub trait Sized {} pub trait Sized {}
#[lang = "receiver"] #[lang = "legacy_receiver"]
pub trait Receiver {} pub 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 = "copy"] #[lang = "copy"]
pub trait Copy: Sized {} pub trait Copy: Sized {}

View File

@ -12,14 +12,14 @@ pub trait Deref {
type Target; type Target;
} }
#[lang="receiver"] #[lang="legacy_receiver"]
pub trait Receiver: Deref {} pub trait LegacyReceiver: Deref {}
impl<'a, T> Deref for &'a T { impl<'a, T> Deref for &'a T {
type Target = T; type Target = T;
} }
impl<'a, T> Receiver for &'a T {} impl<'a, T> LegacyReceiver for &'a T {}
mod bar { mod bar {
// shouldn't bring in too much // shouldn't bring in too much

View File

@ -82,12 +82,12 @@ trait Copy {}
#[lang = "tuple_trait"] #[lang = "tuple_trait"]
trait Tuple {} trait Tuple {}
#[lang = "receiver"] #[lang = "legacy_receiver"]
trait 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")] #[stable(feature = "minicore", since = "1.0.0")]
pub mod effects { pub mod effects {

View File

@ -137,12 +137,12 @@ extern "rust-call" fn call_mut(&mut self, args: ClosureArguments) -> Self::Outpu
//impl_fn_mut_tuple!(A B C D); //impl_fn_mut_tuple!(A B C D);
//impl_fn_mut_tuple!(A B C D E); //impl_fn_mut_tuple!(A B C D E);
#[lang = "receiver"] #[lang = "legacy_receiver"]
trait 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"] #[lang = "destruct"]
#[const_trait] #[const_trait]
@ -454,7 +454,7 @@ fn deref(&self) -> &T {
} }
} }
impl<P: Receiver> Receiver for Pin<P> {} impl<P: LegacyReceiver> LegacyReceiver for Pin<P> {}
impl<T: Clone> Clone for RefCell<T> { impl<T: Clone> Clone for RefCell<T> {
fn clone(&self) -> RefCell<T> { fn clone(&self) -> RefCell<T> {