Skip to content

Commit 0cae849

Browse files
committed
fix mostly grammar per PR comments
1 parent 9974465 commit 0cae849

File tree

1 file changed

+18
-20
lines changed

1 file changed

+18
-20
lines changed

src/doc/guide-lifetimes.md

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,19 @@ Despite their complete safety, a reference's representation at runtime
1414
is the same as that of an ordinary pointer in a C program. They introduce zero
1515
overhead. The compiler does all safety checks at compile time.
1616

17-
Although references have rather elaborate theoretical
18-
underpinnings (region pointers), the core concepts will be familiar to
19-
anyone who has worked with C or C++. Therefore, the best way to explain
20-
how they are used—and their limitations—is probably just to work
21-
through several examples.
17+
Although references have rather elaborate theoretical underpinnings usually
18+
introduced as (e.g. region pointers), the core concepts will be familiar to
19+
anyone who has worked with C or C++. The best way to explain how they are
20+
used—and their limitations—is probably just to work through several examples.
2221

2322
# By example
2423

2524
References, sometimes known as *borrowed pointers*, are only valid for
2625
a limited duration. References never claim any kind of ownership
27-
over the data that they point to, instead, they are used for cases
26+
over the data that they point to. Instead, they are used for cases
2827
where you would like to use data for a short time.
2928

30-
As an example, consider a simple struct type `Point`:
29+
Consider a simple struct type `Point`:
3130

3231
~~~
3332
struct Point {x: f64, y: f64}
@@ -78,9 +77,9 @@ value. We also call this _borrowing_ the local variable
7877
`on_the_stack`, because we have created an alias: that is, another
7978
name for the same data.
8079

81-
For the second argument, we need to grab the contents of `on_the_heap`
82-
by using the `*` operator, and then get a reference to that data. In
83-
order to convert `Box<T>` into a `&T`, we need to use `&*`.
80+
For the second argument, we need to extract the contents of `on_the_heap`
81+
by derefercing with the `*` symbol. Now that we have the data, we need
82+
to create a reference with the `&` symbol.
8483

8584
Whenever a caller lends data to a callee, there are some limitations on what
8685
the caller can do with the original. For example, if the contents of a
@@ -194,7 +193,7 @@ fn example3() -> int {
194193
}
195194
~~~
196195

197-
Here, as before, the interior of the variable `x` is being borrowed
196+
Here, the interior of the variable `x` is being borrowed
198197
and `x` is declared as mutable. However, the compiler can prove that
199198
`x` is not assigned anywhere in the lifetime L of the variable
200199
`y`. Therefore, it accepts the function, even though `x` is mutable
@@ -281,8 +280,8 @@ prevents pointers from pointing into freed memory. There is one other
281280
case where the compiler must be very careful to ensure that pointers
282281
remain valid: pointers into the interior of an `enum`.
283282

284-
As an example, let’s look at the following `shape` type that can
285-
represent both rectangles and circles:
283+
Let’s look at the following `shape` type that can represent both rectangles
284+
and circles:
286285

287286
~~~
288287
struct Point {x: f64, y: f64}; // as before
@@ -391,7 +390,7 @@ reference, then uses it within the same scope. It is also
391390
possible to return references as the result of a function, but
392391
as we'll see, doing so requires some explicit annotation.
393392

394-
For example, we could write a subroutine like this:
393+
We could write a subroutine like this:
395394

396395
~~~
397396
struct Point {x: f64, y: f64}
@@ -412,11 +411,10 @@ pointer result will always have the same lifetime as one of the
412411
parameters; named lifetimes indicate which parameter that
413412
is.
414413

415-
In the previous examples, function parameter types did not include a
416-
lifetime name. In those examples, the compiler simply creates a fresh
417-
name for the lifetime automatically: that is, the lifetime name is
418-
guaranteed to refer to a distinct lifetime from the lifetimes of all
419-
other parameters.
414+
In the previous code samples, function parameter types did not include a
415+
lifetime name. The compiler simply creates a fresh name for the lifetime
416+
automatically: that is, the lifetime name is guaranteed to refer to a distinct
417+
lifetime from the lifetimes of all other parameters.
420418

421419
Named lifetimes that appear in function signatures are conceptually
422420
the same as the other lifetimes we have seen before, but they are a bit
@@ -461,7 +459,7 @@ guarantees; in fact, it cannot guarantee that the pointer will remain
461459
valid at all once it returns, as the parameter `p` may or may not be
462460
live in the caller. Therefore, the compiler will report an error here.
463461

464-
In general, if you borrow a structs or boxes to create a
462+
In general, if you borrow a struct or box to create a
465463
reference, it will only be valid within the function
466464
and cannot be returned. This is why the typical way to return references
467465
is to take references as input (the only other case in

0 commit comments

Comments
 (0)