RBE more variable bindings fun

This commit is contained in:
Dan Buch 2021-10-06 19:40:31 -04:00
parent d2563484f9
commit 6d6e600720
Signed by: meatballhat
GPG Key ID: 9685130D8B763EA7
4 changed files with 58 additions and 0 deletions

View File

@ -0,0 +1,19 @@
fn main() {
let a_binding;
{
let x = 2;
a_binding = x * x;
}
println!("a binding: {}", a_binding);
let another_binding;
//println!("another binding: {}", another_binding);
another_binding = 1;
println!("another binding: {}", another_binding);
}

View File

@ -0,0 +1,11 @@
fn main() {
let mut _mutable_integer = 7i32;
{
let _mutable_integer = _mutable_integer;
// _mutable_integer = 50;
}
_mutable_integer = 3;
}

View File

@ -0,0 +1,12 @@
fn main() {
let long_lived_binding = 1;
{
let short_lived_binding = 2;
println!("inner short: {}", short_lived_binding);
}
// println!("outer short: {}", short_lived_binding);
println!("outer long: {}", long_lived_binding);
}

View File

@ -0,0 +1,16 @@
fn main() {
let shadowed_binding = 1;
{
println!("before being shadowed: {}", shadowed_binding);
let shadowed_binding = "abc";
println!("shadowed in inner block: {}", shadowed_binding);
}
println!("outside inner block: {}", shadowed_binding);
let shadowed_binding = 2;
println!("shadowed in outer block: {}", shadowed_binding);
}