oh interesting. Dangling reference not allowed.
``` error[E0597]: `x` does not live long enough ```
This commit is contained in:
parent
0a2003dfc8
commit
de5218c5dd
22 changed files with 21 additions and 12 deletions
27
src/main.rs
27
src/main.rs
|
@ -3,19 +3,24 @@ fn main() {
|
|||
a[5] = 0;
|
||||
println!("a: {:?}", a);
|
||||
|
||||
// so this is assigning an immutable tuple
|
||||
// so this is assigning an immutable tuple
|
||||
let t: (i8, bool) = (7, true);
|
||||
println!("t 1st: {}", t.0);
|
||||
println!("t 2nd: {}", t.1);
|
||||
|
||||
let mut x: i32 = 10;
|
||||
let mut z: i32 = 5;
|
||||
println!("x: {x}");
|
||||
println!("z: {z}");
|
||||
let mut ref_x: &mut i32 = &mut x;
|
||||
*ref_x = 20;
|
||||
println!("x: {x}");
|
||||
ref_x = &mut z;
|
||||
*ref_x = 20;
|
||||
println!("z: {z}");
|
||||
let pre_ref_x: &mut i32;
|
||||
{
|
||||
let mut x: i32 = 10;
|
||||
let mut z: i32 = 5;
|
||||
println!("x: {x}");
|
||||
println!("z: {z}");
|
||||
let mut ref_x: &mut i32 = &mut x;
|
||||
*ref_x = 20;
|
||||
pre_ref_x = &mut x;
|
||||
println!("x: {x}");
|
||||
ref_x = &mut z;
|
||||
*ref_x = 20;
|
||||
println!("z: {z}");
|
||||
}
|
||||
println!("pre_ref_x: {pre_ref_x}");
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue