mirror of
https://github.com/rust-lang/rust.git
synced 2025-10-03 02:40:40 +00:00
25 lines
387 B
Rust
25 lines
387 B
Rust
//! Test that function and closure parameters marked as `mut` can be mutated
|
|
//! within the function body.
|
|
|
|
//@ run-pass
|
|
|
|
fn f(mut y: Box<isize>) {
|
|
*y = 5;
|
|
assert_eq!(*y, 5);
|
|
}
|
|
|
|
fn g() {
|
|
let frob = |mut q: Box<isize>| {
|
|
*q = 2;
|
|
assert_eq!(*q, 2);
|
|
};
|
|
let w = Box::new(37);
|
|
frob(w);
|
|
}
|
|
|
|
pub fn main() {
|
|
let z = Box::new(17);
|
|
f(z);
|
|
g();
|
|
}
|