Arbitrary self types v2 by adetaylor · Pull Request #3519 · rust-lang/rfcs (original) (raw)

Conversation

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters

[ Show hidden characters]({{ revealButtonHref }})

adetaylor

@adetaylor @Urhengulas

This PR suggests small changes to the existing unstable "aribtrary self types" feature to make it more flexible. In particular, it suggests driving this feature from a new (ish) "Receiver" trait instead of from Deref, but to maintain compatibility by having a blanket implementation for all Deref types.

This is a squashed commit of much work by various folks including Johann Hemmann, Lukas Wirth, Mads Marquart and myself. Thanks also to David Hewitt and Manish Goregaokar for feedback.

Co-authored-by: Johann Hemmann johann.hemmann@code.berlin

@adetaylor

CraftSpider

@adetaylor

@traviscross traviscross added the T-lang

Relevant to the language team, which will review and decide on the RFC.

label

Nov 1, 2023

clarfonthey

clarfonthey

deltragon

Nadrieril

Nadrieril

Nadrieril

RalfJung

RalfJung

RalfJung

RalfJung

RalfJung

Veykril

Comment on lines 117 to 126

RalfJung

RalfJung

RalfJung

RalfJung

rust-timer added a commit to rust-lang-ci/rust that referenced this pull request

Nov 12, 2024

@rust-timer

Rollup merge of rust-lang#132144 - adetaylor:receiver-trait-itself, r=wesleywiser

Arbitrary self types v2: (unused) Receiver trait

This commit contains a new Receiver trait, which is the basis for the Arbitrary Self Types v2 RFC. This allows smart pointers to be method receivers even if they're not Deref.

This is currently unused by the compiler - a subsequent PR will start to use this for method resolution if the arbitrary_self_types feature gate is enabled. This is being landed first simply to make review simpler: if people feel this should all be in an atomic PR let me know.

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

r? @wesleywiser

alistair23 pushed a commit to alistair23/linux that referenced this pull request

Nov 12, 2024

@nbdd0121 @alistair23

The term "receiver" means that a type can be used as the type of self, and thus enables method call syntax foo.bar() instead of Foo::bar(foo). Stable Rust as of today (1.81) enables a limited selection of types (primitives and types in std, e.g. Box and Arc) to be used as receivers, while custom types cannot.

We want the kernel Arc type to have the same functionality as the Rust std Arc, so we use the Receiver trait (gated behind receiver_trait unstable feature) to gain the functionality.

