-
Notifications
You must be signed in to change notification settings - Fork 508
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 v2: update reference. #1699
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,34 +17,12 @@ r[lang-types.box.deref] | |
* The [dereference operator] for `Box<T>` produces a place which can be moved | ||
from. This means that the `*` operator and the destructor of `Box<T>` are | ||
built-in to the language. | ||
|
||
r[lang-types.box.receiver] | ||
* [Methods] can take `Box<Self>` as a receiver. | ||
|
||
r[lang-types.box.fundamental] | ||
* A trait may be implemented for `Box<T>` in the same crate as `T`, which the | ||
[orphan rules] prevent for other generic types. | ||
|
||
<!-- Editor Note: This is nowhere close to an exhaustive list --> | ||
|
||
r[lang-types.rc] | ||
## `Rc<T>` | ||
|
||
r[lang-types.rc.receiver] | ||
[Methods] can take [`Rc<Self>`] as a receiver. | ||
|
||
r[lang-types.arc] | ||
## `Arc<T>` | ||
|
||
r[lang-types.arc.receiver] | ||
[Methods] can take [`Arc<Self>`] as a receiver. | ||
|
||
r[lang-types.pin] | ||
## `Pin<P>` | ||
|
||
r[lang-types.pin.receiver] | ||
[Methods] can take [`Pin<P>`] as a receiver. | ||
Comment on lines
-42
to
-46
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: Is |
||
|
||
r[lang-types.unsafe-cell] | ||
## `UnsafeCell<T>` | ||
|
||
|
@@ -73,7 +51,19 @@ r[lang-types.deref] | |
## `Deref` and `DerefMut` | ||
|
||
As well as overloading the unary `*` operator, [`Deref`] and [`DerefMut`] are | ||
also used in [method resolution] and [deref coercions]. | ||
also used in [deref coercions]; see also [`Receiver`] below. | ||
|
||
r[lang-types.receiver] | ||
## `Receiver` | ||
|
||
[`Receiver`] is used in [method resolution]. It indicates that a type may be | ||
used as a method receiver; that is, the type of a `self` parameter for a | ||
method. There is a blanket implementation of `Receiver` for all `T: Deref`, | ||
so it's rare to implement `Receiver` directly: you'd only normally do this | ||
for smart pointer types which for some reason can't implement `Deref`. | ||
Comment on lines
+62
to
+63
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd probably remove this bit about it being rare and instead describe affirmatively why There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The same comment probably applies to #1725 but let's see which PR seems most likely to succeed before I tackle this (relative) detail. |
||
Built-in types which implement `Receiver` (via `Deref`) and are commonly | ||
used as method receivers include `Rc<T>`, `Arc<T>`, `Box<T>`, and `Pin<P>` | ||
where `P: Deref`. | ||
|
||
r[lang-types.drop] | ||
## `Drop` | ||
|
@@ -218,6 +208,7 @@ These implicit `Sized` bounds may be relaxed by using the special `?Sized` bound | |
[`DerefMut`]: std::ops::DerefMut | ||
[`Pin<P>`]: std::pin::Pin | ||
[`Rc<Self>`]: std::rc::Rc | ||
[`Receiver`]: std::ops::Receiver | ||
[`RefUnwindSafe`]: std::panic::RefUnwindSafe | ||
[`Termination`]: std::process::Termination | ||
[`UnwindSafe`]: std::panic::UnwindSafe | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is better, but still some things we can improve:
T
, add ... to the list"), but we don't mean the list of "candidate types" as defined later, we mean the list of "contributing types". The word "candidate" is also used further below in a seemingly-inconsistent way.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed with all your points other than this one:
It is of semantic relevance - it says this, which you may have overlooked:
I'll have another crack at it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great, thanks. Did miss that bit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I attempted a major rewrite of this bit of the reference in #1725. It's an alternative to this PR.