mirror of
https://github.com/rust-lang/rust.git
synced 2025-01-26 14:43:24 +00:00
Update the manual.
This commit is contained in:
parent
03111fb83b
commit
b2b2095eaf
15
doc/rust.md
15
doc/rust.md
@ -3395,16 +3395,23 @@ a [temporary](#lvalues-rvalues-and-temporaries), or a local variable.
|
||||
A _local variable_ (or *stack-local* allocation) holds a value directly,
|
||||
allocated within the stack's memory. The value is a part of the stack frame.
|
||||
|
||||
Local variables are immutable unless declared with `let mut`. The
|
||||
`mut` keyword applies to all local variables declared within that
|
||||
declaration (so `let mut (x, y) = ...` declares two mutable variables, `x` and
|
||||
`y`).
|
||||
Local variables are immutable unless declared otherwise like: `let mut x = ...`.
|
||||
|
||||
Function parameters are immutable unless declared with `mut`. The
|
||||
`mut` keyword applies only to the following parameter (so `|mut x, y|`
|
||||
and `fn f(mut x: ~int, y: ~int)` declare one mutable variable `x` and
|
||||
one immutable variable `y`).
|
||||
|
||||
Methods that take either `self` or `~self` can optionally place them in a
|
||||
mutable slot by prefixing them with `mut` (similar to regular arguments):
|
||||
|
||||
~~~
|
||||
trait Changer {
|
||||
fn change(mut self) -> Self;
|
||||
fn modify(mut ~self) -> ~Self;
|
||||
}
|
||||
~~~
|
||||
|
||||
Local variables are not initialized when allocated; the entire frame worth of
|
||||
local variables are allocated at once, on frame-entry, in an uninitialized
|
||||
state. Subsequent statements within a function may or may not initialize the
|
||||
|
Loading…
Reference in New Issue
Block a user