oh interesting. Dangling reference not allowed.

```
error[E0597]: `x` does not live long enough
```
This commit is contained in:
Vincent Batts 2023-01-14 15:08:36 -05:00
parent 0a2003dfc8
commit de5218c5dd
22 changed files with 21 additions and 12 deletions

View File

@ -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}");
}

View File

@ -1 +0,0 @@
7cbe46f1ccde8504

File diff suppressed because one or more lines are too long