Skip to content

Commit fdcef75

Browse files
authored
Editorial changes. (#120)
Editorial changes.
2 parents 0bddb89 + d148b40 commit fdcef75

File tree

1 file changed

+17
-13
lines changed

1 file changed

+17
-13
lines changed

reference/src/layout/pointers.md

+17-13
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,33 @@
22

33
### Terminology
44

5-
Reference types are types of the form `&T`, `&mut T` or `&dyn T`.
5+
Reference types are types of the form `&T`, `&mut T`.
66

77
Raw pointer types are types of the form `*const T` or `*mut T`.
8-
We write `*T` when the mutability attribute is unimportant.
98

109
### Representation
1110

1211
The alignment of `&T`, `&mut T`, `*const T` and `*mut T` are the same,
1312
and are at least the word size.
1413

15-
* If `T` is a trait, then the alignment of `&dyn T` is the word size.
1614
* If `T` is a sized type then the alignment of `&T` is the word size.
15+
* The alignment of `&dyn Trait` is the word size.
1716
* The alignment of `&[T]` is the word size.
1817
* The alignment of `&str` is the word size.
1918
* Alignment in other cases may be more than the word size (e.g., for other dynamically sized types).
2019

2120
The sizes of `&T`, `&mut T`, `*const T` and `*mut T` are the same,
2221
and are at least one word.
2322

24-
* If `T` is a trait, then the size of `&dyn T` is two words.
2523
* If `T` is a sized type then the size of `&T` is one word.
24+
* The size of `&dyn Trait` is two words.
2625
* The size of `&[T]` is two words.
2726
* The size of `&str` is two words.
2827
* Size in other cases may be more than one word (e.g., for other dynamically sized types).
2928

3029
### Notes
3130

32-
The layouts of `&T`, `&mut T` and `*T` are the same.
31+
The layouts of `&T`, `&mut T`, `*const T` and `*mut T` are the same.
3332

3433
If `T` is sized, references and pointers to `T` have a size and alignment of one
3534
word and have therefore the same layout as C pointers.
@@ -40,25 +39,30 @@ word and have therefore the same layout as C pointers.
4039
> or, in the case of `&mut T`, aliasing.
4140
4241
We do not make any guarantees about the layout of
43-
multi-trait objects `&(dyn T + U)` or references to other dynamically sized types,
42+
multi-trait objects `&(dyn Trait1 + Trait2)` or references to other dynamically sized types,
4443
other than that they are at least word-aligned, and have size at least one word.
4544

46-
The layout of `&dyn T` when `T` is a trait is the same as that of:
47-
```rust,ignore
45+
The layout of `&dyn Trait` when `Trait` is a trait is the same as that of:
46+
```rust
4847
#[repr(C)]
4948
struct DynObject {
50-
data: *u8,
51-
vtable: *u8,
49+
data: *const u8,
50+
vtable: *const u8,
5251
}
5352
```
5453

54+
> **note**: In the layout of `&dyn mut Trait` the field `data` is of the type `*mut u8`.
55+
5556
The layout of `&[T]` is the same as that of:
56-
```rust,ignore
57+
```rust
5758
#[repr(C)]
5859
struct Slice<T> {
59-
ptr: *T,
60+
ptr: *const T,
6061
len: usize,
6162
}
6263
```
6364

64-
The layout of `&str` is the same as that of `&[u8]`.
65+
> **note**: In the layout of `&mut [T]` the field `ptr` is of the type `*mut T`.
66+
67+
The layout of `&str` is the same as that of `&[u8]`, and the layout of `&mut str` is
68+
the same as that of `&mut [u8]`.

0 commit comments

Comments
 (0)