-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Just a few minor updates to guide.md #17754
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
Conversation
See issue rust-lang#17672. This was started in commit ee1cbb9, but there were a few more lines to update.
Oddly (to me), this code runs fine without the comma separating the `Some` and `None` arms of the `match` construct. It seems like Rust doesn't require you to separate arms with commas if all the expressions are enclosed in braces.
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @aturon (or someone else) soon. |
I don't know if there's a convention, but I always include commas. Are trailing commas rare enough to be called out specifically? The only thing I use on a regular basis that doesnt have trailing commas is JSON. Regardless is the questions, these changes are all good. Aaron, what do you think re convention? |
(I'm on mobile and so it's not easy to see the correct commit. If someone wants to r=me before I can get to it, feel free.) |
@steveklabnik There's a proposed convention to use trailing commas whenever the thing in question spans multiple lines, but it hasn't gone through the RFC process yet. Most of the basic style questions (that don't involve APIs) are not completely "approved" yet; we plan to sit down and write them all up at once in the near future. I'll send it to bors on your behalf. |
Thanks for the feedback. I agree that always explicitly including commas is a good practice. I guess I just had the (false) inclination that something like the contrived example below wouldn't compile. let x = 5i;
match x {
1 => { println!("one");
println!("{:d}", 1i); }
2 => { println!("two");
println!("{:d}", 2i); }
3 => { println!("three");
println!("{:d}", 3i); }
4 => { println!("four");
println!("{:d}", 4i); }
5 => { println!("five");
println!("{:d}", 5i); }
_ => { println!("something else");
println!("{:d}", 42i); }
} As for trailing commas, I can definitely see the benefits. I didn't realize they were so prevalent. |
Hi, These are a few small edits to the Guide that I made while reading online. Really well done and approachable. I have a few questions below, but I don't know if this is the proper place to ask them, so feel free to ignore the below. 1. Trailing commas seem to be a convention in Rust and are used quite a bit throughout the Guide, but are never explicitly mentioned. Maybe adding a short mention about them when they first appear in the Structs section might be helpful to those who are unfamiliar with or don't use them in other languages. 2. In the Iterators section, there is a block of code like this: ```rust let mut range = range(0i, 10i); loop { match range.next() { Some(x) => { println!("{}", x); } // no comma needed? None => { break } } } ``` My inclination would be to put a comma where the comment is to separate the two arms to get this to compile, but it runs fine either way. Is there a convention on commas for scenarios like this where each arm is enclosed in `{}`? All the best, O-I
Hi,
These are a few small edits to the Guide that I made while reading online. Really well done and approachable.
I have a few questions below, but I don't know if this is the proper place to ask them, so feel free to ignore the below.
My inclination would be to put a comma where the comment is to separate the two arms to get this to compile, but it runs fine either way. Is there a convention on commas for scenarios like this where each arm is enclosed in
{}
?All the best,
O-I