You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have noticed that rustfmt leaves those 2 equivalent functions unchanged, although they are differently formatted:
fnfirst_function() -> ReturnType{structinner_item{field:u32,};// <- With a semicolon.
last_expression
}fnsecond_function() -> ReturnType{structinner_item{field:u32,}// <- Without a semicolon.
last_expression
}
Is this something that rustfmt should have an opinion about?
I would like the answer to be yes, because I would not have to choose myself whether to write this semicolon or not.
But I would understand that the answer be no, because ; is an additional (empty) statement that does not appear in the second_function, so the two functions are somewhat different. However, if this is how rustfmt stands, then it should maybe reformat the first snippet to
fnfirst_function() -> ReturnType{structinner_item{field:u32,};// <- Make it clear that this is additional, empty statement.
last_expression
}
The text was updated successfully, but these errors were encountered:
Rustfmt already elides empty statements (per a comment on the RFC mentioned above, maybe this is actually unsafe?), so I think it is reasonable to elide the semicolon in this case too.
ayazhafiz
added a commit
to ayazhafiz/rustfmt
that referenced
this issue
Jun 6, 2020
Per the Rust grammar, trailing semicolons on an item statement may be
optional (i.e. if the statement is a block). Keeping the semicolon in
such cases is unnecessary and may be confusing (does the semicolon
terminate the last statement, or is it an empty statement?), so just
drop it.
Closesrust-lang#4222
I have noticed that
rustfmt
leaves those 2 equivalent functions unchanged, although they are differently formatted:Is this something that
rustfmt
should have an opinion about?I would like the answer to be yes, because I would not have to choose myself whether to write this semicolon or not.
But I would understand that the answer be no, because
;
is an additional (empty) statement that does not appear in thesecond_function
, so the two functions are somewhat different. However, if this is howrustfmt
stands, then it should maybe reformat the first snippet toThe text was updated successfully, but these errors were encountered: