-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Clarified why Sized
bound not implicit on trait's implicit Self
type.
#48210
Clarified why Sized
bound not implicit on trait's implicit Self
type.
#48210
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @steveklabnik (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
src/libcore/marker.rs
Outdated
/// The one exception is the implicit `Self` type of a trait. A trait does not | ||
/// have an implicit `Sized` bound as this is incompatible with [trait object]s | ||
/// where, by definition, one cannot know the size of all possible | ||
/// implementations of the trait. |
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.
👍 for explaining why trait objects are not Sized
.
I think the compiler would "know" the size of all implementations. But it's not something that is encoded in trait objects? Is there a clearer way to phrase this?
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.
It's especially important for public traits, since those are truly open-ended. If you're using a trait object, then that function needs to be treated as if the variable that's holding it has a single size, but if the trait is public, some new struct from downstream could come along that's a different size from what was expected. Perhaps something like this?
...with trait objects, which need to work with any implementor of the trait, and thus can be any size.
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 agree with both comments that this could be clearer. I've changed this slightly and, although more wordy, seems to read a bit better. What do you think?
Looks great, thanks so much! @bors r+ rollup |
📌 Commit 38064a9 has been approved by |
…_api_docs, r=QuietMisdreavus Clarified why `Sized` bound not implicit on trait's implicit `Self` type. This part of the documentation was a little confusing to me on first read. I've added a couple lines for further explanation. Hopefully this makes things a bit clearer for new readers.
This part of the documentation was a little confusing to me on first read. I've added a couple lines for further explanation. Hopefully this makes things a bit clearer for new readers.
r? @steveklabnik