Skip to content

Instantly share code, notes, and snippets.

@jbowles
Last active August 29, 2015 14:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jbowles/81b1200553c03b3cd383 to your computer and use it in GitHub Desktop.
Save jbowles/81b1200553c03b3cd383 to your computer and use it in GitHub Desktop.

I can only rebind a variable that is explicitly declared as mutable; cool.

fn main() {
    let mut x: int = 5;
    x = 10i;
    println!("value of x: {}", x); // -> 10
}

However, I'm guessing this would be redeclaring the same variable (?), which does NOT trigger a compiler error.

fn main() {
    let x: int = 5;
    println!("value of x: {}", x); // -> 5
    let x: int = 10;
    println!("value of x: {}", x); // -> 10
}

Is this intentional in Rust?

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