-
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
Clarify object safety rules for methods striked from the vtable #965
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -67,23 +67,23 @@ trait Seq<T> { | |||||
Object safe traits can be the base trait of a [trait object]. A trait is | ||||||
*object safe* if it has the following qualities (defined in [RFC 255]): | ||||||
|
||||||
* It must not require `Self: Sized` | ||||||
* All associated functions must either have a `where Self: Sized` bound, or | ||||||
* Not have any type parameters (although lifetime parameters are allowed), | ||||||
and | ||||||
* Be a [method] that does not use `Self` except in the type of the receiver. | ||||||
* All [supertraits] must also be object safe. | ||||||
* It must not require `Self: Sized` (i.e. `Sized` must not be a [supertrait][supertraits]) | ||||||
* It must not have any associated constants. | ||||||
* All supertraits must also be object safe. | ||||||
|
||||||
When there isn't a `Self: Sized` bound on a method, the type of a method | ||||||
receiver must be one of the following types: | ||||||
|
||||||
* `&Self` | ||||||
* `&mut Self` | ||||||
* [`Box<Self>`] | ||||||
* [`Rc<Self>`] | ||||||
* [`Arc<Self>`] | ||||||
* [`Pin<P>`] where `P` is one of the types above | ||||||
* All associated functions must "dispatchable from a trait object" or "explicitly non-dispatchable from a trait object": | ||||||
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.
Suggested change
|
||||||
* Dispatchable functions require: | ||||||
* Not have any type parameters (although lifetime parameters are allowed), | ||||||
* Be a [method] that does not use `Self` except in the type of the receiver. | ||||||
* Have a receiver with one of the following types: | ||||||
* `&Self` (i.e. `&self`) | ||||||
* `&mut Self` (i.e `&mut self`) | ||||||
* [`Box<Self>`] | ||||||
* [`Rc<Self>`] | ||||||
* [`Arc<Self>`] | ||||||
* [`Pin<P>`] where `P` is one of the types above | ||||||
* Does not have a `where Self: Sized` bound (reciever type of `Self` (i.e. `self`) implies this). | ||||||
* Explicitly non-dispatchable functions require: | ||||||
* Have a `where Self: Sized` bound (reciever type of `Self` (i.e. `self`) implies this). | ||||||
|
||||||
```rust | ||||||
# use std::rc::Rc; | ||||||
|
@@ -325,6 +325,7 @@ fn main() { | |||||
[RFC 255]: https://github.com/rust-lang/rfcs/blob/master/text/0255-object-safety.md | ||||||
[associated items]: associated-items.md | ||||||
[method]: associated-items.md#methods | ||||||
[supertraits]: #supertraits | ||||||
[implementations]: implementations.md | ||||||
[generics]: generics.md | ||||||
[where clauses]: generics.md#where-clauses | ||||||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Let's avoid the latinisms like "i.e."