diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2014-12-09 09:25:04 -0800 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2014-12-09 09:25:04 -0800 |
| commit | fb587f1f9bfbd102e7fffdd023c40974a3dd71cc (patch) | |
| tree | 2d01d4cff8c12bc31ec7eef70b43a9ce9a99ccc2 /src/doc/guide-pointers.md | |
| parent | ae805da48724e6238c4d2f56541774e5fcd13bf1 (diff) | |
| parent | 8ba56052330c69b6bb5bb9c477ff2d3894e5911d (diff) | |
| download | rust-fb587f1f9bfbd102e7fffdd023c40974a3dd71cc.tar.gz rust-fb587f1f9bfbd102e7fffdd023c40974a3dd71cc.zip | |
rollup merge of #19614: steveklabnik/gh19599
Fixes #19599
Diffstat (limited to 'src/doc/guide-pointers.md')
| -rw-r--r-- | src/doc/guide-pointers.md | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/src/doc/guide-pointers.md b/src/doc/guide-pointers.md index f6216760d64..dbb8d6b007d 100644 --- a/src/doc/guide-pointers.md +++ b/src/doc/guide-pointers.md @@ -84,7 +84,7 @@ println!("{}", x + z); This gives us an error: -```{notrust,ignore} +```{ignore} hello.rs:6:24: 6:25 error: mismatched types: expected `int` but found `&int` (expected int but found &-ptr) hello.rs:6 println!("{}", x + z); ^ @@ -132,7 +132,7 @@ Pointers are useful in languages that are pass-by-value, rather than pass-by-reference. Basically, languages can make two choices (this is made up syntax, it's not Rust): -```{notrust,ignore} +```{ignore} func foo(x) { x = 5 } @@ -152,7 +152,7 @@ and therefore, can change its value. At the comment, `i` will be `5`. So what do pointers have to do with this? Well, since pointers point to a location in memory... -```{notrust,ignore} +```{ignore} func foo(&int x) { *x = 5 } @@ -179,7 +179,7 @@ but here are problems with pointers in other languages: Uninitialized pointers can cause a problem. For example, what does this program do? -```{notrust,ignore} +```{ignore} &int x; *x = 5; // whoops! ``` @@ -191,7 +191,7 @@ knows. This might be harmless, and it might be catastrophic. When you combine pointers and functions, it's easy to accidentally invalidate the memory the pointer is pointing to. For example: -```{notrust,ignore} +```{ignore} func make_pointer(): &int { x = 5; @@ -213,7 +213,7 @@ As one last example of a big problem with pointers, **aliasing** can be an issue. Two pointers are said to alias when they point at the same location in memory. Like this: -```{notrust,ignore} +```{ignore} func mutate(&int i, int j) { *i = j; } @@ -398,7 +398,7 @@ fn main() { It gives this error: -```{notrust,ignore} +```{ignore} test.rs:5:8: 5:10 error: cannot assign to `*x` because it is borrowed test.rs:5 *x -= 1; ^~ @@ -522,7 +522,7 @@ boxes, though. As a rough approximation, you can treat this Rust code: As being similar to this C code: -```{notrust,ignore} +```{ignore} { int *x; x = (int *)malloc(sizeof(int)); @@ -626,7 +626,7 @@ fn main() { This prints: -```{notrust,ignore} +```{ignore} Cons(1, box Cons(2, box Cons(3, box Nil))) ``` |
