Skip to content
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

Merged
merged 2 commits into from
Feb 15, 2018
Merged

Clarified why Sized bound not implicit on trait's implicit Self type. #48210

merged 2 commits into from
Feb 15, 2018

Conversation

jacob-hughes
Copy link
Contributor

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

@rust-highfive
Copy link
Collaborator

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.

/// 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.
Copy link
Contributor

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?

Copy link
Member

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.

Copy link
Contributor Author

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?

@pietroalbini pietroalbini added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Feb 14, 2018
@QuietMisdreavus
Copy link
Member

Looks great, thanks so much!

@bors r+ rollup

@bors
Copy link
Contributor

bors commented Feb 14, 2018

📌 Commit 38064a9 has been approved by QuietMisdreavus

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Feb 14, 2018
kennytm added a commit to kennytm/rust that referenced this pull request Feb 15, 2018
…_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.
bors added a commit that referenced this pull request Feb 15, 2018
@kennytm kennytm merged commit 38064a9 into rust-lang:master Feb 15, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants