Arbitrary self types v2: use Receiver trait
In this new version of Arbitrary Self Types, we no longer use the Deref trait exclusively when working out which self types are valid. Instead, we follow a chain of Receiver traits. This enables methods to be called on smart pointer types which fundamentally cannot support Deref (for instance because they are wrappers for pointers that don't follow Rust's aliasing rules). This includes: * Changes to tests appropriately * New tests for: * The basics of the feature * Ensuring lifetime elision works properly * Generic Receivers * A copy of the method subst test enhanced with Receiver This is really the heart of the 'arbitrary self types v2' feature, and is the most critical commit in the current PR. Subsequent commits are focused on: * Detecting "shadowing" problems, where a smart pointer type can hide methods in the pointee. * Diagnostics and cleanup. Naming: in this commit, the "Autoderef" type is modified so that it no longer solely focuses on the "Deref" trait, but can now consider the "Receiver" trait instead. Should it be renamed, to something like "TraitFollower"? This was considered, but rejected, because * even in the Receiver case, it still considers built-in derefs * the name Autoderef is short and snappy.
This commit is contained in:
@@ -65,8 +65,10 @@ impl Trait for Foo {
|
||||
```
|
||||
|
||||
The nightly feature [Arbitrary self types][AST] extends the accepted
|
||||
set of receiver types to also include any type that can dereference to
|
||||
`Self`:
|
||||
set of receiver types to also include any type that implements the
|
||||
`Receiver` trait and can follow its chain of `Target` types to `Self`.
|
||||
There's a blanket implementation of `Receiver` for `T: Deref`, so any
|
||||
type which dereferences to `Self` can be used.
|
||||
|
||||
```
|
||||
#![feature(arbitrary_self_types)]
|
||||
|
||||
Reference in New Issue
Block a user