I expected this code to work because all bindings are in the same scope:
fn main() {
let mut foobar = vec!["foo"];
let bar = "bar".to_string();
foobar.push(&bar);
}
But I am getting this error:
error: `bar` does not live long enough
--> baz.rs:4:18
|>
4 |> foobar.push(&bar);
|> ^^^
note: reference must be valid for the block suffix following statement 0 at 2:33...
--> baz.rs:2:34
|>
2 |> let mut foobar = vec!["foo"];
|> ^
note: ...but borrowed value is only valid for the block suffix following statement 1 at 3:32
--> baz.rs:3:33
|>
3 |> let bar = "bar".to_string();
|> ^
error: aborting due to previous error