The arbitrary_self_types RFC [1] (tracking issue [2]) is accepted and it will allow all types that implement a new Receiver trait (different from today's unstable trait) to be used as receivers. This trait will be automatically implemented for all Deref types, which include our Arc type, so we no longer have to opt-in to be used as receiver. To prepare us for the change, remove the Receiver implementation and the associated feature. To still allow Arc and others to be used as method receivers, turn on arbitrary_self_types feature instead.

This feature gate is introduced in 1.23.0. It used to enable both Deref types and raw pointer types to be used as receivers, but the latter is now split into a different feature gate in Rust 1.83 nightly. We do not need receivers on raw pointers so this change would not affect us and usage of arbitrary_self_types feature would work for all Rust versions that we support (>=1.78).

Cc: Adrian Taylor ade@hohum.me.uk Link: rust-lang/rfcs#3519 [1] Link: rust-lang/rust#44874 [2] Signed-off-by: Gary Guo gary@garyguo.net Reviewed-by: Benno Lossin benno.lossin@proton.me Reviewed-by: Alice Ryhl aliceryhl@google.com Link: https://lore.kernel.org/r/20240915132734.1653004-1-gary@garyguo.net Signed-off-by: Miguel Ojeda ojeda@kernel.org

herrnst pushed a commit to herrnst/linux-asahi that referenced this pull request

Nov 21, 2024

@nbdd0121 @herrnst

The term "receiver" means that a type can be used as the type of self, and thus enables method call syntax foo.bar() instead of Foo::bar(foo). Stable Rust as of today (1.81) enables a limited selection of types (primitives and types in std, e.g. Box and Arc) to be used as receivers, while custom types cannot.

We want the kernel Arc type to have the same functionality as the Rust std Arc, so we use the Receiver trait (gated behind receiver_trait unstable feature) to gain the functionality.

The arbitrary_self_types RFC [1] (tracking issue [2]) is accepted and it will allow all types that implement a new Receiver trait (different from today's unstable trait) to be used as receivers. This trait will be automatically implemented for all Deref types, which include our Arc type, so we no longer have to opt-in to be used as receiver. To prepare us for the change, remove the Receiver implementation and the associated feature. To still allow Arc and others to be used as method receivers, turn on arbitrary_self_types feature instead.

This feature gate is introduced in 1.23.0. It used to enable both Deref types and raw pointer types to be used as receivers, but the latter is now split into a different feature gate in Rust 1.83 nightly. We do not need receivers on raw pointers so this change would not affect us and usage of arbitrary_self_types feature would work for all Rust versions that we support (>=1.78).

Cc: Adrian Taylor ade@hohum.me.uk Link: rust-lang/rfcs#3519 [1] Link: rust-lang/rust#44874 [2] Signed-off-by: Gary Guo gary@garyguo.net Reviewed-by: Benno Lossin benno.lossin@proton.me Reviewed-by: Alice Ryhl aliceryhl@google.com Link: https://lore.kernel.org/r/20240915132734.1653004-1-gary@garyguo.net Signed-off-by: Miguel Ojeda ojeda@kernel.org

herrnst pushed a commit to herrnst/linux-asahi that referenced this pull request

Nov 22, 2024

@nbdd0121 @herrnst

The term "receiver" means that a type can be used as the type of self, and thus enables method call syntax foo.bar() instead of Foo::bar(foo). Stable Rust as of today (1.81) enables a limited selection of types (primitives and types in std, e.g. Box and Arc) to be used as receivers, while custom types cannot.

We want the kernel Arc type to have the same functionality as the Rust std Arc, so we use the Receiver trait (gated behind receiver_trait unstable feature) to gain the functionality.

The arbitrary_self_types RFC [1] (tracking issue [2]) is accepted and it will allow all types that implement a new Receiver trait (different from today's unstable trait) to be used as receivers. This trait will be automatically implemented for all Deref types, which include our Arc type, so we no longer have to opt-in to be used as receiver. To prepare us for the change, remove the Receiver implementation and the associated feature. To still allow Arc and others to be used as method receivers, turn on arbitrary_self_types feature instead.

This feature gate is introduced in 1.23.0. It used to enable both Deref types and raw pointer types to be used as receivers, but the latter is now split into a different feature gate in Rust 1.83 nightly. We do not need receivers on raw pointers so this change would not affect us and usage of arbitrary_self_types feature would work for all Rust versions that we support (>=1.78).

Cc: Adrian Taylor ade@hohum.me.uk Link: rust-lang/rfcs#3519 [1] Link: rust-lang/rust#44874 [2] Signed-off-by: Gary Guo gary@garyguo.net Reviewed-by: Benno Lossin benno.lossin@proton.me Reviewed-by: Alice Ryhl aliceryhl@google.com Link: https://lore.kernel.org/r/20240915132734.1653004-1-gary@garyguo.net Signed-off-by: Miguel Ojeda ojeda@kernel.org

WhatAmISupposedToPutHere pushed a commit to WhatAmISupposedToPutHere/linux that referenced this pull request

Nov 23, 2024

@nbdd0121 @jannau

The term "receiver" means that a type can be used as the type of self, and thus enables method call syntax foo.bar() instead of Foo::bar(foo). Stable Rust as of today (1.81) enables a limited selection of types (primitives and types in std, e.g. Box and Arc) to be used as receivers, while custom types cannot.

We want the kernel Arc type to have the same functionality as the Rust std Arc, so we use the Receiver trait (gated behind receiver_trait unstable feature) to gain the functionality.

The arbitrary_self_types RFC [1] (tracking issue [2]) is accepted and it will allow all types that implement a new Receiver trait (different from today's unstable trait) to be used as receivers. This trait will be automatically implemented for all Deref types, which include our Arc type, so we no longer have to opt-in to be used as receiver. To prepare us for the change, remove the Receiver implementation and the associated feature. To still allow Arc and others to be used as method receivers, turn on arbitrary_self_types feature instead.

This feature gate is introduced in 1.23.0. It used to enable both Deref types and raw pointer types to be used as receivers, but the latter is now split into a different feature gate in Rust 1.83 nightly. We do not need receivers on raw pointers so this change would not affect us and usage of arbitrary_self_types feature would work for all Rust versions that we support (>=1.78).

Cc: Adrian Taylor ade@hohum.me.uk Link: rust-lang/rfcs#3519 [1] Link: rust-lang/rust#44874 [2] Signed-off-by: Gary Guo gary@garyguo.net Reviewed-by: Benno Lossin benno.lossin@proton.me Reviewed-by: Alice Ryhl aliceryhl@google.com Link: https://lore.kernel.org/r/20240915132734.1653004-1-gary@garyguo.net Signed-off-by: Miguel Ojeda ojeda@kernel.org

herrnst pushed a commit to herrnst/linux-asahi that referenced this pull request

Nov 23, 2024

@nbdd0121 @herrnst

The term "receiver" means that a type can be used as the type of self, and thus enables method call syntax foo.bar() instead of Foo::bar(foo). Stable Rust as of today (1.81) enables a limited selection of types (primitives and types in std, e.g. Box and Arc) to be used as receivers, while custom types cannot.

We want the kernel Arc type to have the same functionality as the Rust std Arc, so we use the Receiver trait (gated behind receiver_trait unstable feature) to gain the functionality.

The arbitrary_self_types RFC [1] (tracking issue [2]) is accepted and it will allow all types that implement a new Receiver trait (different from today's unstable trait) to be used as receivers. This trait will be automatically implemented for all Deref types, which include our Arc type, so we no longer have to opt-in to be used as receiver. To prepare us for the change, remove the Receiver implementation and the associated feature. To still allow Arc and others to be used as method receivers, turn on arbitrary_self_types feature instead.

This feature gate is introduced in 1.23.0. It used to enable both Deref types and raw pointer types to be used as receivers, but the latter is now split into a different feature gate in Rust 1.83 nightly. We do not need receivers on raw pointers so this change would not affect us and usage of arbitrary_self_types feature would work for all Rust versions that we support (>=1.78).

Cc: Adrian Taylor ade@hohum.me.uk Link: rust-lang/rfcs#3519 [1] Link: rust-lang/rust#44874 [2] Signed-off-by: Gary Guo gary@garyguo.net Reviewed-by: Benno Lossin benno.lossin@proton.me Reviewed-by: Alice Ryhl aliceryhl@google.com Link: https://lore.kernel.org/r/20240915132734.1653004-1-gary@garyguo.net Signed-off-by: Miguel Ojeda ojeda@kernel.org

bors added a commit to rust-lang-ci/rust that referenced this pull request

Dec 3, 2024

@bors

…ig-bit, r=

Arbitrary self types v2: main compiler changes

This is the main PR in a series of PRs related to Arbitrary Self Types v2, tracked in rust-lang#44874. Specifically this is step 7 of the plan [described here](rust-lang#44874 (comment)), for RFC 3519.

Overall this PR:

This should not break compatibility for:

Subsequent PRs will add better diagnostics.

It's probably easiest to review this commit-by-commit.

r? @wesleywiser

herrnst pushed a commit to herrnst/linux-asahi that referenced this pull request

Dec 5, 2024

@nbdd0121 @herrnst

The term "receiver" means that a type can be used as the type of self, and thus enables method call syntax foo.bar() instead of Foo::bar(foo). Stable Rust as of today (1.81) enables a limited selection of types (primitives and types in std, e.g. Box and Arc) to be used as receivers, while custom types cannot.

We want the kernel Arc type to have the same functionality as the Rust std Arc, so we use the Receiver trait (gated behind receiver_trait unstable feature) to gain the functionality.

The arbitrary_self_types RFC [1] (tracking issue [2]) is accepted and it will allow all types that implement a new Receiver trait (different from today's unstable trait) to be used as receivers. This trait will be automatically implemented for all Deref types, which include our Arc type, so we no longer have to opt-in to be used as receiver. To prepare us for the change, remove the Receiver implementation and the associated feature. To still allow Arc and others to be used as method receivers, turn on arbitrary_self_types feature instead.

This feature gate is introduced in 1.23.0. It used to enable both Deref types and raw pointer types to be used as receivers, but the latter is now split into a different feature gate in Rust 1.83 nightly. We do not need receivers on raw pointers so this change would not affect us and usage of arbitrary_self_types feature would work for all Rust versions that we support (>=1.78).

Cc: Adrian Taylor ade@hohum.me.uk Link: rust-lang/rfcs#3519 [1] Link: rust-lang/rust#44874 [2] Signed-off-by: Gary Guo gary@garyguo.net Reviewed-by: Benno Lossin benno.lossin@proton.me Reviewed-by: Alice Ryhl aliceryhl@google.com Link: https://lore.kernel.org/r/20240915132734.1653004-1-gary@garyguo.net Signed-off-by: Miguel Ojeda ojeda@kernel.org

herrnst pushed a commit to herrnst/linux-asahi that referenced this pull request

Dec 6, 2024

@nbdd0121 @herrnst

The term "receiver" means that a type can be used as the type of self, and thus enables method call syntax foo.bar() instead of Foo::bar(foo). Stable Rust as of today (1.81) enables a limited selection of types (primitives and types in std, e.g. Box and Arc) to be used as receivers, while custom types cannot.

We want the kernel Arc type to have the same functionality as the Rust std Arc, so we use the Receiver trait (gated behind receiver_trait unstable feature) to gain the functionality.

The arbitrary_self_types RFC [1] (tracking issue [2]) is accepted and it will allow all types that implement a new Receiver trait (different from today's unstable trait) to be used as receivers. This trait will be automatically implemented for all Deref types, which include our Arc type, so we no longer have to opt-in to be used as receiver. To prepare us for the change, remove the Receiver implementation and the associated feature. To still allow Arc and others to be used as method receivers, turn on arbitrary_self_types feature instead.

This feature gate is introduced in 1.23.0. It used to enable both Deref types and raw pointer types to be used as receivers, but the latter is now split into a different feature gate in Rust 1.83 nightly. We do not need receivers on raw pointers so this change would not affect us and usage of arbitrary_self_types feature would work for all Rust versions that we support (>=1.78).

Cc: Adrian Taylor ade@hohum.me.uk Link: rust-lang/rfcs#3519 [1] Link: rust-lang/rust#44874 [2] Signed-off-by: Gary Guo gary@garyguo.net Reviewed-by: Benno Lossin benno.lossin@proton.me Reviewed-by: Alice Ryhl aliceryhl@google.com Link: https://lore.kernel.org/r/20240915132734.1653004-1-gary@garyguo.net Signed-off-by: Miguel Ojeda ojeda@kernel.org

jannau pushed a commit to AsahiLinux/linux that referenced this pull request

Dec 7, 2024

@nbdd0121 @jannau

The term "receiver" means that a type can be used as the type of self, and thus enables method call syntax foo.bar() instead of Foo::bar(foo). Stable Rust as of today (1.81) enables a limited selection of types (primitives and types in std, e.g. Box and Arc) to be used as receivers, while custom types cannot.

We want the kernel Arc type to have the same functionality as the Rust std Arc, so we use the Receiver trait (gated behind receiver_trait unstable feature) to gain the functionality.

The arbitrary_self_types RFC [1] (tracking issue [2]) is accepted and it will allow all types that implement a new Receiver trait (different from today's unstable trait) to be used as receivers. This trait will be automatically implemented for all Deref types, which include our Arc type, so we no longer have to opt-in to be used as receiver. To prepare us for the change, remove the Receiver implementation and the associated feature. To still allow Arc and others to be used as method receivers, turn on arbitrary_self_types feature instead.

This feature gate is introduced in 1.23.0. It used to enable both Deref types and raw pointer types to be used as receivers, but the latter is now split into a different feature gate in Rust 1.83 nightly. We do not need receivers on raw pointers so this change would not affect us and usage of arbitrary_self_types feature would work for all Rust versions that we support (>=1.78).

Cc: Adrian Taylor ade@hohum.me.uk Link: rust-lang/rfcs#3519 [1] Link: rust-lang/rust#44874 [2] Signed-off-by: Gary Guo gary@garyguo.net Reviewed-by: Benno Lossin benno.lossin@proton.me Reviewed-by: Alice Ryhl aliceryhl@google.com Link: https://lore.kernel.org/r/20240915132734.1653004-1-gary@garyguo.net Signed-off-by: Miguel Ojeda ojeda@kernel.org

ojeda pushed a commit to ojeda/linux that referenced this pull request

Dec 10, 2024

@nbdd0121 @ojeda

[ Upstream commit c95bbb5 ]

The term "receiver" means that a type can be used as the type of self, and thus enables method call syntax foo.bar() instead of Foo::bar(foo). Stable Rust as of today (1.81) enables a limited selection of types (primitives and types in std, e.g. Box and Arc) to be used as receivers, while custom types cannot.

We want the kernel Arc type to have the same functionality as the Rust std Arc, so we use the Receiver trait (gated behind receiver_trait unstable feature) to gain the functionality.

The arbitrary_self_types RFC [1] (tracking issue [2]) is accepted and it will allow all types that implement a new Receiver trait (different from today's unstable trait) to be used as receivers. This trait will be automatically implemented for all Deref types, which include our Arc type, so we no longer have to opt-in to be used as receiver. To prepare us for the change, remove the Receiver implementation and the associated feature. To still allow Arc and others to be used as method receivers, turn on arbitrary_self_types feature instead.

This feature gate is introduced in 1.23.0. It used to enable both Deref types and raw pointer types to be used as receivers, but the latter is now split into a different feature gate in Rust 1.83 nightly. We do not need receivers on raw pointers so this change would not affect us and usage of arbitrary_self_types feature would work for all Rust versions that we support (>=1.78).

Cc: Adrian Taylor ade@hohum.me.uk Link: rust-lang/rfcs#3519 [1] Link: rust-lang/rust#44874 [2] Signed-off-by: Gary Guo gary@garyguo.net Reviewed-by: Benno Lossin benno.lossin@proton.me Reviewed-by: Alice Ryhl aliceryhl@google.com Link: https://lore.kernel.org/r/20240915132734.1653004-1-gary@garyguo.net Signed-off-by: Miguel Ojeda ojeda@kernel.org

johnny-mnemonic pushed a commit to linux-ia64/linux-stable-rc that referenced this pull request

Dec 11, 2024

@nbdd0121

commit c95bbb5 upstream.

The term "receiver" means that a type can be used as the type of self, and thus enables method call syntax foo.bar() instead of Foo::bar(foo). Stable Rust as of today (1.81) enables a limited selection of types (primitives and types in std, e.g. Box and Arc) to be used as receivers, while custom types cannot.

We want the kernel Arc type to have the same functionality as the Rust std Arc, so we use the Receiver trait (gated behind receiver_trait unstable feature) to gain the functionality.

The arbitrary_self_types RFC [1] (tracking issue [2]) is accepted and it will allow all types that implement a new Receiver trait (different from today's unstable trait) to be used as receivers. This trait will be automatically implemented for all Deref types, which include our Arc type, so we no longer have to opt-in to be used as receiver. To prepare us for the change, remove the Receiver implementation and the associated feature. To still allow Arc and others to be used as method receivers, turn on arbitrary_self_types feature instead.

This feature gate is introduced in 1.23.0. It used to enable both Deref types and raw pointer types to be used as receivers, but the latter is now split into a different feature gate in Rust 1.83 nightly. We do not need receivers on raw pointers so this change would not affect us and usage of arbitrary_self_types feature would work for all Rust versions that we support (>=1.78).

Cc: Adrian Taylor ade@hohum.me.uk Link: rust-lang/rfcs#3519 [1] Link: rust-lang/rust#44874 [2] Signed-off-by: Gary Guo gary@garyguo.net Reviewed-by: Benno Lossin benno.lossin@proton.me Reviewed-by: Alice Ryhl aliceryhl@google.com Link: https://lore.kernel.org/r/20240915132734.1653004-1-gary@garyguo.net Signed-off-by: Miguel Ojeda ojeda@kernel.org Signed-off-by: Greg Kroah-Hartman gregkh@linuxfoundation.org

antoyo pushed a commit to rust-lang/rustc_codegen_gcc that referenced this pull request

Dec 11, 2024

@adetaylor

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:

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/rust#44874

r? @wesleywiser

antoyo pushed a commit to rust-lang/rustc_codegen_gcc that referenced this pull request

Dec 11, 2024

@Zalathar

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:

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/rust#44874

r? @wesleywiser

johnny-mnemonic pushed a commit to linux-ia64/linux-stable-rc that referenced this pull request

Dec 12, 2024

@nbdd0121

commit c95bbb5 upstream.

The term "receiver" means that a type can be used as the type of self, and thus enables method call syntax foo.bar() instead of Foo::bar(foo). Stable Rust as of today (1.81) enables a limited selection of types (primitives and types in std, e.g. Box and Arc) to be used as receivers, while custom types cannot.

We want the kernel Arc type to have the same functionality as the Rust std Arc, so we use the Receiver trait (gated behind receiver_trait unstable feature) to gain the functionality.

The arbitrary_self_types RFC [1] (tracking issue [2]) is accepted and it will allow all types that implement a new Receiver trait (different from today's unstable trait) to be used as receivers. This trait will be automatically implemented for all Deref types, which include our Arc type, so we no longer have to opt-in to be used as receiver. To prepare us for the change, remove the Receiver implementation and the associated feature. To still allow Arc and others to be used as method receivers, turn on arbitrary_self_types feature instead.

This feature gate is introduced in 1.23.0. It used to enable both Deref types and raw pointer types to be used as receivers, but the latter is now split into a different feature gate in Rust 1.83 nightly. We do not need receivers on raw pointers so this change would not affect us and usage of arbitrary_self_types feature would work for all Rust versions that we support (>=1.78).

Cc: Adrian Taylor ade@hohum.me.uk Link: rust-lang/rfcs#3519 [1] Link: rust-lang/rust#44874 [2] Signed-off-by: Gary Guo gary@garyguo.net Reviewed-by: Benno Lossin benno.lossin@proton.me Reviewed-by: Alice Ryhl aliceryhl@google.com Link: https://lore.kernel.org/r/20240915132734.1653004-1-gary@garyguo.net Signed-off-by: Miguel Ojeda ojeda@kernel.org Signed-off-by: Greg Kroah-Hartman gregkh@linuxfoundation.org

Kaz205 pushed a commit to Kaz205/linux that referenced this pull request

Dec 12, 2024

@nbdd0121

commit c95bbb5 upstream.

The term "receiver" means that a type can be used as the type of self, and thus enables method call syntax foo.bar() instead of Foo::bar(foo). Stable Rust as of today (1.81) enables a limited selection of types (primitives and types in std, e.g. Box and Arc) to be used as receivers, while custom types cannot.

We want the kernel Arc type to have the same functionality as the Rust std Arc, so we use the Receiver trait (gated behind receiver_trait unstable feature) to gain the functionality.

The arbitrary_self_types RFC [1] (tracking issue [2]) is accepted and it will allow all types that implement a new Receiver trait (different from today's unstable trait) to be used as receivers. This trait will be automatically implemented for all Deref types, which include our Arc type, so we no longer have to opt-in to be used as receiver. To prepare us for the change, remove the Receiver implementation and the associated feature. To still allow Arc and others to be used as method receivers, turn on arbitrary_self_types feature instead.

This feature gate is introduced in 1.23.0. It used to enable both Deref types and raw pointer types to be used as receivers, but the latter is now split into a different feature gate in Rust 1.83 nightly. We do not need receivers on raw pointers so this change would not affect us and usage of arbitrary_self_types feature would work for all Rust versions that we support (>=1.78).

Cc: Adrian Taylor ade@hohum.me.uk Link: rust-lang/rfcs#3519 [1] Link: rust-lang/rust#44874 [2] Signed-off-by: Gary Guo gary@garyguo.net Reviewed-by: Benno Lossin benno.lossin@proton.me Reviewed-by: Alice Ryhl aliceryhl@google.com Link: https://lore.kernel.org/r/20240915132734.1653004-1-gary@garyguo.net Signed-off-by: Miguel Ojeda ojeda@kernel.org Signed-off-by: Greg Kroah-Hartman gregkh@linuxfoundation.org

mj22226 pushed a commit to mj22226/linux that referenced this pull request

Dec 12, 2024

@nbdd0121 @gregkh

commit c95bbb5 upstream.

The term "receiver" means that a type can be used as the type of self, and thus enables method call syntax foo.bar() instead of Foo::bar(foo). Stable Rust as of today (1.81) enables a limited selection of types (primitives and types in std, e.g. Box and Arc) to be used as receivers, while custom types cannot.

We want the kernel Arc type to have the same functionality as the Rust std Arc, so we use the Receiver trait (gated behind receiver_trait unstable feature) to gain the functionality.

The arbitrary_self_types RFC [1] (tracking issue [2]) is accepted and it will allow all types that implement a new Receiver trait (different from today's unstable trait) to be used as receivers. This trait will be automatically implemented for all Deref types, which include our Arc type, so we no longer have to opt-in to be used as receiver. To prepare us for the change, remove the Receiver implementation and the associated feature. To still allow Arc and others to be used as method receivers, turn on arbitrary_self_types feature instead.

This feature gate is introduced in 1.23.0. It used to enable both Deref types and raw pointer types to be used as receivers, but the latter is now split into a different feature gate in Rust 1.83 nightly. We do not need receivers on raw pointers so this change would not affect us and usage of arbitrary_self_types feature would work for all Rust versions that we support (>=1.78).

Cc: Adrian Taylor ade@hohum.me.uk Link: rust-lang/rfcs#3519 [1] Link: rust-lang/rust#44874 [2] Signed-off-by: Gary Guo gary@garyguo.net Reviewed-by: Benno Lossin benno.lossin@proton.me Reviewed-by: Alice Ryhl aliceryhl@google.com Link: https://lore.kernel.org/r/20240915132734.1653004-1-gary@garyguo.net Signed-off-by: Miguel Ojeda ojeda@kernel.org Signed-off-by: Greg Kroah-Hartman gregkh@linuxfoundation.org

bors added a commit to rust-lang-ci/rust that referenced this pull request

Dec 12, 2024

@bors

…ig-bit, r=compiler-errors,wesleywiser

Arbitrary self types v2: main compiler changes

This is the main PR in a series of PRs related to Arbitrary Self Types v2, tracked in rust-lang#44874. Specifically this is step 7 of the plan [described here](rust-lang#44874 (comment)), for RFC 3519.

Overall this PR:

This should not break compatibility for:

Subsequent PRs will add better diagnostics.

It's probably easiest to review this commit-by-commit.

r? @wesleywiser

johnny-mnemonic pushed a commit to linux-ia64/linux-stable-rc that referenced this pull request

Dec 13, 2024

@nbdd0121

commit c95bbb5 upstream.

The term "receiver" means that a type can be used as the type of self, and thus enables method call syntax foo.bar() instead of Foo::bar(foo). Stable Rust as of today (1.81) enables a limited selection of types (primitives and types in std, e.g. Box and Arc) to be used as receivers, while custom types cannot.

We want the kernel Arc type to have the same functionality as the Rust std Arc, so we use the Receiver trait (gated behind receiver_trait unstable feature) to gain the functionality.

The arbitrary_self_types RFC [1] (tracking issue [2]) is accepted and it will allow all types that implement a new Receiver trait (different from today's unstable trait) to be used as receivers. This trait will be automatically implemented for all Deref types, which include our Arc type, so we no longer have to opt-in to be used as receiver. To prepare us for the change, remove the Receiver implementation and the associated feature. To still allow Arc and others to be used as method receivers, turn on arbitrary_self_types feature instead.

This feature gate is introduced in 1.23.0. It used to enable both Deref types and raw pointer types to be used as receivers, but the latter is now split into a different feature gate in Rust 1.83 nightly. We do not need receivers on raw pointers so this change would not affect us and usage of arbitrary_self_types feature would work for all Rust versions that we support (>=1.78).

Cc: Adrian Taylor ade@hohum.me.uk Link: rust-lang/rfcs#3519 [1] Link: rust-lang/rust#44874 [2] Signed-off-by: Gary Guo gary@garyguo.net Reviewed-by: Benno Lossin benno.lossin@proton.me Reviewed-by: Alice Ryhl aliceryhl@google.com Link: https://lore.kernel.org/r/20240915132734.1653004-1-gary@garyguo.net Signed-off-by: Miguel Ojeda ojeda@kernel.org Signed-off-by: Greg Kroah-Hartman gregkh@linuxfoundation.org

mj22226 pushed a commit to mj22226/linux that referenced this pull request

Dec 13, 2024

@nbdd0121 @gregkh

commit c95bbb5 upstream.

The term "receiver" means that a type can be used as the type of self, and thus enables method call syntax foo.bar() instead of Foo::bar(foo). Stable Rust as of today (1.81) enables a limited selection of types (primitives and types in std, e.g. Box and Arc) to be used as receivers, while custom types cannot.

We want the kernel Arc type to have the same functionality as the Rust std Arc, so we use the Receiver trait (gated behind receiver_trait unstable feature) to gain the functionality.

The arbitrary_self_types RFC [1] (tracking issue [2]) is accepted and it will allow all types that implement a new Receiver trait (different from today's unstable trait) to be used as receivers. This trait will be automatically implemented for all Deref types, which include our Arc type, so we no longer have to opt-in to be used as receiver. To prepare us for the change, remove the Receiver implementation and the associated feature. To still allow Arc and others to be used as method receivers, turn on arbitrary_self_types feature instead.

This feature gate is introduced in 1.23.0. It used to enable both Deref types and raw pointer types to be used as receivers, but the latter is now split into a different feature gate in Rust 1.83 nightly. We do not need receivers on raw pointers so this change would not affect us and usage of arbitrary_self_types feature would work for all Rust versions that we support (>=1.78).

Cc: Adrian Taylor ade@hohum.me.uk Link: rust-lang/rfcs#3519 [1] Link: rust-lang/rust#44874 [2] Signed-off-by: Gary Guo gary@garyguo.net Reviewed-by: Benno Lossin benno.lossin@proton.me Reviewed-by: Alice Ryhl aliceryhl@google.com Link: https://lore.kernel.org/r/20240915132734.1653004-1-gary@garyguo.net Signed-off-by: Miguel Ojeda ojeda@kernel.org Signed-off-by: Greg Kroah-Hartman gregkh@linuxfoundation.org

johnny-mnemonic pushed a commit to linux-ia64/linux-stable-rc that referenced this pull request

Dec 14, 2024

@nbdd0121

commit c95bbb5 upstream.

The term "receiver" means that a type can be used as the type of self, and thus enables method call syntax foo.bar() instead of Foo::bar(foo). Stable Rust as of today (1.81) enables a limited selection of types (primitives and types in std, e.g. Box and Arc) to be used as receivers, while custom types cannot.

We want the kernel Arc type to have the same functionality as the Rust std Arc, so we use the Receiver trait (gated behind receiver_trait unstable feature) to gain the functionality.

The arbitrary_self_types RFC [1] (tracking issue [2]) is accepted and it will allow all types that implement a new Receiver trait (different from today's unstable trait) to be used as receivers. This trait will be automatically implemented for all Deref types, which include our Arc type, so we no longer have to opt-in to be used as receiver. To prepare us for the change, remove the Receiver implementation and the associated feature. To still allow Arc and others to be used as method receivers, turn on arbitrary_self_types feature instead.

This feature gate is introduced in 1.23.0. It used to enable both Deref types and raw pointer types to be used as receivers, but the latter is now split into a different feature gate in Rust 1.83 nightly. We do not need receivers on raw pointers so this change would not affect us and usage of arbitrary_self_types feature would work for all Rust versions that we support (>=1.78).

Cc: Adrian Taylor ade@hohum.me.uk Link: rust-lang/rfcs#3519 [1] Link: rust-lang/rust#44874 [2] Signed-off-by: Gary Guo gary@garyguo.net Reviewed-by: Benno Lossin benno.lossin@proton.me Reviewed-by: Alice Ryhl aliceryhl@google.com Link: https://lore.kernel.org/r/20240915132734.1653004-1-gary@garyguo.net Signed-off-by: Miguel Ojeda ojeda@kernel.org Signed-off-by: Greg Kroah-Hartman gregkh@linuxfoundation.org

gregkh pushed a commit to gregkh/linux that referenced this pull request

Dec 14, 2024

@nbdd0121 @gregkh

commit c95bbb5 upstream.

The term "receiver" means that a type can be used as the type of self, and thus enables method call syntax foo.bar() instead of Foo::bar(foo). Stable Rust as of today (1.81) enables a limited selection of types (primitives and types in std, e.g. Box and Arc) to be used as receivers, while custom types cannot.

We want the kernel Arc type to have the same functionality as the Rust std Arc, so we use the Receiver trait (gated behind receiver_trait unstable feature) to gain the functionality.

The arbitrary_self_types RFC [1] (tracking issue [2]) is accepted and it will allow all types that implement a new Receiver trait (different from today's unstable trait) to be used as receivers. This trait will be automatically implemented for all Deref types, which include our Arc type, so we no longer have to opt-in to be used as receiver. To prepare us for the change, remove the Receiver implementation and the associated feature. To still allow Arc and others to be used as method receivers, turn on arbitrary_self_types feature instead.

This feature gate is introduced in 1.23.0. It used to enable both Deref types and raw pointer types to be used as receivers, but the latter is now split into a different feature gate in Rust 1.83 nightly. We do not need receivers on raw pointers so this change would not affect us and usage of arbitrary_self_types feature would work for all Rust versions that we support (>=1.78).

Cc: Adrian Taylor ade@hohum.me.uk Link: rust-lang/rfcs#3519 [1] Link: rust-lang/rust#44874 [2] Signed-off-by: Gary Guo gary@garyguo.net Reviewed-by: Benno Lossin benno.lossin@proton.me Reviewed-by: Alice Ryhl aliceryhl@google.com Link: https://lore.kernel.org/r/20240915132734.1653004-1-gary@garyguo.net Signed-off-by: Miguel Ojeda ojeda@kernel.org Signed-off-by: Greg Kroah-Hartman gregkh@linuxfoundation.org

johnny-mnemonic pushed a commit to linux-ia64/linux-stable-rc that referenced this pull request

Dec 15, 2024

@nbdd0121

commit c95bbb5 upstream.

The term "receiver" means that a type can be used as the type of self, and thus enables method call syntax foo.bar() instead of Foo::bar(foo). Stable Rust as of today (1.81) enables a limited selection of types (primitives and types in std, e.g. Box and Arc) to be used as receivers, while custom types cannot.

We want the kernel Arc type to have the same functionality as the Rust std Arc, so we use the Receiver trait (gated behind receiver_trait unstable feature) to gain the functionality.

The arbitrary_self_types RFC [1] (tracking issue [2]) is accepted and it will allow all types that implement a new Receiver trait (different from today's unstable trait) to be used as receivers. This trait will be automatically implemented for all Deref types, which include our Arc type, so we no longer have to opt-in to be used as receiver. To prepare us for the change, remove the Receiver implementation and the associated feature. To still allow Arc and others to be used as method receivers, turn on arbitrary_self_types feature instead.

This feature gate is introduced in 1.23.0. It used to enable both Deref types and raw pointer types to be used as receivers, but the latter is now split into a different feature gate in Rust 1.83 nightly. We do not need receivers on raw pointers so this change would not affect us and usage of arbitrary_self_types feature would work for all Rust versions that we support (>=1.78).

Cc: Adrian Taylor ade@hohum.me.uk Link: rust-lang/rfcs#3519 [1] Link: rust-lang/rust#44874 [2] Signed-off-by: Gary Guo gary@garyguo.net Reviewed-by: Benno Lossin benno.lossin@proton.me Reviewed-by: Alice Ryhl aliceryhl@google.com Link: https://lore.kernel.org/r/20240915132734.1653004-1-gary@garyguo.net Signed-off-by: Miguel Ojeda ojeda@kernel.org Signed-off-by: Greg Kroah-Hartman gregkh@linuxfoundation.org

kongwoojin pushed a commit to kongwoojin/linux-kernel that referenced this pull request

Dec 17, 2024

@nbdd0121 @kongwoojin

commit c95bbb5 upstream.

The term "receiver" means that a type can be used as the type of self, and thus enables method call syntax foo.bar() instead of Foo::bar(foo). Stable Rust as of today (1.81) enables a limited selection of types (primitives and types in std, e.g. Box and Arc) to be used as receivers, while custom types cannot.

We want the kernel Arc type to have the same functionality as the Rust std Arc, so we use the Receiver trait (gated behind receiver_trait unstable feature) to gain the functionality.

The arbitrary_self_types RFC [1] (tracking issue [2]) is accepted and it will allow all types that implement a new Receiver trait (different from today's unstable trait) to be used as receivers. This trait will be automatically implemented for all Deref types, which include our Arc type, so we no longer have to opt-in to be used as receiver. To prepare us for the change, remove the Receiver implementation and the associated feature. To still allow Arc and others to be used as method receivers, turn on arbitrary_self_types feature instead.

This feature gate is introduced in 1.23.0. It used to enable both Deref types and raw pointer types to be used as receivers, but the latter is now split into a different feature gate in Rust 1.83 nightly. We do not need receivers on raw pointers so this change would not affect us and usage of arbitrary_self_types feature would work for all Rust versions that we support (>=1.78).

Cc: Adrian Taylor ade@hohum.me.uk Link: rust-lang/rfcs#3519 [1] Link: rust-lang/rust#44874 [2] Signed-off-by: Gary Guo gary@garyguo.net Reviewed-by: Benno Lossin benno.lossin@proton.me Reviewed-by: Alice Ryhl aliceryhl@google.com Link: https://lore.kernel.org/r/20240915132734.1653004-1-gary@garyguo.net Signed-off-by: Miguel Ojeda ojeda@kernel.org Signed-off-by: Greg Kroah-Hartman gregkh@linuxfoundation.org

lnicola pushed a commit to lnicola/rust-analyzer that referenced this pull request

Dec 23, 2024

@bors

…=compiler-errors,wesleywiser

Arbitrary self types v2: main compiler changes

This is the main PR in a series of PRs related to Arbitrary Self Types v2, tracked in #44874. Specifically this is step 7 of the plan [described here](rust-lang/rust#44874 (comment)), for RFC 3519.

Overall this PR:

This should not break compatibility for:

Subsequent PRs will add better diagnostics.

It's probably easiest to review this commit-by-commit.

r? @wesleywiser

tuxedo-bot pushed a commit to tuxedocomputers/linux that referenced this pull request

Feb 24, 2025

@nbdd0121 @mehmetb0

BugLink: https://bugs.launchpad.net/bugs/2096827

commit c95bbb5 upstream.

The term "receiver" means that a type can be used as the type of self, and thus enables method call syntax foo.bar() instead of Foo::bar(foo). Stable Rust as of today (1.81) enables a limited selection of types (primitives and types in std, e.g. Box and Arc) to be used as receivers, while custom types cannot.

We want the kernel Arc type to have the same functionality as the Rust std Arc, so we use the Receiver trait (gated behind receiver_trait unstable feature) to gain the functionality.

The arbitrary_self_types RFC [1] (tracking issue [2]) is accepted and it will allow all types that implement a new Receiver trait (different from today's unstable trait) to be used as receivers. This trait will be automatically implemented for all Deref types, which include our Arc type, so we no longer have to opt-in to be used as receiver. To prepare us for the change, remove the Receiver implementation and the associated feature. To still allow Arc and others to be used as method receivers, turn on arbitrary_self_types feature instead.

This feature gate is introduced in 1.23.0. It used to enable both Deref types and raw pointer types to be used as receivers, but the latter is now split into a different feature gate in Rust 1.83 nightly. We do not need receivers on raw pointers so this change would not affect us and usage of arbitrary_self_types feature would work for all Rust versions that we support (>=1.78).

Cc: Adrian Taylor ade@hohum.me.uk Link: rust-lang/rfcs#3519 [1] Link: rust-lang/rust#44874 [2] Signed-off-by: Gary Guo gary@garyguo.net Reviewed-by: Benno Lossin benno.lossin@proton.me Reviewed-by: Alice Ryhl aliceryhl@google.com Link: https://lore.kernel.org/r/20240915132734.1653004-1-gary@garyguo.net Signed-off-by: Miguel Ojeda ojeda@kernel.org Signed-off-by: Greg Kroah-Hartman gregkh@linuxfoundation.org [koichiroden: dropped changes on rust/kernel/list/arc.rs due to missing commit: 6cd3417 ("rust: list: add ListArc")] Signed-off-by: Koichiro Den koichiro.den@canonical.com