Fix wording on the aliasing section by JohnTitor · Pull Request #366 · rust-lang/nomicon (original) (raw)

I've read this over several times, and I'm not clear on this.

The original says: "the value of a local variable can't be aliased by things that existed before it was declared" which I read to be true. The local variable can't be aliased before it is declared because it doesn't exist, yet. There is nothing to alias. That is:

fn compute(input: &u32, output: &mut u32) { // Up to this point, nothing can alias temp because temp doesn't exist, yet. let mut temp = *output; if *input > 10 { temp = 1; } if *input > 5 { temp *= 2; } *output = temp; }

The new version says: "the value of a local variable cannot alias things that existed before it was declared."
This doesn't seem correct to me because local variables can be created which alias things before their declaration.

fn f(a: &str) { let b = a; // local variable b created an alias of a }

Can you help me understand the proposed correction?