forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#117495 - compiler-errors:unsize-docs, r=lcnr
Clarify `Unsize` documentation The documentation erroneously says that: ```rust /// - Types implementing a trait `Trait` also implement `Unsize<dyn Trait>`. /// - Structs `Foo<..., T, ...>` implement `Unsize<Foo<..., U, ...>>` if all of these conditions /// are met: /// - `T: Unsize<U>`. /// - Only the last field of `Foo` has a type involving `T`. /// - `Bar<T>: Unsize<Bar<U>>`, where `Bar<T>` stands for the actual type of that last field. ``` Specifically, `T: Unsize<U>` is not required to hold -- only the final field must implement `FinalField<T>: Unsize<FinalField<U>>`. This can be demonstrated by the test I added. --- Second commit fleshes out the documentation a lot more.
- Loading branch information
Showing
2 changed files
with
41 additions
and
6 deletions.
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
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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// check-pass | ||
|
||
struct Foo<T, U> | ||
where | ||
(T, U): Trait, | ||
{ | ||
f: <(T, U) as Trait>::Assoc, | ||
} | ||
|
||
trait Trait { | ||
type Assoc: ?Sized; | ||
} | ||
|
||
struct Count<const N: usize>; | ||
|
||
impl<const N: usize> Trait for (i32, Count<N>) { | ||
type Assoc = [(); N]; | ||
} | ||
|
||
impl<'a> Trait for (u32, ()) { | ||
type Assoc = [()]; | ||
} | ||
|
||
// Test that we can unsize several trait params in creative ways. | ||
fn unsize<const N: usize>(x: &Foo<i32, Count<N>>) -> &Foo<u32, ()> { | ||
x | ||
} | ||
|
||
fn main() {} |