2
2
3
3
#### Aliasing
4
4
5
- (Please note: a full aliasing model for Rust has not yet been constructed, but
6
- at the moment we can give the following definition. The most developed potential
7
- aliasing model so far is known as "Stacked Borrows", and can be found
8
- [ here] ( https://github.com/rust-lang/unsafe-code-guidelines/blob/master/wip/stacked-borrows.md ) .)
9
-
10
- * Aliasing* is any time one pointer or reference points to a "span" of memory
5
+ * Aliasing* occurs when one pointer or reference points to a "span" of memory
11
6
that overlaps with the span of another pointer or reference. A span of memory is
12
7
similar to how a slice works: there's a base byte address as well as a length in
13
8
bytes.
14
9
10
+ ** Note** : a full aliasing model for Rust, defining when aliasing is allowed
11
+ and when not, has not yet been defined. The purpose of this definition is to
12
+ define when aliasing * happens* , not when it is * allowed* . The most developed
13
+ potential aliasing model so far is known as "Stacked Borrows", and can be found
14
+ [ here] ( https://github.com/rust-lang/unsafe-code-guidelines/blob/master/wip/stacked-borrows.md ) .
15
+
15
16
Consider the following example:
16
17
17
18
``` rust
@@ -33,7 +34,6 @@ byte of `u` and `tail` points to the other seven bytes of `u` after it. Both `he
33
34
and ` tail ` alias ` s ` , any overlap is sufficient to count as an alias.
34
35
35
36
The span of a pointer or reference is the size of the value being pointed to or referenced.
36
-
37
37
Depending on the type, you can determine the size as follows:
38
38
39
39
* For a type ` T ` that is [ ` Sized ` ] ( https://doc.rust-lang.org/core/marker/trait.Sized.html )
0 commit comments