Skip to content

Instantly share code, notes, and snippets.

@cbzehner
Created February 20, 2018 00:49
Show Gist options
  • Save cbzehner/94a06656a929d57dfac0c7ce4837b7c1 to your computer and use it in GitHub Desktop.
Save cbzehner/94a06656a929d57dfac0c7ce4837b7c1 to your computer and use it in GitHub Desktop.
fn main() {
let r = 2;
{
let x = 5;
let r = x;
}
println!("r: {}", r);
}
@cbzehner
Copy link
Author

The second r declaration gets dropped when we go out of scope of the inner { }

$cargo run
   Compiling re-letting v0.1.0 (file:///Users/cbzehner/Projects/rustbook/re-letting)
warning: unused variable: `r`
 --> src/main.rs:5:13
  |
5 |         let r = x;
  |             ^
  |
  = note: #[warn(unused_variables)] on by default
  = note: to avoid this warning, consider using `_r` instead

    Finished dev [unoptimized + debuginfo] target(s) in 0.48 secs
     Running `target/debug/re-letting`
r: 2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment