From 465d24e1a03f21c1c7685f5105a32ffc52bdd68c Mon Sep 17 00:00:00 2001 From: Cesar Eduardo Barros Date: Thu, 19 Jan 2017 18:16:11 -0200 Subject: [PATCH 1/2] book: size and align in trait object vtables are used The book currently claims that the `size` and `align` fields in the trait object vtable are not used, but this is false. These two fields are used by the stable `mem::size_of_val` and `mem::align_of_val` functions. See the `ty::TyDynamic` case of the `glue::size_and_align_of_dst` function in librustc_trans, which is used to implement both intrinsics in the unsized case. --- src/doc/book/trait-objects.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/doc/book/trait-objects.md b/src/doc/book/trait-objects.md index a0396a75fa26e..71536f409e8f4 100644 --- a/src/doc/book/trait-objects.md +++ b/src/doc/book/trait-objects.md @@ -264,9 +264,7 @@ will free the memory. This is necessary for owning trait objects like `Box`, which need to clean-up both the `Box` allocation as well as the internal type when they go out of scope. The `size` and `align` fields store the size of the erased type, and its alignment requirements; these are -essentially unused at the moment since the information is embedded in the -destructor, but will be used in the future, as trait objects are progressively -made more flexible. +used by the `std::mem::size_of_val` and `std::mem::align_of_val` functions. Suppose we’ve got some values that implement `Foo`. The explicit form of construction and use of `Foo` trait objects might look a bit like (ignoring the From c7b092b47d8e50b58c975040af0a84a544f7fa7a Mon Sep 17 00:00:00 2001 From: Cesar Eduardo Barros Date: Thu, 19 Jan 2017 22:45:57 -0200 Subject: [PATCH 2/2] No need to mention how these fields are used --- src/doc/book/trait-objects.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/doc/book/trait-objects.md b/src/doc/book/trait-objects.md index 71536f409e8f4..00a841a75db86 100644 --- a/src/doc/book/trait-objects.md +++ b/src/doc/book/trait-objects.md @@ -263,8 +263,7 @@ any resources of the vtable’s type: for `u8` it is trivial, but for `String` i will free the memory. This is necessary for owning trait objects like `Box`, which need to clean-up both the `Box` allocation as well as the internal type when they go out of scope. The `size` and `align` fields store -the size of the erased type, and its alignment requirements; these are -used by the `std::mem::size_of_val` and `std::mem::align_of_val` functions. +the size of the erased type, and its alignment requirements. Suppose we’ve got some values that implement `Foo`. The explicit form of construction and use of `Foo` trait objects might look a bit like (ignoring the