Skip to content

Commit 6c41f99

Browse files
committed
auto merge of #12547 : jagtalon/rust/jag/rust/tutorial-freezing, r=pnkfelix
- "Lending an immutable pointer" might be confusing. It was not discussed why borrowed pointers are immutable in the first place. - Make it clear that the borrowed pointers are immutable even if the variable was declared with `mut`. - Make it clear that we cannot even assign anything to the variable while its value is being borrowed. tutorial: change "--" to an em-dash. tutorial: change instances of "--" to em-dash.
2 parents eb86913 + 82747ed commit 6c41f99

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/doc/tutorial.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1468,14 +1468,14 @@ For a more in-depth explanation of references and lifetimes, read the
14681468
14691469
## Freezing
14701470
1471-
Lending an immutable pointer to an object freezes it and prevents mutation.
1471+
Lending an &-pointer to an object freezes it and prevents mutation—even if the object was declared as `mut`.
14721472
`Freeze` objects have freezing enforced statically at compile-time. An example
14731473
of a non-`Freeze` type is [`RefCell<T>`][refcell].
14741474
14751475
~~~~
14761476
let mut x = 5;
14771477
{
1478-
let y = &x; // `x` is now frozen, it cannot be modified
1478+
let y = &x; // `x` is now frozen. It cannot be modified or re-assigned.
14791479
}
14801480
// `x` is now unfrozen again
14811481
# x = 3;
@@ -2021,8 +2021,8 @@ C++ templates.
20212021
20222022
## Traits
20232023
2024-
Within a generic function -- that is, a function parameterized by a
2025-
type parameter, say, `T` -- the operations we can do on arguments of
2024+
Within a generic functionthat is, a function parameterized by a
2025+
type parameter, say, `T`the operations we can do on arguments of
20262026
type `T` are quite limited. After all, since we don't know what type
20272027
`T` will be instantiated with, we can't safely modify or query values
20282028
of type `T`. This is where _traits_ come into play. Traits are Rust's

0 commit comments

Comments
 (0)