Non-Lexical Lifetimes in Rust Arrives for Everyone
blog.pnkfx.org
blog.pnkfx.org
fn main() { // SCOPE TREE
//
let mut names = // +- `names` scope start
["abe", "beth", "cory", "diane"]; // |
// |
let alias = &mut names[0]; // | +- `alias` scope start
// | |
*alias = "alex"; // <------------------------ write to `*alias`
// | |
println!("{}", names[0]); // <--------------- read of `names[0]`
// | |
// | +- `alias` scope end
// +- `name` scope end
}
That is to say: fn main() { // SCOPE TREE
//
let mut names = // +- `names` scope start
["abe", "beth", "cory", "diane"]; // |
// |
{ let alias = &mut names[0]; // | +- `alias` scope start
// | |
*alias = "alex"; } // <------------------------ write to `*alias`
// | |
println!("{}", names[0]); // <--------------- read of `names[0]`
// | |
// | +- `alias` scope end
// +- `name` scope end
}
If that can be made to work without diagnostics, it's a better solution than playing games with de facto tying scopes to the last uses of identifiers.