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
25
src/main.rs
25
src/main.rs
|
@ -8,14 +8,19 @@ fn main() {
|
|||
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…
Add table
Add a link
Reference in a new issue