The problem of struct declaration

Hello, I'm a new rustacean. My problem is that why the existence of comma in the last line of struct declaration can be compiled successfully.
In Listing 5-1 of rust book, the declaration of struct

struct User {
       username: String,
       email: String,
       sign_in_count: u64,
       active: bool,  
}

and

struct User {
       username: String,
       email: String,
       sign_in_count: u64,
       active: bool
}

Rustc can compile both successfully. Won't that produce some risks?

What risks?

Some reasons for allowing this are

  • Be lenient with your inputs
  • diffs are cleaner (adding a field changes one line, not two)
    • Making such an addition is simpler / more consistent too
  • Macros and other code generation are simpler
  • In the case of tuples, consistency
    • A 1-tuple requires a trailing comma to distinguish from a parenthesized non-tuple
  • And presently of course, backwards compatibility
5 Likes

Which one would you suspect introduces a risk?

Risk of what?

1 Like

No, it won't.

1 Like

Ok, I see. Thank you.

OK, thank you.