oh interesting. Dangling reference not allowed.
``` error[E0597]: `x` does not live long enough ```
This commit is contained in:
parent
0a2003dfc8
commit
de5218c5dd
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}");
|
||||
}
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
7cbe46f1ccde8504
|
File diff suppressed because one or more lines are too long
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue