Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/libcore/marker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,13 @@ impl<T: ?Sized> !Send for *mut T { }
/// struct BarUse(Bar<[i32]>); // OK
/// ```
///
/// The one exception is the implicit `Self` type of a trait, which does not
/// get an implicit `Sized` bound. This is because a `Sized` bound prevents
/// the trait from being used to form a [trait object]:
/// 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
Contributor

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?

///
/// Although Rust will let you bind `Sized` to a trait, you won't
/// be able to use it as a trait object later:
///
/// ```
/// # #![allow(unused_variables)]
Expand Down