Section on coercions fails to mention requirement on trait object creation
Nobody has claimed this yet.
- Dominant language
- CSS
- Stars
- 2.3k
- Forks
- 325
- PR merge metrics
- No merged PRs in 30d
Description
Rust converts a Pointer<T> to a Pointer<Trait> where T implements Trait and Pointer is a type constructor like & or Box, only if Pointer<T> is a thin pointer. The Nomicon suggests otherwise.
According to the "Coercions" section of the Nomicon:
Pointer<T>: CoerceUnsized<Pointer<U>>for all pointer types, whereT: Unsize<U>.Unsize<U>is automatically implemented forTifT: U.
Suppose I have two traits T1 and T2, and impl T2 for T1. Since T1: Unsize<T2>, the Nomicon claims that Pointer<T1>: CoerceUnsized<Pointer<T2>>. But I can't convert a Box<T1> to a Box<T2>; that would be a doubly-fat pointer, since it needs both the vtable for impl T2 for T1 and whatever vtable Box<T1> was using.
There was a longish thread about this; I think this post is where I finally got it right: https://users.rust-lang.org/t/trait-objects-of-trait-objects/14077/27
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the Nomicon's "Coercions" section and compare its statements about CoerceUnsized, Unsize, and trait-object creation with the Box to Box example in the issue. Read the linked Rust Users discussion for the settled explanation, then revise the section to state the missing thin-pointer requirement and verify that the example is accurately covered.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- documentation
- Issue type
- Documentation
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100