Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tutorial about match can be misunderstood about the role of the "my_number" #13571

Closed
zookoatleastauthoritycom opened this issue Apr 17, 2014 · 0 comments

Comments

@zookoatleastauthoritycom

Reading http://static.rust-lang.org/doc/master/tutorial.html#pattern-matching, my partner copied the example code:

match my_number {
 0 => { println!("zero") }
  _ => { println!("something else") }
}

into her program, but then was unsure what to do, possibly because she thought that the example code above would define a variable named "my_number". I suggested to her that the tutorial could instead suggest:

fn f(my_number: int) -> void {
    match my_number {
     0 => { println!("zero") }
      _ => { println!("something else") }
    }
}

and that made sense to her.

zookoatleastauthoritycom pushed a commit to zookoatleastauthoritycom/rust that referenced this issue May 12, 2014
This is to clarify that match construct doesn't define a new variable, since I
observed a person reading the Rust tutorial who seemed to incorrectly think
that it did. Fixes rust-lang#13571 .
matthiaskrgr pushed a commit to matthiaskrgr/rust that referenced this issue Nov 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant