-
Notifications
You must be signed in to change notification settings - Fork 13.7k
arbitrary_self_types: Split the Autoderef chain #146095
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
arbitrary_self_types: Split the Autoderef chain #146095
Conversation
This PR changes a file inside tests/crashes
. If a crash was fixed, please move into the corresponding ui
subdir and add 'Fixes #' to the PR description to autoclose the issue upon merge.
This comment has been minimized.
This comment has been minimized.
bef5ba5
to
f3e8785
Compare
This comment has been minimized.
This comment has been minimized.
f3e8785
to
31788b7
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
@rustbot label +F-arbitrary_self_types
Receiver chain has been an extension of Deref chain, but the consequence has been questioned as this would admit method signatures that are deemed dubious. It is also debatable that Receiver trait which determines applicable `Self` type should have anything to do with dereference operation in general. This patch separate the two traits and isolate their use in the language. This means that in method probing, we will chase down a Deref chain for an applicable type for the variable `self`, from which we additionally chase down a Receiver chain for an applicable `Self` type from a list of methods that accepts one of these possible types of `self`.
31788b7
to
1a2dbf8
Compare
The Miri subtree was changed
cc @rust-lang/miri
Some changes occurred in compiler/rustc_codegen_gcc
This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed.
Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.
The job aarch64-gnu-llvm-19-2
failed! Check out the build log: (web) (plain enhanced) (plain)
Click to see the possible cause of the failure (guessed by this bot)
[RUSTC-TIMING] ____ test:false 0.023
##[endgroup]
##[group][AOT] arbitrary_self_types_pointers_and_wrappers
[AOT] arbitrary_self_types_pointers_and_wrappers
error[E0307]: invalid `self` parameter type: `Ptr<Wrapper<i32>>`
##[error] --> example/arbitrary_self_types_pointers_and_wrappers.rs:41:26
|
41 | fn ptr_wrapper(self: Ptr<Wrapper<Self>>) -> i32 {
| ^^^^^^^^^^^^^^^^^^
|
= note: type of `self` must be `Self` or some type implementing `Receiver`
= help: consider changing to `self`, `&self`, `&mut self`, or a type implementing `Receiver` such as `self: Box<Self>`, `self: Rc<Self>`, or `self: Arc<Self>`
error[E0307]: invalid `self` parameter type: `Wrapper<Ptr<i32>>`
##[error] --> example/arbitrary_self_types_pointers_and_wrappers.rs:44:26
|
44 | fn wrapper_ptr(self: Wrapper<Ptr<Self>>) -> i32 {
| ^^^^^^^^^^^^^^^^^^
|
= note: type of `self` must be `Self` or some type implementing `Receiver`
= help: consider changing to `self`, `&self`, `&mut self`, or a type implementing `Receiver` such as `self: Box<Self>`, `self: Rc<Self>`, or `self: Arc<Self>`
error[E0307]: invalid `self` parameter type: `Wrapper<Ptr<Wrapper<i32>>>`
##[error] --> example/arbitrary_self_types_pointers_and_wrappers.rs:47:34
|
47 | fn wrapper_ptr_wrapper(self: Wrapper<Ptr<Wrapper<Self>>>) -> i32 {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: type of `self` must be `Self` or some type implementing `Receiver`
= help: consider changing to `self`, `&self`, `&mut self`, or a type implementing `Receiver` such as `self: Box<Self>`, `self: Rc<Self>`, or `self: Arc<Self>`
error[E0307]: invalid `self` parameter type: `Ptr<Wrapper<Self>>`
##[error] --> example/arbitrary_self_types_pointers_and_wrappers.rs:35:26
|
35 | fn ptr_wrapper(self: Ptr<Wrapper<Self>>) -> i32;
| ^^^^^^^^^^^^^^^^^^
|
= note: type of `self` must be `Self` or some type implementing `Receiver`
= help: consider changing to `self`, `&self`, `&mut self`, or a type implementing `Receiver` such as `self: Box<Self>`, `self: Rc<Self>`, or `self: Arc<Self>`
error[E0307]: invalid `self` parameter type: `Wrapper<Ptr<Self>>`
##[error] --> example/arbitrary_self_types_pointers_and_wrappers.rs:36:26
|
36 | fn wrapper_ptr(self: Wrapper<Ptr<Self>>) -> i32;
| ^^^^^^^^^^^^^^^^^^
|
= note: type of `self` must be `Self` or some type implementing `Receiver`
= help: consider changing to `self`, `&self`, `&mut self`, or a type implementing `Receiver` such as `self: Box<Self>`, `self: Rc<Self>`, or `self: Arc<Self>`
error[E0307]: invalid `self` parameter type: `Wrapper<Ptr<Wrapper<Self>>>`
##[error] --> example/arbitrary_self_types_pointers_and_wrappers.rs:37:34
|
37 | fn wrapper_ptr_wrapper(self: Wrapper<Ptr<Wrapper<Self>>>) -> i32;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: type of `self` must be `Self` or some type implementing `Receiver`
= help: consider changing to `self`, `&self`, `&mut self`, or a type implementing `Receiver` such as `self: Box<Self>`, `self: Rc<Self>`, or `self: Arc<Self>`
error: aborting due to 6 previous errors
For more information about this error, try `rustc --explain E0307`.
"/checkout/obj/build/aarch64-unknown-linux-gnu/stage2-codegen/cg_clif/dist/rustc-clif" "-Csymbol-mangling-version=v0" "-Zrandomize-layout" "-Zunstable-options" "--check-cfg=cfg(bootstrap)" "--check-cfg=cfg(llvm_enzyme)" "-Zmacro-backtrace" "-Csplit-debuginfo=off" "-Clink-arg=-L/usr/lib/llvm-19/lib" "-Cllvm-args=-import-instr-limit=10" "-Clink-args=-Wl,-z,origin" "-Clink-args=-Wl,-rpath,$ORIGIN/../lib" "-Alinker-messages" "-L" "crate=/checkout/obj/build/aarch64-unknown-linux-gnu/stage2-codegen/cg_clif/build/example" "--out-dir" "/checkout/obj/build/aarch64-unknown-linux-gnu/stage2-codegen/cg_clif/build/example" "-Cdebuginfo=2" "--target" "aarch64-unknown-linux-gnu" "-Cpanic=abort" "--check-cfg=cfg(jit)" "example/arbitrary_self_types_pointers_and_wrappers.rs" exited with status ExitStatus(unix_wait_status(256))
Command `/checkout/obj/build/aarch64-unknown-linux-gnu/stage0/bin/cargo run --target aarch64-unknown-linux-gnu -Zbinary-dep-depinfo -j 4 -Zroot-dir=/checkout --locked --color always --release --manifest-path /checkout/compiler/rustc_codegen_cranelift/build_system/Cargo.toml -- test --download-dir /checkout/obj/build/cg_clif_download --out-dir /checkout/obj/build/aarch64-unknown-linux-gnu/stage2-codegen/cg_clif --no-unstable-features --use-backend cranelift --sysroot llvm --skip-test testsuite.extended_sysroot [workdir=/checkout/compiler/rustc_codegen_cranelift]` failed with exit code 1
Created at: src/bootstrap/src/core/build_steps/test.rs:3645:25
Executed at: src/bootstrap/src/core/build_steps/test.rs:3686:26
Command has failed. Rerun with -v to see more details.
Bootstrap failed while executing `--stage 2 test --skip tests --skip coverage-map --skip coverage-run --skip library --skip tidyselftest`
Build completed unsuccessfully in 0:25:15
local time: Tue Sep 2 09:16:17 UTC 2025
network time: 2025年9月02日 09:16:17 GMT
##[error]Process completed with exit code 1.
Receiver chain has been an extension of Deref chain, but the consequence has been questioned as this would admit method signatures that are deemed dubious.
It is also debatable that Receiver trait which determines applicable
Self
type should have anything to do with dereference operation in general.This patch separate the two traits and isolate their use in the language. This means that in method probing, we will chase down a Deref chain for an applicable type for the variable
self
, from which we additionally chase down a Receiver chain for an applicableSelf
type from a list of methods that accepts one of these possible types ofself
.To facilitate discussion, we can use the Zulip thread #t-lang > Consequences of making Deref a subtrait of Receiver.