Skip to content

Commit bff1707

Browse files
Fixed one textual mistake and one casing error.
Corrected "Ownership": - [`Variable bindings`] link was not processed properly. - Changed the paragraph about move semantics with two vectors, because it was confusing. - Removed "So it may not be as inefficient as it initially seems", because there is nothing that seems inefficient in copying pointers only. - Other text corrections. Fixed copied-and-pasted text mistakes. Revised the paragraph about moving a vector (taking into account suggestions by echochamber). Fixed markdown. Fixes requested by steveklabnik. Brought back a sentence about supposed inefficiency.
1 parent 7334518 commit bff1707

File tree

4 files changed

+18
-18
lines changed

4 files changed

+18
-18
lines changed

src/doc/trpl/lifetimes.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Rust’s most unique and compelling features, with which Rust developers should
55
become quite acquainted. Ownership is how Rust achieves its largest goal,
66
memory safety. There are a few distinct concepts, each with its own chapter:
77

8-
* [ownership][ownership], ownership, the key concept
8+
* [ownership][ownership], the key concept
99
* [borrowing][borrowing], and their associated feature ‘references’
1010
* lifetimes, which you’re reading now
1111

src/doc/trpl/ownership.md

+14-14
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ become quite acquainted. Ownership is how Rust achieves its largest goal,
66
memory safety. There are a few distinct concepts, each with its own
77
chapter:
88

9-
* ownership, which you’re reading now.
9+
* ownership, which you’re reading now
1010
* [borrowing][borrowing], and their associated feature ‘references’
1111
* [lifetimes][lifetimes], an advanced concept of borrowing
1212

@@ -23,7 +23,7 @@ Before we get to the details, two important notes about the ownership system.
2323
Rust has a focus on safety and speed. It accomplishes these goals through many
2424
‘zero-cost abstractions’, which means that in Rust, abstractions cost as little
2525
as possible in order to make them work. The ownership system is a prime example
26-
of a zero cost abstraction. All of the analysis we’ll talk about in this guide
26+
of a zero-cost abstraction. All of the analysis we’ll talk about in this guide
2727
is _done at compile time_. You do not pay any run-time cost for any of these
2828
features.
2929

@@ -41,7 +41,7 @@ With that in mind, let’s learn about ownership.
4141

4242
# Ownership
4343

44-
[`Variable bindings`][bindings] have a property in Rust: they ‘have ownership’
44+
[Variable bindings][bindings] have a property in Rust: they ‘have ownership’
4545
of what they’re bound to. This means that when a binding goes out of scope, the
4646
resource that they’re bound to are freed. For example:
4747

@@ -106,8 +106,8 @@ take(v);
106106
println!("v[0] is: {}", v[0]);
107107
```
108108

109-
Same error: use of moved value.” When we transfer ownership to something else,
110-
we say that we’ve ‘moved’ the thing we refer to. You don’t need some sort of
109+
Same error: use of moved value’. When we transfer ownership to something else,
110+
we say that we’ve ‘moved’ the thing we refer to. You don’t need any sort of
111111
special annotation here, it’s the default thing that Rust does.
112112

113113
## The details
@@ -121,19 +121,19 @@ let v = vec![1, 2, 3];
121121
let v2 = v;
122122
```
123123

124-
The first line creates some data for the vector on the [stack][sh], `v`. The
125-
vector’s data, however, is stored on the [heap][sh], and so it contains a
126-
pointer to that data. When we move `v` to `v2`, it creates a copy of that pointer,
127-
for `v2`. Which would mean two pointers to the contents of the vector on the
128-
heap. That would be a problem: it would violate Rust’s safety guarantees by
129-
introducing a data race. Therefore, Rust forbids using `v` after we’ve done the
130-
move.
124+
The first line allocates memory for the vector object, `v`, and for the data it
125+
contains. The vector object is stored on the [stack][sh] and contains a pointer
126+
to the content (`[1, 2, 3]`) stored on the [heap][sh]. When we move `v` to `v2`,
127+
it creates a copy of that pointer, for `v2`. Which means that there would be two
128+
pointers to the content of the vector on the heap. It would violate Rust’s
129+
safety guarantees by introducing a data race. Therefore, Rust forbids using `v`
130+
after we’ve done the move.
131131

132132
[sh]: the-stack-and-the-heap.html
133133

134134
It’s also important to note that optimizations may remove the actual copy of
135-
the bytes, depending on circumstances. So it may not be as inefficient as it
136-
initially seems.
135+
the bytes on the stack, depending on circumstances. So it may not be as
136+
inefficient as it initially seems.
137137

138138
## `Copy` types
139139

src/doc/trpl/references-and-borrowing.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ become quite acquainted. Ownership is how Rust achieves its largest goal,
66
memory safety. There are a few distinct concepts, each with its own
77
chapter:
88

9-
* [ownership][ownership], ownership, the key concept
9+
* [ownership][ownership], the key concept
1010
* borrowing, which you’re reading now
1111
* [lifetimes][lifetimes], an advanced concept of borrowing
1212

@@ -368,4 +368,4 @@ statement 1 at 3:14
368368
369369
println!("{}", y);
370370
}
371-
```
371+
```

src/doc/trpl/while-loops.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
% while loops
1+
% while Loops
22

33
Rust also has a `while` loop. It looks like this:
44

0 commit comments

Comments
 (0)